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