Add gradient option to addressable color wipe effect (#5689)

This commit is contained in:
Matthew Campbell 2023-12-20 16:08:44 -08:00 committed by GitHub
parent 3c2383e261
commit c6a37da9da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -100,6 +100,7 @@ struct AddressableColorWipeEffectColor {
uint8_t r, g, b, w; uint8_t r, g, b, w;
bool random; bool random;
size_t num_leds; size_t num_leds;
bool gradient;
}; };
class AddressableColorWipeEffect : public AddressableLightEffect { class AddressableColorWipeEffect : public AddressableLightEffect {
@ -117,8 +118,15 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
it.shift_left(1); it.shift_left(1);
else else
it.shift_right(1); it.shift_right(1);
const AddressableColorWipeEffectColor color = this->colors_[this->at_color_]; const AddressableColorWipeEffectColor &color = this->colors_[this->at_color_];
const Color esp_color = Color(color.r, color.g, color.b, color.w); Color esp_color = Color(color.r, color.g, color.b, color.w);
if (color.gradient) {
size_t next_color_index = (this->at_color_ + 1) % this->colors_.size();
const AddressableColorWipeEffectColor &next_color = this->colors_[next_color_index];
const Color next_esp_color = Color(next_color.r, next_color.g, next_color.b, next_color.w);
uint8_t gradient = 255 * ((float) this->leds_added_ / color.num_leds);
esp_color = esp_color.gradient(next_esp_color, gradient);
}
if (this->reverse_) if (this->reverse_)
it[-1] = esp_color; it[-1] = esp_color;
else else

View File

@ -58,6 +58,7 @@ from .types import (
CONF_ADD_LED_INTERVAL = "add_led_interval" CONF_ADD_LED_INTERVAL = "add_led_interval"
CONF_REVERSE = "reverse" CONF_REVERSE = "reverse"
CONF_GRADIENT = "gradient"
CONF_MOVE_INTERVAL = "move_interval" CONF_MOVE_INTERVAL = "move_interval"
CONF_SCAN_WIDTH = "scan_width" CONF_SCAN_WIDTH = "scan_width"
CONF_TWINKLE_PROBABILITY = "twinkle_probability" CONF_TWINKLE_PROBABILITY = "twinkle_probability"
@ -386,6 +387,7 @@ async def addressable_rainbow_effect_to_code(config, effect_id):
cv.Optional(CONF_WHITE, default=1.0): cv.percentage, cv.Optional(CONF_WHITE, default=1.0): cv.percentage,
cv.Optional(CONF_RANDOM, default=False): cv.boolean, cv.Optional(CONF_RANDOM, default=False): cv.boolean,
cv.Required(CONF_NUM_LEDS): cv.All(cv.uint32_t, cv.Range(min=1)), cv.Required(CONF_NUM_LEDS): cv.All(cv.uint32_t, cv.Range(min=1)),
cv.Optional(CONF_GRADIENT, default=False): cv.boolean,
} }
), ),
cv.Optional( cv.Optional(
@ -409,6 +411,7 @@ async def addressable_color_wipe_effect_to_code(config, effect_id):
("w", int(round(color[CONF_WHITE] * 255))), ("w", int(round(color[CONF_WHITE] * 255))),
("random", color[CONF_RANDOM]), ("random", color[CONF_RANDOM]),
("num_leds", color[CONF_NUM_LEDS]), ("num_leds", color[CONF_NUM_LEDS]),
("gradient", color[CONF_GRADIENT]),
) )
) )
cg.add(var.set_colors(colors)) cg.add(var.set_colors(colors))