11static const float SCALE_G[] PROGMEM = {0.0625e-3f, 0.125e-3f, 0.25e-3f, 0.75e-3f};
16 return LOG_STR(
"low power (8-bit)");
18 return LOG_STR(
"normal (10-bit)");
20 return LOG_STR(
"high resolution (12-bit)");
25static const uint16_t RATE_HZ[]
PROGMEM = {1, 10, 25, 50, 100, 200, 400, 1620, 1344};
28 MotionComponent::setup();
30 if (!this->
check_chip_id(
this, LIS3DH_REG_WHO_AM_I, LIS3DH_WHO_AM_I_VALUE))
34 this->
mark_failed(LOG_STR(
"Failed to configure sensor"));
41 uint8_t ctrl_reg1 = ((uint8_t) this->
data_rate_ << 4) | LIS3DH_CTRL_REG1_AXES_EN;
43 ctrl_reg1 |= LIS3DH_CTRL_REG1_LPEN;
44 if (!this->
write_byte(LIS3DH_REG_CTRL_REG1, ctrl_reg1))
48 uint8_t ctrl_reg4 = LIS3DH_CTRL_REG4_BDU | ((uint8_t) this->
range_ << 4);
50 ctrl_reg4 |= LIS3DH_CTRL_REG4_HR;
51 return this->
write_byte(LIS3DH_REG_CTRL_REG4, ctrl_reg4);
57 this->
temperature_callback_.empty() ? 0x00 : (uint8_t) (LIS3DH_TEMP_CFG_ADC_EN | LIS3DH_TEMP_CFG_TEMP_EN);
58 return this->
write_byte(LIS3DH_REG_TEMP_CFG, temp_cfg);
68 if (!this->
write_byte(LIS3DH_REG_CTRL_REG2, ctrl_reg2))
78 if (!this->
write_byte(LIS3DH_REG_CTRL_REG5, ctrl_reg5))
82 uint8_t ctrl_reg3 = 0;
86 ctrl_reg3 |= LIS3DH_CTRL_REG3_I1_IA1;
88 ctrl_reg6 |= LIS3DH_CTRL_REG6_I2_IA1;
91 if (!this->
write_byte(LIS3DH_REG_CTRL_REG3, ctrl_reg3) || !this->
write_byte(LIS3DH_REG_CTRL_REG6, ctrl_reg6))
99 uint8_t reference = 0;
100 this->
read_byte(LIS3DH_REG_REFERENCE, &reference);
110 ESP_LOGCONFIG(TAG,
"LIS3DH:");
111 LOG_I2C_DEVICE(
this);
117 " Operating mode: %s\n"
123 " Motion interrupt: %s (%s%s%s)\n"
124 " Threshold: %u steps\n"
125 " Duration: %u samples",
132 MotionComponent::dump_config();
157 int16_t raw_x =
raw[0];
158 int16_t raw_y =
raw[1];
159 int16_t raw_z =
raw[2];
160 ESP_LOGV(TAG,
"Read raw accel data: %d, %d, %d", raw_x, raw_y, raw_z);
161 data.acceleration[motion::X_AXIS] = raw_x * scale;
162 data.acceleration[motion::Y_AXIS] = raw_y * scale;
163 data.acceleration[motion::Z_AXIS] = raw_z * scale;
BedjetMode mode
BedJet operating mode.
void mark_failed()
Mark this component as failed.
void status_set_warning()
void status_clear_warning()
bool check_chip_id(Component *component, uint8_t a_register, uint8_t expected, uint8_t mask=0xFF)
Read the 8-bit ID at a_register and accept it when it matches expected in the bits set in mask.
bool read_bytes_16_le(uint8_t a_register, uint16_t *data, uint8_t len)
Read len 16-bit values stored least significant byte first; no conversion is compiled on little-endia...
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
bool setup_accelerometer_()
void dump_config() override
LIS3DHInterruptPin interrupt_pin_
LIS3DHOperatingMode operating_mode_
bool setup_temperature_()
LIS3DHDataRate data_rate_
LazyCallbackManager< void(float)> temperature_callback_
uint8_t interrupt_threshold_
uint8_t interrupt_axes_cfg_
bool update_data(motion::MotionData &data) override
bool publish_temperature_()
uint8_t interrupt_duration_
void on_shutdown() override
bool interrupt_active_high_
bool interrupt_high_pass_
constexpr float BME680_GAS_LOOKUP_TABLE_1[16] PROGMEM
ESPHOME_LOG_TAG(TAG, "lis3dh")
@ LIS3DH_MODE_HIGH_RESOLUTION
void progmem_memcpy(void *dst, const void *src, size_t len)
uint16_t progmem_read_uint16(const uint16_t *addr)