x9c: fix off by 1 error (#6318)

This commit is contained in:
Andy Barcinski 2024-03-04 12:18:18 -08:00 committed by GitHub
parent 56837b0947
commit f3ed091395
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}