ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
sm16716.cpp
Go to the documentation of this file.
1#include "sm16716.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace sm16716 {
6
7static const char *const TAG = "sm16716";
8
10 this->data_pin_->setup();
11 this->data_pin_->digital_write(false);
12 this->clock_pin_->setup();
13 this->clock_pin_->digital_write(false);
14 this->pwm_amounts_.resize(this->num_channels_, 0);
15}
17 ESP_LOGCONFIG(TAG, "SM16716:");
18 LOG_PIN(" Data Pin: ", this->data_pin_);
19 LOG_PIN(" Clock Pin: ", this->clock_pin_);
20 ESP_LOGCONFIG(TAG, " Total number of channels: %u", this->num_channels_);
21 ESP_LOGCONFIG(TAG, " Number of chips: %u", this->num_chips_);
22}
24 if (!this->update_)
25 return;
26
27 for (uint8_t i = 0; i < 50; i++) {
28 this->write_bit_(false);
29 }
30
31 // send 25 bits (1 start bit plus 24 data bits) for each chip
32 for (uint8_t index = 0; index < this->num_channels_; index++) {
33 // send a start bit initially and after every 3 channels
34 if (index % 3 == 0) {
35 this->write_bit_(true);
36 }
37
38 this->write_byte_(this->pwm_amounts_[index]);
39 }
40
41 // send a blank 25 bits to signal the end
42 this->write_bit_(false);
43 this->write_byte_(0);
44 this->write_byte_(0);
45 this->write_byte_(0);
46
47 this->update_ = false;
48}
49
50} // namespace sm16716
51} // namespace esphome
virtual void setup()=0
virtual void digital_write(bool value)=0
void dump_config() override
Definition sm16716.cpp:16
std::vector< uint8_t > pwm_amounts_
Definition sm16716.h:67
void write_byte_(uint8_t data)
Definition sm16716.h:57
void loop() override
Send new values if they were updated.
Definition sm16716.cpp:23
void write_bit_(bool value)
Definition sm16716.h:52
void setup() override
Definition sm16716.cpp:9
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7