43 ESP_LOGD(TAG,
"Reset register: 0x%02x",
reg);
65 raw = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
66 humidity =
raw * 9.5367431640625e-5;
69 return crc8(data, 6, 0xFF, 0x31,
true) == data[6];
83 if ((
status & 0x18) != 0x18) {
84 ESP_LOGD(TAG,
"Resetting AM2315C registers");
98 ESP_LOGE(TAG,
"Write failed!");
108 ESP_LOGE(TAG,
"Read failed!");
112 if ((status & 0x80) == 0x80) {
113 ESP_LOGE(TAG,
"HW still busy!");
121 ESP_LOGE(TAG,
"Read failed!");
128 for (uint8_t i : data) {
129 zeros = zeros && (i == 0);
132 ESP_LOGW(TAG,
"Data all zeros!");
139 float humidity = 0.0;
149 ESP_LOGW(TAG,
"CRC failed!");
156 ESP_LOGCONFIG(TAG,
"AM2315C:");
157 LOG_I2C_DEVICE(
this);
void mark_failed()
Mark this component as failed.
void status_set_warning()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void status_clear_warning()
void dump_config() override
sensor::Sensor * humidity_sensor_
bool convert_(uint8_t *data, float &humidity, float &temperature)
bool reset_register_(uint8_t reg)
sensor::Sensor * temperature_sensor_
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
void publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "am2315c")
@ ERROR_OK
No error found during execution of method.
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.
uint8_t crc8(const uint8_t *data, uint8_t len, uint8_t crc, uint8_t poly, bool msb_first)
Calculate a CRC-8 checksum of data with size len.
void HOT delay(uint32_t ms)