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;
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

View file

@ -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))