ESPHome  2024.10.2
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 
6 namespace esphome {
7 namespace fastled_base {
8 
9 static 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();
38 }
39 
40 } // namespace fastled_base
41 } // namespace esphome
42 
43 #endif // USE_ARDUINO
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:34
bool has_value() const
Definition: optional.h:87
uint32_t IRAM_ATTR HOT micros()
Definition: core.cpp:27
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
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.
Definition: fastled_light.h:29
bool state
Definition: fan.h:34