7 static const char *
const TAG =
"adalight_light_effect";
9 static const uint32_t ADALIGHT_ACK_INTERVAL = 1000;
10 static const uint32_t ADALIGHT_RECEIVE_TIMEOUT = 1000;
15 AddressableLightEffect::start();
25 AddressableLightEffect::stop();
33 return 3 + 2 + 1 + led_count * 3;
40 frame_.reserve(buffer_capacity);
44 for (
int led = it.
size(); led-- > 0;) {
51 const uint32_t now =
millis();
53 if (now - this->
last_ack_ >= ADALIGHT_ACK_INTERVAL) {
54 ESP_LOGV(TAG,
"Sending ACK");
60 ESP_LOGW(TAG,
"Frame: Reset.");
66 if (!this->
frame_.empty() && now - this->
last_byte_ >= ADALIGHT_RECEIVE_TIMEOUT) {
67 ESP_LOGW(TAG,
"Frame: Receive timeout (size=%zu).", this->
frame_.size());
73 ESP_LOGV(TAG,
"Frame: Available (size=%d).", this->
available());
80 this->
frame_.push_back(data);
81 this->last_byte_ = now;
85 ESP_LOGD(TAG,
"Frame: Invalid (size=%zu, first=%d).", this->
frame_.size(), this->
frame_[0]);
93 ESP_LOGV(TAG,
"Frame: Consumed (size=%zu).", this->
frame_.size());
118 if (checksum != frame_[5])
122 uint16_t led_count = (frame_[3] << 8) + frame_[4] + 1;
124 if (frame_.size() < buffer_size)
128 auto accepted_led_count = std::min<int>(led_count, it.
size());
129 uint8_t *led_data = &frame_[6];
131 for (
int led = 0; led < accepted_led_count; led++, led_data += 3) {
132 auto white = std::min(std::min(led_data[0], led_data[1]), led_data[2]);
134 it[led].set(
Color(led_data[0], led_data[1], led_data[2], white));
void reset_frame_(light::AddressableLight &it)
void write_str(const char *str)
AdalightLightEffect(const std::string &name)
Frame parse_frame_(light::AddressableLight &it)
void blank_all_leds_(light::AddressableLight &it)
uint32_t IRAM_ATTR HOT millis()
bool read_byte(uint8_t *data)
virtual int32_t size() const =0
std::vector< uint8_t > frame_
unsigned int get_frame_size_(int led_count) const
Implementation of SPI Controller mode.