Skip to content

Commit

Permalink
Merge pull request arthurrump#3 from FreeBear-nc/main
Browse files Browse the repository at this point in the history
Rework output function to interpolate between min|max limits.
  • Loading branch information
olegtarasov authored Aug 5, 2024
2 parents ea3f5bb + c10e6f1 commit 6ddabef
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions components/opentherm/output/output.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "esphome/core/helpers.h" // for clamp()
#include "esphome/core/helpers.h" // for clamp() and lerp()
#include "output.h"

namespace esphome {
namespace opentherm {

void opentherm::OpenthermOutput::write_state(float state) {
ESP_LOGD("opentherm.output", "Received state: %.2f. Min value: %.2f, max value: %.2f", state, min_value_, max_value_);
this->state = state < 0.003 && this->zero_means_zero_ ? 0.0 : clamp(min_value_ + state * (max_value_ - min_value_), min_value_, max_value_);
state = state < 0.003 && this->zero_means_zero_ ? 0.0 : lerp(state, min_value_, max_value_);
this->state = clamp(state, min_value_, max_value_);
this->has_state_ = true;
ESP_LOGD("opentherm.output", "Output %s set to %.2f", this->id_, this->state);
}
Expand Down

0 comments on commit 6ddabef

Please sign in to comment.