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();
31 if (!this->
read_byte(LIS3DH_REG_WHO_AM_I, &who_am_i)) {
32 this->
mark_failed(LOG_STR(
"Failed to read chip ID - check wiring / address"));
35 if (who_am_i != LIS3DH_WHO_AM_I_VALUE) {
36 ESP_LOGE(TAG,
"Wrong chip ID: 0x%02X (expected 0x%02X)", who_am_i, LIS3DH_WHO_AM_I_VALUE);
42 this->
mark_failed(LOG_STR(
"Failed to configure sensor"));
49 uint8_t ctrl_reg1 = ((uint8_t) this->
data_rate_ << 4) | LIS3DH_CTRL_REG1_AXES_EN;
51 ctrl_reg1 |= LIS3DH_CTRL_REG1_LPEN;
52 if (!this->
write_byte(LIS3DH_REG_CTRL_REG1, ctrl_reg1))
56 uint8_t ctrl_reg4 = LIS3DH_CTRL_REG4_BDU | ((uint8_t) this->
range_ << 4);
58 ctrl_reg4 |= LIS3DH_CTRL_REG4_HR;
59 return this->
write_byte(LIS3DH_REG_CTRL_REG4, ctrl_reg4);
65 this->
temperature_callback_.empty() ? 0x00 : (uint8_t) (LIS3DH_TEMP_CFG_ADC_EN | LIS3DH_TEMP_CFG_TEMP_EN);
66 return this->
write_byte(LIS3DH_REG_TEMP_CFG, temp_cfg);
76 if (!this->
write_byte(LIS3DH_REG_CTRL_REG2, ctrl_reg2))
86 if (!this->
write_byte(LIS3DH_REG_CTRL_REG5, ctrl_reg5))
90 uint8_t ctrl_reg3 = 0;
94 ctrl_reg3 |= LIS3DH_CTRL_REG3_I1_IA1;
96 ctrl_reg6 |= LIS3DH_CTRL_REG6_I2_IA1;
99 if (!this->
write_byte(LIS3DH_REG_CTRL_REG3, ctrl_reg3) || !this->
write_byte(LIS3DH_REG_CTRL_REG6, ctrl_reg6))
107 uint8_t reference = 0;
108 this->
read_byte(LIS3DH_REG_REFERENCE, &reference);
118 ESP_LOGCONFIG(TAG,
"LIS3DH:");
119 LOG_I2C_DEVICE(
this);
125 " Operating mode: %s\n"
131 " Motion interrupt: %s (%s%s%s)\n"
132 " Threshold: %u steps\n"
133 " Duration: %u samples",
140 MotionComponent::dump_config();
156 if (!this->
read_bytes(LIS3DH_REG_OUT_X_L | LIS3DH_AUTO_INCREMENT,
raw, 6)) {
168 ESP_LOGV(TAG,
"Read raw accel data: %d, %d, %d", raw_x, raw_y, raw_z);
169 data.acceleration[motion::X_AXIS] = raw_x * scale;
170 data.acceleration[motion::Y_AXIS] = raw_y * scale;
171 data.acceleration[motion::Z_AXIS] = raw_z * scale;
180 if (!this->
read_bytes(LIS3DH_REG_OUT_ADC3_L | LIS3DH_AUTO_INCREMENT,
raw, 2)) {
BedjetMode mode
BedJet operating mode.
void mark_failed()
Mark this component as failed.
void status_set_warning()
void status_clear_warning()
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
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)
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.