14inline static int16_t sin16_c(uint16_t theta) {
15 static const uint16_t BASE[] = {0, 6393, 12539, 18204, 23170, 27245, 30273, 32137};
16 static const uint8_t SLOPE[] = {49, 48, 44, 38, 31, 23, 14, 4};
17 uint16_t offset = (theta & 0x3FFF) >> 3;
19 offset = 2047 - offset;
20 uint8_t section = offset / 256;
21 uint16_t
b = BASE[section];
22 uint8_t
m = SLOPE[section];
23 uint8_t secoffset8 = uint8_t(offset) / 2;
24 uint16_t mx =
m * secoffset8;
30inline static uint8_t half_sin8(uint8_t v) {
return sin16_c(uint16_t(v) * 128u) >> 8; }
90 const uint16_t add = 0xFFFF / this->
width_;
113static_assert(std::is_trivially_copyable_v<AddressableColorWipeEffectColor>,
114 "AddressableColorWipeEffectColor is copied out of flash");
116 "AddressableColorWipeEffectColor must be whole words for ESP8266 flash reads");
117static constexpr uint8_t NO_RANDOM_SLOT = 0xFF;
146 esp_color = esp_color.
gradient(next_esp_color, gradient);
177 return Color(entry.
r, entry.
g, entry.
b, entry.
w);
201 it.
all() = current_color;
208 if (this->
at_led_ >= max_pos) {
227 it[this->
at_led_ + i] = current_color;
252 for (
auto view : addressable) {
253 if (view.get_effect_data() != 0) {
254 const uint8_t sine = half_sin8(view.get_effect_data());
255 view = current_color * sine;
256 const uint8_t new_pos = view.get_effect_data() + pos_add;
257 if (new_pos < view.get_effect_data()) {
258 view.set_effect_data(0);
260 view.set_effect_data(new_pos);
268 if (addressable[
pos].get_effect_data() != 0)
270 addressable[
pos].set_effect_data(1);
294 for (
auto view : it) {
295 if (view.get_effect_data() != 0) {
296 const uint8_t
x = (view.get_effect_data() >> 3) & 0b11111;
297 const uint8_t color = view.get_effect_data() & 0b111;
298 const uint16_t sine = half_sin8((
x << 3) | subsine);
300 view = current_color * sine;
302 view =
Color(((color >> 2) & 1) * sine, ((color >> 1) & 1) * sine, ((color >> 0) & 1) * sine);
304 const uint8_t new_x =
x + pos_add;
305 if (new_x > 0b11111) {
306 view.set_effect_data(0);
308 view.set_effect_data((new_x << 3) | color);
311 view =
Color(0, 0, 0, 0);
316 if (it[
pos].get_effect_data() != 0)
319 it[
pos].set_effect_data(0b1000 | color);
346 for (
auto view : it) {
347 Color target = view.get() * fade_out_mult;
354 int last = it.
size() - 1;
355 it[0].set(it[0].get() + (it[1].get() * 128));
356 for (
int i = 1; i < last; i++) {
357 it[i] = (it[i - 1].
get() * 64) + it[i].
get() + (it[i + 1].
get() * 64);
359 it[last] = it[last].
get() + (it[last - 1].
get() * 128);
365 it[
pos] = current_color;
389 const uint8_t inv_intensity = 255 - intensity;
395 for (
auto var : it) {
396 rng_state = (rng_state * 0x9E3779B9) + 0x9E37;
397 const uint8_t flicker = (rng_state & 0xFF) % intensity;
399 var = var.get() * (255 - flicker);
402 var = (var.get() * inv_intensity) + (current_color * intensity);
Lightweight read-only view over a const array stored in RODATA (will typically be in flash memory).
AddressableColorWipeEffect(const char *name)
Color color_of_(const AddressableColorWipeEffectColor &entry) const
void apply(AddressableLight &it, const Color ¤t_color) override
uint32_t add_led_interval_
ConstVector< AddressableColorWipeEffectColor > colors_
void set_colors(const AddressableColorWipeEffectColor *colors, size_t count, Color *random_colors)
Codegen only: point at the generated flash table of colors, which must outlive the effect.
AddressableColorWipeEffectColor entry_(size_t index) const
void set_reverse(bool reverse)
void set_add_led_interval(uint32_t add_led_interval)
void set_fade_out_rate(uint8_t fade_out_rate)
void set_spark_probability(float spark_probability)
void set_use_random_color(bool random_color)
uint32_t update_interval_
AddressableFireworksEffect(const char *name)
void apply(AddressableLight &it, const Color ¤t_color) override
void set_update_interval(uint32_t update_interval)
void set_intensity(float intensity)
AddressableFlickerEffect(const char *name)
void apply(AddressableLight &it, const Color ¤t_color) override
uint32_t update_interval_
void set_update_interval(uint32_t update_interval)
void(* f_)(AddressableLight &, Color, bool initial_run)
AddressableLambdaLightEffect(const char *name, void(*f)(AddressableLight &, Color, bool initial_run), uint32_t update_interval)
uint32_t update_interval_
void apply(AddressableLight &it, const Color ¤t_color) override
uint32_t get_effect_index() const
Get effect index specifically for addressable effects.
virtual void apply(AddressableLight &it, const Color ¤t_color)=0
AddressableLight * get_addressable_() const
void start_internal() override
bool is_current_effect() const
Check if this is the currently running addressable effect.
AddressableLightEffect(const char *name)
virtual void clear_effect_data()=0
void shift_left(int32_t amnt)
ESPColorView get(int32_t index)
void shift_right(int32_t amnt)
void set_effect_active(bool effect_active)
virtual int32_t size() const =0
bool is_effect_active() const
void apply(AddressableLight &it, const Color ¤t_color) override
void set_speed(uint32_t speed)
AddressableRainbowLightEffect(const char *name)
void set_width(uint16_t width)
void set_progress_interval(uint32_t progress_interval)
void apply(AddressableLight &it, const Color ¤t_color) override
uint32_t progress_interval_
float twinkle_probability_
void set_twinkle_probability(float twinkle_probability)
AddressableRandomTwinkleEffect(const char *name)
void set_scan_width(uint32_t scan_width)
void set_move_interval(uint32_t move_interval)
AddressableScanEffect(const char *name)
void apply(AddressableLight &it, const Color ¤t_color) override
uint32_t progress_interval_
void set_progress_interval(uint32_t progress_interval)
AddressableTwinkleEffect(const char *name)
void set_twinkle_probability(float twinkle_probability)
void apply(AddressableLight &addressable, const Color ¤t_color) override
float twinkle_probability_
virtual void start()
Initialize this LightEffect. Will be called once after creation.
uint32_t get_index() const
Get the index of this effect in the parent light's effect list.
bool is_active() const
Check if this effect is currently active.
LightColorValues remote_values
The remote color values reported to the frontend.
LightOutput * get_output() const
Get the light output associated with this object.
Color color_from_light_color_values(LightColorValues val)
Convert the color information from a LightColorValues object to a Color object (does not apply bright...
FLAG_HAS_TRANSITION float
float random_float()
Return a random float between 0 and 1.
void progmem_memcpy(void *dst, const void *src, size_t len)
uint32_t random_uint32()
Return a random 32-bit unsigned integer.
uint32_t IRAM_ATTR HOT millis()
static Color random_color()
Color gradient(const Color &to_color, uint8_t amnt) const
One wipe color. Codegen keeps the colors in a flash table, so it is read with progmem_memcpy.
uint8_t random_slot
index into the effect's random colors, or NO_RANDOM_SLOT