mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-04 20:09:35 +02:00
Migrate ESPColor to Color (#1551)
* Migrate ESPColor to Color * color.h constructor fix * Updated componets to use Color Added a using for ESPColor * Lint fixes * Fixed value error * Update display components to use colorutil * Updated to latest PR comments * Fixed COLOR_WHITE * Moved esp_scale to color_utils * Rename color_utils to display_color_utils
This commit is contained in:
@@ -34,13 +34,13 @@ class AddressableLightEffect : public LightEffect {
|
||||
this->start();
|
||||
}
|
||||
void stop() override { this->get_addressable_()->set_effect_active(false); }
|
||||
virtual void apply(AddressableLight &it, const ESPColor ¤t_color) = 0;
|
||||
virtual void apply(AddressableLight &it, const Color ¤t_color) = 0;
|
||||
void apply() override {
|
||||
LightColorValues color = this->state_->remote_values;
|
||||
// not using any color correction etc. that will be handled by the addressable layer
|
||||
ESPColor current_color =
|
||||
ESPColor(static_cast<uint8_t>(color.get_red() * 255), static_cast<uint8_t>(color.get_green() * 255),
|
||||
static_cast<uint8_t>(color.get_blue() * 255), static_cast<uint8_t>(color.get_white() * 255));
|
||||
Color current_color =
|
||||
Color(static_cast<uint8_t>(color.get_red() * 255), static_cast<uint8_t>(color.get_green() * 255),
|
||||
static_cast<uint8_t>(color.get_blue() * 255), static_cast<uint8_t>(color.get_white() * 255));
|
||||
this->apply(*this->get_addressable_(), current_color);
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ class AddressableLightEffect : public LightEffect {
|
||||
class AddressableLambdaLightEffect : public AddressableLightEffect {
|
||||
public:
|
||||
AddressableLambdaLightEffect(const std::string &name,
|
||||
const std::function<void(AddressableLight &, ESPColor, bool initial_run)> &f,
|
||||
const std::function<void(AddressableLight &, Color, bool initial_run)> &f,
|
||||
uint32_t update_interval)
|
||||
: AddressableLightEffect(name), f_(f), update_interval_(update_interval) {}
|
||||
void start() override { this->initial_run_ = true; }
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||
const uint32_t now = millis();
|
||||
if (now - this->last_run_ >= this->update_interval_) {
|
||||
this->last_run_ = now;
|
||||
@@ -65,7 +65,7 @@ class AddressableLambdaLightEffect : public AddressableLightEffect {
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void(AddressableLight &, ESPColor, bool initial_run)> f_;
|
||||
std::function<void(AddressableLight &, Color, bool initial_run)> f_;
|
||||
uint32_t update_interval_;
|
||||
uint32_t last_run_{0};
|
||||
bool initial_run_;
|
||||
@@ -74,7 +74,7 @@ class AddressableLambdaLightEffect : public AddressableLightEffect {
|
||||
class AddressableRainbowLightEffect : public AddressableLightEffect {
|
||||
public:
|
||||
explicit AddressableRainbowLightEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||
ESPHSVColor hsv;
|
||||
hsv.value = 255;
|
||||
hsv.saturation = 240;
|
||||
@@ -106,7 +106,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
|
||||
void set_colors(const std::vector<AddressableColorWipeEffectColor> &colors) { this->colors_ = colors; }
|
||||
void set_add_led_interval(uint32_t add_led_interval) { this->add_led_interval_ = add_led_interval; }
|
||||
void set_reverse(bool reverse) { this->reverse_ = reverse; }
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||
const uint32_t now = millis();
|
||||
if (now - this->last_add_ < this->add_led_interval_)
|
||||
return;
|
||||
@@ -116,7 +116,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
|
||||
else
|
||||
it.shift_right(1);
|
||||
const AddressableColorWipeEffectColor color = this->colors_[this->at_color_];
|
||||
const ESPColor esp_color = ESPColor(color.r, color.g, color.b, color.w);
|
||||
const Color esp_color = Color(color.r, color.g, color.b, color.w);
|
||||
if (this->reverse_)
|
||||
it[-1] = esp_color;
|
||||
else
|
||||
@@ -126,7 +126,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
|
||||
this->at_color_ = (this->at_color_ + 1) % this->colors_.size();
|
||||
AddressableColorWipeEffectColor &new_color = this->colors_[this->at_color_];
|
||||
if (new_color.random) {
|
||||
ESPColor c = ESPColor::random_color();
|
||||
Color c = Color::random_color();
|
||||
new_color.r = c.r;
|
||||
new_color.g = c.g;
|
||||
new_color.b = c.b;
|
||||
@@ -148,8 +148,8 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
explicit AddressableScanEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||
void set_move_interval(uint32_t move_interval) { this->move_interval_ = move_interval; }
|
||||
void set_scan_width(uint32_t scan_width) { this->scan_width_ = scan_width; }
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
it.all() = ESPColor::BLACK;
|
||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||
it.all() = COLOR_BLACK;
|
||||
|
||||
for (auto i = 0; i < this->scan_width_; i++) {
|
||||
it[this->at_led_ + i] = current_color;
|
||||
@@ -181,7 +181,7 @@ class AddressableScanEffect : public AddressableLightEffect {
|
||||
class AddressableTwinkleEffect : public AddressableLightEffect {
|
||||
public:
|
||||
explicit AddressableTwinkleEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||
void apply(AddressableLight &addressable, const ESPColor ¤t_color) override {
|
||||
void apply(AddressableLight &addressable, const Color ¤t_color) override {
|
||||
const uint32_t now = millis();
|
||||
uint8_t pos_add = 0;
|
||||
if (now - this->last_progress_ > this->progress_interval_) {
|
||||
@@ -199,7 +199,7 @@ class AddressableTwinkleEffect : public AddressableLightEffect {
|
||||
else
|
||||
view.set_effect_data(new_pos);
|
||||
} else {
|
||||
view = ESPColor::BLACK;
|
||||
view = COLOR_BLACK;
|
||||
}
|
||||
}
|
||||
while (random_float() < this->twinkle_probability_) {
|
||||
@@ -221,7 +221,7 @@ class AddressableTwinkleEffect : public AddressableLightEffect {
|
||||
class AddressableRandomTwinkleEffect : public AddressableLightEffect {
|
||||
public:
|
||||
explicit AddressableRandomTwinkleEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||
const uint32_t now = millis();
|
||||
uint8_t pos_add = 0;
|
||||
if (now - this->last_progress_ > this->progress_interval_) {
|
||||
@@ -237,7 +237,7 @@ class AddressableRandomTwinkleEffect : public AddressableLightEffect {
|
||||
if (color == 0) {
|
||||
view = current_color * sine;
|
||||
} else {
|
||||
view = ESPColor(((color >> 2) & 1) * sine, ((color >> 1) & 1) * sine, ((color >> 0) & 1) * sine);
|
||||
view = Color(((color >> 2) & 1) * sine, ((color >> 1) & 1) * sine, ((color >> 0) & 1) * sine);
|
||||
}
|
||||
const uint8_t new_x = x + pos_add;
|
||||
if (new_x > 0b11111)
|
||||
@@ -245,7 +245,7 @@ class AddressableRandomTwinkleEffect : public AddressableLightEffect {
|
||||
else
|
||||
view.set_effect_data((new_x << 3) | color);
|
||||
} else {
|
||||
view = ESPColor(0, 0, 0, 0);
|
||||
view = Color(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
while (random_float() < this->twinkle_probability_) {
|
||||
@@ -270,9 +270,9 @@ class AddressableFireworksEffect : public AddressableLightEffect {
|
||||
explicit AddressableFireworksEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||
void start() override {
|
||||
auto &it = *this->get_addressable_();
|
||||
it.all() = ESPColor::BLACK;
|
||||
it.all() = COLOR_BLACK;
|
||||
}
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||
const uint32_t now = millis();
|
||||
if (now - this->last_update_ < this->update_interval_)
|
||||
return;
|
||||
@@ -280,7 +280,7 @@ class AddressableFireworksEffect : public AddressableLightEffect {
|
||||
// "invert" the fade out parameter so that higher values make fade out faster
|
||||
const uint8_t fade_out_mult = 255u - this->fade_out_rate_;
|
||||
for (auto view : it) {
|
||||
ESPColor target = view.get() * fade_out_mult;
|
||||
Color target = view.get() * fade_out_mult;
|
||||
if (target.r < 64)
|
||||
target *= 170;
|
||||
view = target;
|
||||
@@ -294,7 +294,7 @@ class AddressableFireworksEffect : public AddressableLightEffect {
|
||||
if (random_float() < this->spark_probability_) {
|
||||
const size_t pos = random_uint32() % it.size();
|
||||
if (this->use_random_color_) {
|
||||
it[pos] = ESPColor::random_color();
|
||||
it[pos] = Color::random_color();
|
||||
} else {
|
||||
it[pos] = current_color;
|
||||
}
|
||||
@@ -316,7 +316,7 @@ class AddressableFireworksEffect : public AddressableLightEffect {
|
||||
class AddressableFlickerEffect : public AddressableLightEffect {
|
||||
public:
|
||||
explicit AddressableFlickerEffect(const std::string &name) : AddressableLightEffect(name) {}
|
||||
void apply(AddressableLight &it, const ESPColor ¤t_color) override {
|
||||
void apply(AddressableLight &it, const Color ¤t_color) override {
|
||||
const uint32_t now = millis();
|
||||
const uint8_t intensity = this->intensity_;
|
||||
const uint8_t inv_intensity = 255 - intensity;
|
||||
|
||||
Reference in New Issue
Block a user