[qmp6988] fix publishing bogus zero values on i2c error (#16840)

This commit is contained in:
Ross Tyler
2026-06-05 11:35:33 -07:00
committed by GitHub
parent 2ab4399ae5
commit 4cb6f2c046
2 changed files with 11 additions and 6 deletions

View File

@@ -280,20 +280,21 @@ void QMP6988Component::calculate_altitude_(float pressure, float temp) {
this->qmp6988_data_.altitude = altitude;
}
void QMP6988Component::calculate_pressure_() {
bool QMP6988Component::calculate_pressure_() {
uint8_t err = 0;
uint32_t p_read, t_read;
int32_t p_raw, t_raw;
uint8_t a_data_uint8_tr[6] = {0};
int32_t t_int, p_int;
this->qmp6988_data_.temperature = 0;
this->qmp6988_data_.pressure = 0;
err = this->read_register(QMP6988_PRESSURE_MSB_REG, a_data_uint8_tr, 6);
if (err != i2c::ERROR_OK) {
ESP_LOGE(TAG, "Error reading raw pressure/temp values");
return;
this->status_set_warning();
return false;
}
this->status_clear_warning();
p_read = encode_uint24(a_data_uint8_tr[0], a_data_uint8_tr[1], a_data_uint8_tr[2]);
p_raw = (int32_t) (p_read - SUBTRACTOR);
@@ -305,6 +306,7 @@ void QMP6988Component::calculate_pressure_() {
this->qmp6988_data_.temperature = (float) t_int / 256.0f;
this->qmp6988_data_.pressure = (float) p_int / 16.0f;
return true;
}
void QMP6988Component::setup() {
@@ -336,7 +338,10 @@ void QMP6988Component::dump_config() {
}
void QMP6988Component::update() {
this->calculate_pressure_();
if (!this->calculate_pressure_()) {
return;
}
float pressurehectopascals = this->qmp6988_data_.pressure / 100;
float temperature = this->qmp6988_data_.temperature;

View File

@@ -98,7 +98,7 @@ class QMP6988Component : public PollingComponent, public i2c::I2CDevice {
void write_oversampling_temperature_(QMP6988Oversampling oversampling_t);
void write_oversampling_pressure_(QMP6988Oversampling oversampling_p);
void write_filter_(QMP6988IIRFilter filter);
void calculate_pressure_();
bool calculate_pressure_();
void calculate_altitude_(float pressure, float temp);
int32_t get_compensated_pressure_(qmp6988_ik_data_t *ik, int32_t dp, int16_t tx);