ESPHome 2026.5.1
Loading...
Searching...
No Matches
m5stack_8angle_light.cpp
Go to the documentation of this file.
2
3#include "esphome/core/log.h"
4
6
7static const char *const TAG = "m5stack_8angle.light";
8
10 RAMAllocator<uint8_t> allocator;
11 this->buf_ = allocator.allocate(M5STACK_8ANGLE_NUM_LEDS * M5STACK_8ANGLE_BYTES_PER_LED);
12 if (this->buf_ == nullptr) {
13 ESP_LOGE(TAG, "Failed to allocate buffer of size %u", M5STACK_8ANGLE_NUM_LEDS * M5STACK_8ANGLE_BYTES_PER_LED);
14 this->mark_failed();
15 return;
16 };
17 memset(this->buf_, 0xFF, M5STACK_8ANGLE_NUM_LEDS * M5STACK_8ANGLE_BYTES_PER_LED);
18
19 this->effect_data_ = allocator.allocate(M5STACK_8ANGLE_NUM_LEDS);
20 if (this->effect_data_ == nullptr) {
21 ESP_LOGE(TAG, "Failed to allocate effect data of size %u", M5STACK_8ANGLE_NUM_LEDS);
22 this->mark_failed();
23 return;
24 };
25 memset(this->effect_data_, 0x00, M5STACK_8ANGLE_NUM_LEDS);
26}
27
29 for (int i = 0; i < M5STACK_8ANGLE_NUM_LEDS;
30 i++) { // write one LED at a time, otherwise the message will be truncated
31 this->parent_->write_register(M5STACK_8ANGLE_REGISTER_RGB_24B + i * M5STACK_8ANGLE_BYTES_PER_LED,
32 this->buf_ + i * M5STACK_8ANGLE_BYTES_PER_LED, M5STACK_8ANGLE_BYTES_PER_LED);
33 }
34}
35
37 size_t pos = index * M5STACK_8ANGLE_BYTES_PER_LED;
38 // red, green, blue, white, effect_data, color_correction
39 return {this->buf_ + pos, this->buf_ + pos + 1, this->buf_ + pos + 2,
40 nullptr, this->effect_data_ + index, &this->correction_};
41}
42
43} // namespace esphome::m5stack_8angle
void mark_failed()
Mark this component as failed.
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2053
T * allocate(size_t n)
Definition helpers.h:2080
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
light::ESPColorView get_view_internal(int32_t index) const override
void write_state(light::LightState *state) override
bool state
Definition fan.h:2
size_t size_t pos
Definition helpers.h:1038