ESPHome  2024.10.2
bp1658cj.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 bp1658cj {
10 
11 class BP1658CJ : public Component {
12  public:
13  class Channel;
14 
15  void set_data_pin(GPIOPin *data_pin) { data_pin_ = data_pin; }
16  void set_clock_pin(GPIOPin *clock_pin) { clock_pin_ = clock_pin; }
17  void set_max_power_color_channels(uint8_t max_power_color_channels) {
18  max_power_color_channels_ = max_power_color_channels;
19  }
20  void set_max_power_white_channels(uint8_t max_power_white_channels) {
21  max_power_white_channels_ = max_power_white_channels;
22  }
23 
24  void setup() override;
25 
26  void dump_config() override;
27 
28  float get_setup_priority() const override { return setup_priority::HARDWARE; }
29 
31  void loop() override;
32 
33  class Channel : public output::FloatOutput {
34  public:
35  void set_parent(BP1658CJ *parent) { parent_ = parent; }
36  void set_channel(uint8_t channel) { channel_ = channel; }
37 
38  protected:
39  void write_state(float state) override {
40  auto amount = static_cast<uint16_t>(state * 0x3FF);
41  this->parent_->set_channel_value_(this->channel_, amount);
42  }
43 
45  uint8_t channel_;
46  };
47 
48  protected:
49  void set_channel_value_(uint8_t channel, uint16_t value);
50  void write_bit_(bool value);
51  void write_byte_(uint8_t data);
52  void write_buffer_(uint8_t *buffer, uint8_t size);
53 
58  uint8_t update_channel_;
59  std::vector<uint16_t> pwm_amounts_;
60  bool update_{true};
61 };
62 
63 } // namespace bp1658cj
64 } // namespace esphome
void dump_config() override
Definition: bp1658cj.cpp:25
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
void setup() override
Definition: bp1658cj.cpp:17
void set_parent(BP1658CJ *parent)
Definition: bp1658cj.h:35
void set_data_pin(GPIOPin *data_pin)
Definition: bp1658cj.h:15
void write_state(float state) override
Definition: bp1658cj.h:39
void write_buffer_(uint8_t *buffer, uint8_t size)
Definition: bp1658cj.cpp:114
void set_clock_pin(GPIOPin *clock_pin)
Definition: bp1658cj.h:16
uint8_t max_power_color_channels_
Definition: bp1658cj.h:56
void set_channel_value_(uint8_t channel, uint16_t value)
Definition: bp1658cj.cpp:83
float get_setup_priority() const override
Definition: bp1658cj.h:28
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:18
void loop() override
Send new values if they were updated.
Definition: bp1658cj.cpp:33
void write_bit_(bool value)
Definition: bp1658cj.cpp:91
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::vector< uint16_t > pwm_amounts_
Definition: bp1658cj.h:59
void set_max_power_white_channels(uint8_t max_power_white_channels)
Definition: bp1658cj.h:20
void set_max_power_color_channels(uint8_t max_power_color_channels)
Definition: bp1658cj.h:17
void set_channel(uint8_t channel)
Definition: bp1658cj.h:36
void write_byte_(uint8_t data)
Definition: bp1658cj.cpp:100
uint8_t max_power_white_channels_
Definition: bp1658cj.h:57
bool state
Definition: fan.h:34