mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 05:24:53 +01:00
Add gradient option to addressable color wipe effect (#5689)
This commit is contained in:
parent
3c2383e261
commit
c6a37da9da
2 changed files with 13 additions and 2 deletions
|
@ -100,6 +100,7 @@ struct AddressableColorWipeEffectColor {
|
|||
uint8_t r, g, b, w;
|
||||
bool random;
|
||||
size_t num_leds;
|
||||
bool gradient;
|
||||
};
|
||||
|
||||
class AddressableColorWipeEffect : public AddressableLightEffect {
|
||||
|
@ -117,8 +118,15 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
|
|||
it.shift_left(1);
|
||||
else
|
||||
it.shift_right(1);
|
||||
const AddressableColorWipeEffectColor color = this->colors_[this->at_color_];
|
||||
const Color esp_color = Color(color.r, color.g, color.b, color.w);
|
||||
const AddressableColorWipeEffectColor &color = this->colors_[this->at_color_];
|
||||
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_)
|
||||
it[-1] = esp_color;
|
||||
else
|
||||
|
|
|
@ -58,6 +58,7 @@ from .types import (
|
|||
|
||||
CONF_ADD_LED_INTERVAL = "add_led_interval"
|
||||
CONF_REVERSE = "reverse"
|
||||
CONF_GRADIENT = "gradient"
|
||||
CONF_MOVE_INTERVAL = "move_interval"
|
||||
CONF_SCAN_WIDTH = "scan_width"
|
||||
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_RANDOM, default=False): cv.boolean,
|
||||
cv.Required(CONF_NUM_LEDS): cv.All(cv.uint32_t, cv.Range(min=1)),
|
||||
cv.Optional(CONF_GRADIENT, default=False): cv.boolean,
|
||||
}
|
||||
),
|
||||
cv.Optional(
|
||||
|
@ -409,6 +411,7 @@ async def addressable_color_wipe_effect_to_code(config, effect_id):
|
|||
("w", int(round(color[CONF_WHITE] * 255))),
|
||||
("random", color[CONF_RANDOM]),
|
||||
("num_leds", color[CONF_NUM_LEDS]),
|
||||
("gradient", color[CONF_GRADIENT]),
|
||||
)
|
||||
)
|
||||
cg.add(var.set_colors(colors))
|
||||
|
|
Loading…
Reference in a new issue