ESPHome  2024.10.2
gp8403_output.cpp
Go to the documentation of this file.
1 #include "gp8403_output.h"
2 
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace gp8403 {
7 
8 static const char *const TAG = "gp8403.output";
9 
10 static const uint8_t OUTPUT_REGISTER = 0x02;
11 
13  ESP_LOGCONFIG(TAG, "GP8403 Output:");
14  ESP_LOGCONFIG(TAG, " Channel: %u", this->channel_);
15 }
16 
18  uint16_t value = ((uint16_t) (state * 4095)) << 4;
19  i2c::ErrorCode err = this->parent_->write_register(OUTPUT_REGISTER + (2 * this->channel_), (uint8_t *) &value, 2);
20  if (err != i2c::ERROR_OK) {
21  ESP_LOGE(TAG, "Error writing to GP8403, code %d", err);
22  }
23 }
24 
25 } // namespace gp8403
26 } // namespace esphome
void write_state(float state) override
No error found during execution of method.
Definition: i2c_bus.h:13
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition: i2c_bus.h:11
bool state
Definition: fan.h:34