refactor mcp4728 component (#5609)

Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
Samuel Sieb
2023-10-26 22:01:18 -07:00
committed by GitHub
parent 907d43827c
commit c83cb30935
6 changed files with 52 additions and 34 deletions
@@ -0,0 +1,17 @@
#include "mcp4728_output.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome {
namespace mcp4728 {
void MCP4728Channel::write_state(float state) {
const uint16_t max_duty = 4095;
const float duty_rounded = roundf(state * max_duty);
auto duty = static_cast<uint16_t>(duty_rounded);
this->parent_->set_channel_value_(this->channel_, duty);
}
} // namespace mcp4728
} // namespace esphome