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