ESPHome 2025.7.4
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 ESP_LOGCONFIG(TAG, "Running setup");
13 this->controller_->init();
14 this->controller_->setLeds(this->leds_, this->num_leds_);
15 this->effect_data_ = new uint8_t[this->num_leds_]; // NOLINT
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: %u",
25 this->num_leds_, *this->max_refresh_rate_);
26}
28 // protect from refreshing too often
29 uint32_t now = micros();
30 if (*this->max_refresh_rate_ != 0 && (now - this->last_refresh_) < *this->max_refresh_rate_) {
31 // try again next loop iteration, so that this change won't get lost
32 this->schedule_show();
33 return;
34 }
35 this->last_refresh_ = now;
36 this->mark_shown_();
37
38 ESP_LOGVV(TAG, "Writing RGB values to bus");
39 this->controller_->showLeds(this->state_parent_->current_values.get_brightness() * 255);
40}
41
42} // namespace fastled_base
43} // namespace esphome
44
45#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