Skip to content

Commit

Permalink
x9c: fix off by 1 error (esphome#6318)
Browse files Browse the repository at this point in the history
  • Loading branch information
andynumber2 authored Mar 4, 2024
1 parent 56837b0 commit f3ed091
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions esphome/components/x9c/x9c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ void X9cOutput::setup() {

if (this->initial_value_ <= 0.50) {
this->trim_value(-101); // Set min value (beyond 0)
this->trim_value((int) (this->initial_value_ * 100));
this->trim_value(static_cast<uint32_t>(roundf(this->initial_value_ * 100)));
} else {
this->trim_value(101); // Set max value (beyond 100)
this->trim_value((int) (this->initial_value_ * 100) - 100);
this->trim_value(static_cast<uint32_t>(roundf(this->initial_value_ * 100) - 100));
}
this->pot_value_ = this->initial_value_;
this->write_state(this->initial_value_);
}

void X9cOutput::write_state(float state) {
this->trim_value((int) ((state - this->pot_value_) * 100));
this->trim_value(static_cast<uint32_t>(roundf((state - this->pot_value_) * 100)));
this->pot_value_ = state;
}

Expand Down

0 comments on commit f3ed091

Please sign in to comment.