7 static const char *
const TAG =
"light.addressable";
12 #ifdef ESPHOME_LOG_HAS_VERY_VERBOSE 15 ESP_LOGVV(TAG,
"Addressable Light '%s' (effect_active=%s)", name, YESNO(this->
effect_active_));
16 for (
int i = 0; i < this->
size(); i++) {
17 auto color = this->
get(i);
18 ESP_LOGVV(TAG,
" [%2d] Color: R=%3u G=%3u B=%3u W=%3u", i, color.get_red_raw(), color.get_green_raw(),
19 color.get_blue_raw(), color.get_white_raw());
27 return make_unique<AddressableLightTransformer>(*this);
35 return Color(r, g, b, w);
40 auto max_brightness = to_uint8_scale(
val.get_brightness() *
val.get_state());
53 if (this->light_.is_effect_active())
56 auto end_values = this->target_values_;
60 this->light_.correction_.set_local_brightness(255);
61 this->target_color_ *= to_uint8_scale(end_values.get_brightness() * end_values.get_state());
70 if (this->light_.is_effect_active())
81 float denom = (1.0f - smoothed_progress);
82 float alpha = denom == 0.0f ? 1.0f : (smoothed_progress - this->last_transition_progress_) / denom;
86 float alpha255 = alpha * 255.0f;
87 float alpha255int = floorf(alpha255);
88 float alpha255remainder = alpha255 - alpha255int;
90 this->accumulated_alpha_ += alpha255remainder;
91 float alpha_add = floorf(this->accumulated_alpha_);
92 this->accumulated_alpha_ -= alpha_add;
94 alpha255 += alpha_add;
95 alpha255 =
clamp(alpha255, 0.0f, 255.0f);
96 auto alpha8 =
static_cast<uint8_t
>(alpha255);
99 uint8_t inv_alpha8 = 255 - alpha8;
100 Color add = this->target_color_ * alpha8;
102 for (
auto led : this->light_)
103 led.set(add + led.get() * inv_alpha8);
106 this->last_transition_progress_ = smoothed_progress;
107 this->light_.schedule_show();
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
std::unique_ptr< LightTransformer > create_default_transition() override
LightColorValues current_values
The current values of the light as outputted to the light.
float get_red() const
Get the red property of these light color values. In range 0.0 to 1.0.
LightState * state_parent_
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
float get_blue() const
Get the blue property of these light color values. In range 0.0 to 1.0.
void call_setup() override
This class represents the color state for a light object.
float get_white() const
Get the white property of these light color values. In range 0.0 to 1.0.
void update_state(LightState *state) override
virtual void setup()
Where the component's initialization should happen.
bool is_effect_active() const
void set_local_brightness(uint8_t local_brightness)
virtual int32_t size() const =0
constexpr const char * c_str() const
Color color_from_light_color_values(LightColorValues val)
Convert the color information from a LightColorValues object to a Color object (does not apply bright...
ESPColorCorrection correction_
Implementation of SPI Controller mode.
float get_color_brightness() const
Get the color brightness property of these light color values. In range 0.0 to 1.0.
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion)
Linearly interpolate between the values in start to the values in end.
float get_green() const
Get the green property of these light color values. In range 0.0 to 1.0.
const StringRef & get_name() const