ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
fastled_light.cpp
Go to the documentation of this file.
1#ifdef USE_ARDUINO
2
3#include "fastled_light.h"
4#include "esphome/core/log.h"
5
6namespace esphome {
7namespace fastled_base {
8
9static const char *const TAG = "fastled";
10
12 this->controller_->init();
13 this->controller_->setLeds(this->leds_, this->num_leds_);
14 this->effect_data_ = new uint8_t[this->num_leds_]; // NOLINT
15 if (!this->max_refresh_rate_.has_value()) {
16 this->set_max_refresh_rate(this->controller_->getMaxRefreshRate());
17 }
18}
20 ESP_LOGCONFIG(TAG,
21 "FastLED light:\n"
22 " Num LEDs: %u\n"
23 " Max refresh rate: %u",
24 this->num_leds_, *this->max_refresh_rate_);
25}
27 // protect from refreshing too often
28 uint32_t now = micros();
29 if (*this->max_refresh_rate_ != 0 && (now - this->last_refresh_) < *this->max_refresh_rate_) {
30 // try again next loop iteration, so that this change won't get lost
31 this->schedule_show();
32 return;
33 }
34 this->last_refresh_ = now;
35 this->mark_shown_();
36
37 ESP_LOGVV(TAG, "Writing RGB values to bus");
38 this->controller_->showLeds(this->state_parent_->current_values.get_brightness() * 255);
39}
40
41} // namespace fastled_base
42} // namespace esphome
43
44#endif // USE_ARDUINO
void write_state(light::LightState *state) override
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:66
LightColorValues current_values
The current values of the light as outputted to the light.
Definition light_state.h:97
bool has_value() const
Definition optional.h:92
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t IRAM_ATTR HOT micros()
Definition core.cpp:30