6static const char *
const TAG =
"stts22h";
8static const uint8_t WHOAMI_REG = 0x01;
9static const uint8_t CTRL_REG = 0x04;
10static const uint8_t TEMPERATURE_REG = 0x06;
13static const uint8_t LOW_ODR_CTRL_ENABLE_FLAG = 0x80;
14static const uint8_t FREERUN_CTRL_ENABLE_FLAG = 0x04;
15static const uint8_t ADD_INC_ENABLE_FLAG = 0x08;
17static const uint8_t WHOAMI_STTS22H_IDENTIFICATION = 0xA0;
19static const float SENSOR_SCALE = 0.01f;
24 this->
mark_failed(LOG_STR(
"Device is not a STTS22H sensor"));
40 LOG_SENSOR(
"",
"STTS22H",
this);
42 LOG_UPDATE_INTERVAL(
this);
44 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
49 uint8_t temp_reg_value[2];
51 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
57 int16_t temp_raw_value =
static_cast<int16_t
>(
encode_uint16(temp_reg_value[1], temp_reg_value[0]));
58 return temp_raw_value * SENSOR_SCALE;
68 if (whoami_value != WHOAMI_STTS22H_IDENTIFICATION) {
69 this->
mark_failed(LOG_STR(
"Unexpected WHOAMI identifier. Sensor is not a STTS22H"));
87 ctrl_value &= ~FREERUN_CTRL_ENABLE_FLAG;
94 ctrl_value |= LOW_ODR_CTRL_ENABLE_FLAG | ADD_INC_ENABLE_FLAG;
virtual void mark_failed()
Mark this component as failed.
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
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
void initialize_sensor_()
float read_temperature_()
bool is_stts22h_sensor_()
@ NO_ERROR
No error found during execution of method.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.