ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
fastled_light.cpp
Go to the documentation of this file.
1#if defined(USE_ARDUINO) && !defined(USE_RP2) && !defined(USE_LIBRETINY)
2
3#include "fastled_light.h"
4#include "esphome/core/log.h"
5
7
8ESPHOME_LOG_TAG(TAG, "fastled");
9
11 this->controller_->init();
12 this->controller_->setLeds(this->leds_, this->num_leds_);
13 this->internal_accessor_.color_data = this->leds_[0].raw;
14 this->internal_accessor_.effect_data = new uint8_t[this->num_leds_]; // NOLINT
15 this->accessor_ = &this->internal_accessor_;
16 if (!this->max_refresh_rate_.has_value()) {
17 this->set_max_refresh_rate(this->controller_->getMaxRefreshRate());
18 }
19}
21 ESP_LOGCONFIG(TAG,
22 "FastLED light:\n"
23 " Num LEDs: %u\n"
24 " Max refresh rate: %" PRIu32,
25 this->num_leds_, this->max_refresh_rate_.value_or(0));
26}
28 // protect from refreshing too often
29 uint32_t now = micros();
30 uint32_t max_rate = this->max_refresh_rate_.value_or(0);
31 if (max_rate != 0 && (now - this->last_refresh_) < max_rate) {
32 // try again next loop iteration, so that this change won't get lost
33 this->schedule_show();
34 return;
35 }
36 this->last_refresh_ = now;
37 this->mark_shown_();
38
39 ESP_LOGVV(TAG, "Writing RGB values to bus");
40 this->controller_->showLeds(this->state_parent_->current_values.get_brightness() * 255);
41}
42
43} // namespace esphome::fastled_base
44
45#endif // USE_ARDUINO
void write_state(light::LightState *state) override
light::CorrectedBufferColorAccessor internal_accessor_
void set_max_refresh_rate(uint32_t interval_us)
Set a maximum refresh rate in µs as some lights do not like being updated too often.
float get_brightness() const
Get the brightness property of these light color values. In range 0.0 to 1.0.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:68
LightColorValues current_values
The current values of the light as outputted to the light.
bool state
Definition fan.h:2
ESPHOME_LOG_TAG(TAG, "fastled")
uint32_t IRAM_ATTR HOT micros()
Definition hal.cpp:43
static void uint32_t