1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

Merge branch 'lps22_remove_set_retry' into integration

This commit is contained in:
J. Nick Koston
2026-02-07 17:23:06 -06:00
2 changed files with 13 additions and 6 deletions

View File

@@ -38,22 +38,29 @@ void LPS22Component::dump_config() {
LOG_UPDATE_INTERVAL(this);
}
static constexpr uint32_t INTERVAL_READ = 0;
void LPS22Component::update() {
uint8_t value = 0x00;
this->read_register(CTRL_REG2, &value, 1);
value |= CTRL_REG2_ONE_SHOT_MASK;
this->write_register(CTRL_REG2, &value, 1);
this->set_retry(READ_INTERVAL, READ_ATTEMPTS, [this](uint8_t _) { return this->try_read_(); });
this->read_attempts_remaining_ = READ_ATTEMPTS;
this->set_interval(INTERVAL_READ, READ_INTERVAL, [this]() { this->try_read_(); });
}
RetryResult LPS22Component::try_read_() {
void LPS22Component::try_read_() {
uint8_t value = 0x00;
this->read_register(STATUS, &value, 1);
const uint8_t expected_status_mask = STATUS_T_DA_MASK | STATUS_P_DA_MASK;
if ((value & expected_status_mask) != expected_status_mask) {
ESP_LOGD(TAG, "STATUS not ready: %x", value);
return RetryResult::RETRY;
if (--this->read_attempts_remaining_ == 0) {
this->cancel_interval(INTERVAL_READ);
}
return;
}
this->cancel_interval(INTERVAL_READ);
if (this->temperature_sensor_ != nullptr) {
uint8_t t_buf[2]{0};
@@ -68,7 +75,6 @@ RetryResult LPS22Component::try_read_() {
uint32_t p_lsb = encode_uint24(p_buf[2], p_buf[1], p_buf[0]);
this->pressure_sensor_->publish_state(PRESSURE_SCALE * static_cast<float>(p_lsb));
}
return RetryResult::DONE;
}
} // namespace lps22

View File

@@ -17,10 +17,11 @@ class LPS22Component : public sensor::Sensor, public PollingComponent, public i2
void dump_config() override;
protected:
void try_read_();
sensor::Sensor *temperature_sensor_{nullptr};
sensor::Sensor *pressure_sensor_{nullptr};
RetryResult try_read_();
uint8_t read_attempts_remaining_{0};
};
} // namespace lps22