ESPHome  2024.10.2
m5stack_8angle_light.cpp
Go to the documentation of this file.
1 #include "m5stack_8angle_light.h"
2 
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace m5stack_8angle {
7 
8 static 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
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:34
void write_state(light::LightState *state) override
M5Stack8AngleComponent * parent_
Definition: helpers.h:532
light::ESPColorView get_view_internal(int32_t index) const override
virtual void mark_failed()
Mark this component as failed.
Definition: component.cpp:118
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool state
Definition: fan.h:34