mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 10:44:13 +01:00
Some fixes, added an ability to clear calibration
This commit is contained in:
parent
054728ec0b
commit
1bdeb405f2
2 changed files with 22 additions and 7 deletions
|
@ -574,6 +574,7 @@ void ShellyDimmer::start_calibration() {
|
|||
this->set_brightness_no_transition_(1);
|
||||
|
||||
// Init calibration data
|
||||
this->calibration_data_.fill(0);
|
||||
this->calibration_measurements_.fill(0);
|
||||
this->calibration_measurement_cnt_ = 0;
|
||||
this->calibration_step_ = -20;
|
||||
|
@ -646,11 +647,7 @@ void ShellyDimmer::complete_calibration_() {
|
|||
value = remap(value, min, max, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
if (this->rtc_.save(&this->calibration_data_)) {
|
||||
ESP_LOGD(TAG, "Saved calibration to flash");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Couldn't save calibration to flash");
|
||||
}
|
||||
this->save_calibration_();
|
||||
|
||||
ESP_LOGD(TAG, "Finished calibration. Values:");
|
||||
for (float value : this->calibration_data_) {
|
||||
|
@ -659,6 +656,13 @@ void ShellyDimmer::complete_calibration_() {
|
|||
|
||||
this->set_brightness_no_transition_(1);
|
||||
}
|
||||
void ShellyDimmer::save_calibration_() {
|
||||
if (this->rtc_.save(&this->calibration_data_)) {
|
||||
ESP_LOGD(TAG, "Saved calibration to flash");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Couldn't save calibration to flash");
|
||||
}
|
||||
}
|
||||
void ShellyDimmer::set_brightness_no_transition_(float brightness) {
|
||||
auto call = this->state_->make_call();
|
||||
call.set_brightness(brightness);
|
||||
|
@ -666,6 +670,10 @@ void ShellyDimmer::set_brightness_no_transition_(float brightness) {
|
|||
call.set_state(true);
|
||||
call.perform();
|
||||
}
|
||||
void ShellyDimmer::clear_calibration() {
|
||||
this->calibration_data_.fill(0);
|
||||
this->save_calibration_();
|
||||
}
|
||||
|
||||
} // namespace shelly_dimmer
|
||||
} // namespace esphome
|
||||
|
|
|
@ -50,8 +50,12 @@ class ShellyDimmer : public PollingComponent, public light::LightOutput, public
|
|||
void set_voltage_sensor(sensor::Sensor *voltage_sensor) { this->voltage_sensor_ = voltage_sensor; }
|
||||
void set_current_sensor(sensor::Sensor *current_sensor) { this->current_sensor_ = current_sensor; }
|
||||
|
||||
/// Starts the calibration process.
|
||||
void start_calibration();
|
||||
|
||||
/// Clears calibration values.
|
||||
void clear_calibration();
|
||||
|
||||
protected:
|
||||
GPIOPin *pin_nrst_;
|
||||
GPIOPin *pin_boot0_;
|
||||
|
@ -132,10 +136,13 @@ class ShellyDimmer : public PollingComponent, public light::LightOutput, public
|
|||
/// Complete a single calibration step averaging over accumulated measurements.
|
||||
void complete_calibration_step_();
|
||||
|
||||
// Complete the whole calibration process.
|
||||
/// Complete the whole calibration process.
|
||||
void complete_calibration_();
|
||||
|
||||
// Set brightness with no transition during calibration.
|
||||
/// Saves calibration values to flash.
|
||||
void save_calibration_();
|
||||
|
||||
/// Set brightness with no transition during calibration.
|
||||
void set_brightness_no_transition_(float brightness);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue