mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
feat: SCD30 support pressure compensation updates
This commit is contained in:
parent
cdcb25be8e
commit
541d8ce451
2 changed files with 26 additions and 6 deletions
|
@ -102,15 +102,17 @@ void SCD30Component::setup() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Sensor initialization
|
/// Sensor initialization
|
||||||
if (!this->write_command(SCD30_CMD_START_CONTINUOUS_MEASUREMENTS, this->ambient_pressure_compensation_)) {
|
restart_continuous_measurements_();
|
||||||
ESP_LOGE(TAG, "Sensor SCD30 error starting continuous measurements.");
|
|
||||||
this->error_code_ = MEASUREMENT_INIT_FAILED;
|
|
||||||
this->mark_failed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check each 500ms if data is ready, and read it in that case
|
// check each 500ms if data is ready, and read it in that case
|
||||||
this->set_interval("status-check", 500, [this]() {
|
this->set_interval("status-check", 500, [this]() {
|
||||||
|
// remove millibar from comparison to avoid frequent updates +/- 10 millibar doesn't matter
|
||||||
|
if (this->current_ambient_pressure_compensation_ / 10 != this->ambient_pressure_compensation_ / 10) {
|
||||||
|
ESP_LOGD(TAG, "ambient pressure compensation triggered; restarting measurements");
|
||||||
|
this->restart_continuous_measurements_();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this->is_data_ready_())
|
if (this->is_data_ready_())
|
||||||
this->update();
|
this->update();
|
||||||
});
|
});
|
||||||
|
@ -229,5 +231,21 @@ uint16_t SCD30Component::get_forced_calibration_reference() {
|
||||||
return forced_calibration_reference;
|
return forced_calibration_reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SCD30Component::restart_continuous_measurements_() {
|
||||||
|
if (!this->write_command(SCD30_CMD_STOP_MEASUREMENTS, this->ambient_pressure_compensation_)) {
|
||||||
|
ESP_LOGE(TAG, "Sensor SCD30 error stopping continuous measurements.");
|
||||||
|
this->error_code_ = MEASUREMENT_INIT_FAILED;
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this->write_command(SCD30_CMD_START_CONTINUOUS_MEASUREMENTS, this->ambient_pressure_compensation_)) {
|
||||||
|
ESP_LOGE(TAG, "Sensor SCD30 error starting continuous measurements.");
|
||||||
|
this->error_code_ = MEASUREMENT_INIT_FAILED;
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->current_ambient_pressure_compensation_ = this->ambient_pressure_compensation_;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace scd30
|
} // namespace scd30
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -30,6 +30,7 @@ class SCD30Component : public Component, public sensirion_common::SensirionI2CDe
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool is_data_ready_();
|
bool is_data_ready_();
|
||||||
|
void restart_continuous_measurements_();
|
||||||
|
|
||||||
enum ErrorCode {
|
enum ErrorCode {
|
||||||
COMMUNICATION_FAILED,
|
COMMUNICATION_FAILED,
|
||||||
|
@ -41,6 +42,7 @@ class SCD30Component : public Component, public sensirion_common::SensirionI2CDe
|
||||||
bool enable_asc_{true};
|
bool enable_asc_{true};
|
||||||
uint16_t altitude_compensation_{0xFFFF};
|
uint16_t altitude_compensation_{0xFFFF};
|
||||||
uint16_t ambient_pressure_compensation_{0x0000};
|
uint16_t ambient_pressure_compensation_{0x0000};
|
||||||
|
uint16_t current_ambient_pressure_compensation_{0x0000};
|
||||||
float temperature_offset_{0.0};
|
float temperature_offset_{0.0};
|
||||||
uint16_t update_interval_{0xFFFF};
|
uint16_t update_interval_{0xFFFF};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue