30static const char *
const TAG =
"am2315c";
44 ESP_LOGD(TAG,
"Reset register: 0x%02x",
reg);
46 ESP_LOGE(TAG,
"Write failed!");
52 ESP_LOGE(TAG,
"Read failed!");
59 ESP_LOGE(TAG,
"Write failed!");
70 humidity =
raw * 9.5367431640625e-5;
80 ESP_LOGE(TAG,
"Read failed!");
88 if ((status & 0x18) != 0x18) {
89 ESP_LOGD(TAG,
"Resetting AM2315C registers");
112 ESP_LOGE(TAG,
"Write failed!");
122 ESP_LOGE(TAG,
"Read failed!");
126 if ((status & 0x80) == 0x80) {
127 ESP_LOGE(TAG,
"HW still busy!");
135 ESP_LOGE(TAG,
"Read failed!");
142 for (uint8_t i :
data) {
143 zeros = zeros && (i == 0);
146 ESP_LOGW(TAG,
"Data all zeros!");
153 float humidity = 0.0;
163 ESP_LOGW(TAG,
"CRC failed!");
170 ESP_LOGCONFIG(TAG,
"AM2315C:");
171 LOG_I2C_DEVICE(
this);
173 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void dump_config() override
sensor::Sensor * humidity_sensor_
float get_setup_priority() const override
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.
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
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 IRAM_ATTR HOT delay(uint32_t ms)