mirror of
https://github.com/esphome/esphome.git
synced 2025-03-13 22:28:14 +00:00
Update mcp4461_output.cpp
This commit is contained in:
parent
b6a27a70cc
commit
89abf35b70
@ -12,6 +12,13 @@ static const char *const TAG = "mcp4461.output";
|
||||
// floats from other components (like light etc.) are passed as "percentage floats"
|
||||
// this function converts them to the 0 - 256 range used by the MCP4461
|
||||
void Mcp4461Wiper::write_state(float state) {
|
||||
if (!std::isfinite(state)) {
|
||||
return;
|
||||
}
|
||||
state = clamp(state, 0.0f, 1.0f);
|
||||
if (this->is_inverted()) {
|
||||
state = 1.0f - state;
|
||||
}
|
||||
if (this->parent_->set_wiper_level_(this->wiper_, static_cast<uint16_t>(std::roundf(state * 256)))) {
|
||||
this->state_ = state;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user