mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Apply color brightness to addressable light effects (#2321)
This commit is contained in:
parent
30eca885c9
commit
50da630811
3 changed files with 8 additions and 8 deletions
|
@ -27,7 +27,7 @@ std::unique_ptr<LightTransformer> AddressableLight::create_default_transition()
|
||||||
return make_unique<AddressableLightTransformer>(*this);
|
return make_unique<AddressableLightTransformer>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color esp_color_from_light_color_values(LightColorValues val) {
|
Color color_from_light_color_values(LightColorValues val) {
|
||||||
auto r = to_uint8_scale(val.get_color_brightness() * val.get_red());
|
auto r = to_uint8_scale(val.get_color_brightness() * val.get_red());
|
||||||
auto g = to_uint8_scale(val.get_color_brightness() * val.get_green());
|
auto g = to_uint8_scale(val.get_color_brightness() * val.get_green());
|
||||||
auto b = to_uint8_scale(val.get_color_brightness() * val.get_blue());
|
auto b = to_uint8_scale(val.get_color_brightness() * val.get_blue());
|
||||||
|
@ -44,7 +44,7 @@ void AddressableLight::update_state(LightState *state) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// don't use LightState helper, gamma correction+brightness is handled by ESPColorView
|
// don't use LightState helper, gamma correction+brightness is handled by ESPColorView
|
||||||
this->all() = esp_color_from_light_color_values(val);
|
this->all() = color_from_light_color_values(val);
|
||||||
this->schedule_show();
|
this->schedule_show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ void AddressableLightTransformer::start() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto end_values = this->target_values_;
|
auto end_values = this->target_values_;
|
||||||
this->target_color_ = esp_color_from_light_color_values(end_values);
|
this->target_color_ = color_from_light_color_values(end_values);
|
||||||
|
|
||||||
// our transition will handle brightness, disable brightness in correction.
|
// our transition will handle brightness, disable brightness in correction.
|
||||||
this->light_.correction_.set_local_brightness(255);
|
this->light_.correction_.set_local_brightness(255);
|
||||||
|
|
|
@ -19,6 +19,9 @@ namespace light {
|
||||||
|
|
||||||
using ESPColor ESPDEPRECATED("esphome::light::ESPColor is deprecated, use esphome::Color instead.", "v1.21") = Color;
|
using ESPColor ESPDEPRECATED("esphome::light::ESPColor is deprecated, use esphome::Color instead.", "v1.21") = Color;
|
||||||
|
|
||||||
|
/// Convert the color information from a `LightColorValues` object to a `Color` object (does not apply brightness).
|
||||||
|
Color color_from_light_color_values(LightColorValues val);
|
||||||
|
|
||||||
class AddressableLight : public LightOutput, public Component {
|
class AddressableLight : public LightOutput, public Component {
|
||||||
public:
|
public:
|
||||||
virtual int32_t size() const = 0;
|
virtual int32_t size() const = 0;
|
||||||
|
|
|
@ -38,11 +38,8 @@ class AddressableLightEffect : public LightEffect {
|
||||||
void stop() override { this->get_addressable_()->set_effect_active(false); }
|
void stop() override { this->get_addressable_()->set_effect_active(false); }
|
||||||
virtual void apply(AddressableLight &it, const Color ¤t_color) = 0;
|
virtual void apply(AddressableLight &it, const Color ¤t_color) = 0;
|
||||||
void apply() override {
|
void apply() override {
|
||||||
LightColorValues color = this->state_->remote_values;
|
// not using any color correction etc. that will be handled by the addressable layer through ESPColorCorrection
|
||||||
// not using any color correction etc. that will be handled by the addressable layer
|
Color current_color = color_from_light_color_values(this->state_->remote_values);
|
||||||
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);
|
this->apply(*this->get_addressable_(), current_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue