Update esphome/components/lps22/lps22.cpp

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Simonas Kazlauskas 2024-10-15 17:08:24 +03:00 committed by GitHub
parent ff66c43d37
commit 85eafdf8ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,11 +60,12 @@ RetryResult LPS22Component::try_read_() {
float temp =
TEMPERATURE_SCALE * static_cast<float>(static_cast<int16_t>(t_buf[1]) << 8 | static_cast<int16_t>(t_buf[0]));
this->temperature_sensor_->publish_state(temp);
uint8_t p_buf[3]{0};
this->read_register(PRES_OUT_XL, p_buf, 3);
uint32_t p_lsb =
static_cast<uint32_t>(p_buf[2]) << 16 | static_cast<uint32_t>(p_buf[1]) << 8 | static_cast<uint32_t>(p_buf[0]);
this->pressure_sensor_->publish_state(PRESSURE_SCALE * static_cast<float>(p_lsb));
if (this->pressure_sensor_ != nullptr) {
uint8_t p_buf[3]{0};
this->read_register(PRES_OUT_XL, p_buf, 3);
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;
}