ESPHome  2024.11.0
sm10bit_base.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 #include <vector>
7 
8 namespace esphome {
9 namespace sm10bit_base {
10 
11 class Sm10BitBase : public Component {
12  public:
13  class Channel;
14 
15  void set_model(uint8_t model_id) { model_id_ = model_id; }
16  void set_data_pin(GPIOPin *data_pin) { data_pin_ = data_pin; }
17  void set_clock_pin(GPIOPin *clock_pin) { clock_pin_ = clock_pin; }
18  void set_max_power_color_channels(uint8_t max_power_color_channels) {
19  max_power_color_channels_ = max_power_color_channels;
20  }
21  void set_max_power_white_channels(uint8_t max_power_white_channels) {
22  max_power_white_channels_ = max_power_white_channels;
23  }
24 
25  float get_setup_priority() const override { return setup_priority::HARDWARE; }
26 
27  void setup() override;
28  void dump_config() override;
29  void loop() override;
30 
31  class Channel : public output::FloatOutput {
32  public:
33  void set_parent(Sm10BitBase *parent) { parent_ = parent; }
34  void set_channel(uint8_t channel) { channel_ = channel; }
35 
36  protected:
37  void write_state(float state) override {
38  auto amount = static_cast<uint16_t>(state * 0x3FF);
39  this->parent_->set_channel_value_(this->channel_, amount);
40  }
41 
43  uint8_t channel_;
44  };
45 
46  protected:
47  void set_channel_value_(uint8_t channel, uint16_t value);
48  void write_bit_(bool value);
49  void write_byte_(uint8_t data);
50  void write_buffer_(uint8_t *buffer, uint8_t size);
51 
54  uint8_t model_id_;
57  uint8_t update_channel_;
58  std::vector<uint16_t> pwm_amounts_;
59  bool update_{true};
60 };
61 
62 } // namespace sm10bit_base
63 } // namespace esphome
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
void write_state(float state) override
Definition: sm10bit_base.h:37
void set_parent(Sm10BitBase *parent)
Definition: sm10bit_base.h:33
std::vector< uint16_t > pwm_amounts_
Definition: sm10bit_base.h:58
float get_setup_priority() const override
Definition: sm10bit_base.h:25
void set_model(uint8_t model_id)
Definition: sm10bit_base.h:15
void set_data_pin(GPIOPin *data_pin)
Definition: sm10bit_base.h:16
void set_max_power_color_channels(uint8_t max_power_color_channels)
Definition: sm10bit_base.h:18
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
void write_buffer_(uint8_t *buffer, uint8_t size)
void set_clock_pin(GPIOPin *clock_pin)
Definition: sm10bit_base.h:17
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_max_power_white_channels(uint8_t max_power_white_channels)
Definition: sm10bit_base.h:21
void set_channel_value_(uint8_t channel, uint16_t value)
bool state
Definition: fan.h:34