8static constexpr uint8_t WHO_AM_I = 0x0F;
9static constexpr uint8_t LPS22HB_ID = 0xB1;
10static constexpr uint8_t LPS22HH_ID = 0xB3;
11static constexpr uint8_t LPS22DF_ID = 0xB4;
12static constexpr uint8_t CTRL_REG2 = 0x11;
13static constexpr uint8_t CTRL_REG2_ONE_SHOT_MASK = 0b1;
14static constexpr uint8_t STATUS = 0x27;
15static constexpr uint8_t STATUS_T_DA_MASK = 0b10;
16static constexpr uint8_t STATUS_P_DA_MASK = 0b01;
17static constexpr uint8_t TEMP_L = 0x2b;
18static constexpr uint8_t PRES_OUT_XL = 0x28;
19static constexpr uint8_t REF_P_XL = 0x28;
20static constexpr uint8_t READ_ATTEMPTS = 10;
21static constexpr uint8_t READ_INTERVAL = 5;
22static constexpr float PRESSURE_SCALE = 1.0f / 4096.0f;
23static constexpr float TEMPERATURE_SCALE = 0.01f;
28 if (
value != LPS22HB_ID &&
value != LPS22HH_ID &&
value != LPS22DF_ID) {
29 ESP_LOGW(TAG,
"device IDs as %02x, which isn't a known LPS22HB/HH/DF ID",
value);
34void LPS22Component::dump_config() {
35 ESP_LOGCONFIG(TAG,
"LPS22:");
36 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
37 LOG_SENSOR(
" ",
"Pressure", this->pressure_sensor_);
39 LOG_UPDATE_INTERVAL(
this);
42static constexpr uint32_t INTERVAL_READ = 0;
44void LPS22Component::update() {
54 const uint8_t expected_status_mask = STATUS_T_DA_MASK | STATUS_P_DA_MASK;
55 if ((
value & expected_status_mask) != expected_status_mask) {
56 ESP_LOGD(TAG,
"STATUS not ready: %x",
value);
64 if (this->temperature_sensor_ !=
nullptr) {
68 float temp = TEMPERATURE_SCALE *
static_cast<float>(encoded);
69 this->temperature_sensor_->publish_state(temp);
71 if (this->pressure_sensor_ !=
nullptr) {
75 this->pressure_sensor_->publish_state(PRESSURE_SCALE *
static_cast<float>(p_lsb));
void mark_failed()
Mark this component as failed.
virtual void setup()
Where the component's initialization should happen.
bool cancel_interval(const char *name)
Cancel an interval function.
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
void set_interval(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a const char* name.
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
bool update_register(uint8_t a_register, uint8_t mask, uint8_t value)
Read a register, replace the bits in mask with those of value and write it back.
uint8_t read_attempts_remaining_
ESPHOME_LOG_TAG(TAG, "lps22")
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...