ESPHome 2025.5.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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, "Setting up FastLED light...");
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, "FastLED light:");
22 ESP_LOGCONFIG(TAG, " Num LEDs: %u", this->num_leds_);
23 ESP_LOGCONFIG(TAG, " Max refresh rate: %u", *this->max_refresh_rate_);
24}
26 // protect from refreshing too often
27 uint32_t now = micros();
28 if (*this->max_refresh_rate_ != 0 && (now - this->last_refresh_) < *this->max_refresh_rate_) {
29 // try again next loop iteration, so that this change won't get lost
30 this->schedule_show();
31 return;
32 }
33 this->last_refresh_ = now;
34 this->mark_shown_();
35
36 ESP_LOGVV(TAG, "Writing RGB values to bus...");
37 this->controller_->showLeds(this->state_parent_->current_values.get_brightness() * 255);
38}
39
40} // namespace fastled_base
41} // namespace esphome
42
43#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:63
LightColorValues current_values
The current values of the light as outputted to the light.
Definition light_state.h:94
bool has_value() const
Definition optional.h:87
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