29static const char *
const TAG =
"am2315c";
43 ESP_LOGD(TAG,
"Reset register: 0x%02x",
reg);
45 ESP_LOGE(TAG,
"Write failed!");
51 ESP_LOGE(TAG,
"Read failed!");
58 ESP_LOGE(TAG,
"Write failed!");
68 raw = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
69 humidity =
raw * 9.5367431640625e-5;
70 raw = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
72 return crc8(data, 6, 0xFF, 0x31,
true) == data[6];
79 ESP_LOGE(TAG,
"Read failed!");
87 if ((status & 0x18) != 0x18) {
88 ESP_LOGD(TAG,
"Resetting AM2315C registers");
111 ESP_LOGE(TAG,
"Write failed!");
121 ESP_LOGE(TAG,
"Read failed!");
125 if ((status & 0x80) == 0x80) {
126 ESP_LOGE(TAG,
"HW still busy!");
134 ESP_LOGE(TAG,
"Read failed!");
141 for (uint8_t i : data) {
142 zeros = zeros && (i == 0);
145 ESP_LOGW(TAG,
"Data all zeros!");
152 float humidity = 0.0;
162 ESP_LOGW(TAG,
"CRC failed!");
169 ESP_LOGCONFIG(TAG,
"AM2315C:");
170 LOG_I2C_DEVICE(
this);
172 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
void mark_failed()
Mark this component as failed.
void status_set_warning()
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique 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.
@ ERROR_OK
No error found during execution of method.
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)