17 return LOG_STR(
"±125dps");
19 return LOG_STR(
"±250dps");
21 return LOG_STR(
"±500dps");
23 return LOG_STR(
"±1000dps");
25 return LOG_STR(
"±2000dps");
27 return LOG_STR(
"unknown");
33 case LSM6DS_WHO_AM_I_LSM6DS3:
34 return LOG_STR(
"LSM6DS3");
35 case LSM6DS_WHO_AM_I_LSM6DS3TR_C:
36 return LOG_STR(
"LSM6DS3TR-C");
37 case LSM6DS_WHO_AM_I_LSM6DSO:
38 return LOG_STR(
"LSM6DSO");
45 return who_am_i == LSM6DS_WHO_AM_I_LSM6DS3 ? 16 : 256;
49 MotionComponent::setup();
52 LOG_STR(
"Failed to read WHO_AM_I — check wiring and I2C address")))
55 if (chip_name ==
nullptr) {
56 ESP_LOGE(TAG,
"Unknown WHO_AM_I: 0x%02X", who_am_i);
57 this->
mark_failed(LOG_STR(
"Unknown WHO_AM_I value"));
60 ESP_LOGD(TAG,
"Found %s (WHO_AM_I = 0x%02X)", LOG_STR_ARG(chip_name), who_am_i);
66 LOG_STR(
"Software reset failed")))
74 uint8_t ctrl3 = CTRL3_C_IF_INC | CTRL3_C_BDU;
76 LOG_STR(
"Config failed")))
83 LOG_STR(
"Failed to configure accelerometer")))
90 LOG_STR(
"Failed to configure gyroscope")))
108 LOG_I2C_DEVICE(
this);
109 LOG_UPDATE_INTERVAL(
this);
114 " Accel range : %s\n"
115 " Accel data rate : %dHz\n"
117 " Gyro data rate : %dHz",
118 LOG_STR_ARG(AccelRangeStrings::get_log_str(this->
accel_range_)), accel_odr,
119 LOG_STR_ARG(gyro_range_to_str(this->
gyro_range_)), gyro_odr);
133 uint8_t
raw[LSM6DS_BURST_LEN];
134 if (!this->
read_bytes(LSM6DS_REG_OUTX_L_G,
raw, LSM6DS_BURST_LEN)) {
143 static constexpr float GYRO_SCALE[] = {
168 static constexpr float ACCEL_SCALE[] = {
180#ifdef USE_MOTION_TEMPERATURE_PUBLISHER
185 if (this->temperature_publisher_ !=
nullptr) {
187 if (this->
read_bytes(LSM6DS_REG_OUT_TEMP_L, raw_t, 2)) {
void mark_failed()
Mark this component as failed.
void status_clear_error()
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
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 read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
void dump_config() override
LSM6DSAccelODR accel_odr_
uint16_t temperature_sensitivity_
bool update_data(motion::MotionData &data) override
LSM6DSGyroRange gyro_range_
LSM6DSAccelRange accel_range_
const LogString * chip_name_
@ ERROR_OK
No error found during execution of method.
uint16_t temperature_sensitivity_from_who_am_i(uint8_t who_am_i)
Temperature sensitivity in LSB/°C for a supported WHO_AM_I value, from the chip's datasheet.
ESPHOME_LOG_TAG(TAG, "lsm6ds")
const LogString * chip_name_from_who_am_i(uint8_t who_am_i)
Chip name for a WHO_AM_I value, or nullptr when the chip is not supported.
PROGMEM_STRING_TABLE(AccelRangeStrings, "±2g", "±16g", "±4g", "±8g")
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...
void HOT delay(uint32_t ms)