ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
bp1658cj.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6#include <vector>
7
8namespace esphome::bp1658cj {
9
10class BP1658CJ : public Component {
11 public:
12 class Channel;
13
14 void set_data_pin(GPIOPin *data_pin) { data_pin_ = data_pin; }
15 void set_clock_pin(GPIOPin *clock_pin) { clock_pin_ = clock_pin; }
16 void set_max_power_color_channels(uint8_t max_power_color_channels) {
17 max_power_color_channels_ = max_power_color_channels;
18 }
19 void set_max_power_white_channels(uint8_t max_power_white_channels) {
20 max_power_white_channels_ = max_power_white_channels;
21 }
22
23 void setup() override;
24
25 void dump_config() override;
26
27 float get_setup_priority() const override { return setup_priority::HARDWARE; }
28
30 void loop() override;
31
33 public:
34 void set_parent(BP1658CJ *parent) { parent_ = parent; }
35 void set_channel(uint8_t channel) { channel_ = channel; }
36
37 protected:
38 void write_state(float state) override {
39 auto amount = static_cast<uint16_t>(state * 0x3FF);
40 this->parent_->set_channel_value_(this->channel_, amount);
41 }
42
44 uint8_t channel_;
45 };
46
47 protected:
48 void set_channel_value_(uint8_t channel, uint16_t value);
49 void write_bit_(bool value);
50 void write_byte_(uint8_t data);
51 void write_buffer_(uint8_t *buffer, uint8_t size);
52
58 std::vector<uint16_t> pwm_amounts_;
59 bool update_{true};
60};
61
62} // namespace esphome::bp1658cj
void write_state(float state) override
Definition bp1658cj.h:38
void set_channel(uint8_t channel)
Definition bp1658cj.h:35
void set_parent(BP1658CJ *parent)
Definition bp1658cj.h:34
void dump_config() override
Definition bp1658cj.cpp:23
std::vector< uint16_t > pwm_amounts_
Definition bp1658cj.h:58
void write_buffer_(uint8_t *buffer, uint8_t size)
Definition bp1658cj.cpp:114
void loop() override
Send new values if they were updated.
Definition bp1658cj.cpp:33
void write_bit_(bool value)
Definition bp1658cj.cpp:91
void set_channel_value_(uint8_t channel, uint16_t value)
Definition bp1658cj.cpp:83
void set_max_power_color_channels(uint8_t max_power_color_channels)
Definition bp1658cj.h:16
float get_setup_priority() const override
Definition bp1658cj.h:27
void set_clock_pin(GPIOPin *clock_pin)
Definition bp1658cj.h:15
void set_data_pin(GPIOPin *data_pin)
Definition bp1658cj.h:14
void set_max_power_white_channels(uint8_t max_power_white_channels)
Definition bp1658cj.h:19
void write_byte_(uint8_t data)
Definition bp1658cj.cpp:100
Base class for all output components that can output a variable level, like PWM.
bool state
Definition fan.h:2
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:41
uint16_t size
Definition helpers.cpp:25