30 static const char *
const TAG =
"am2315c";
36 for (uint8_t i = 0; i < 8; i++) {
60 ESP_LOGD(TAG,
"Reset register: 0x%02x", reg);
62 ESP_LOGE(TAG,
"Write failed!");
68 ESP_LOGE(TAG,
"Read failed!");
75 ESP_LOGE(TAG,
"Write failed!");
85 raw = (data[1] << 12) | (data[2] << 4) | (data[3] >> 4);
86 humidity = raw * 9.5367431640625e-5;
87 raw = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
88 temperature = raw * 1.9073486328125e-4 - 50;
89 return this->
crc8_(data, 6) == data[6];
93 ESP_LOGCONFIG(TAG,
"Setting up AM2315C...");
98 ESP_LOGE(TAG,
"Read failed!");
106 if ((status & 0x18) != 0x18) {
107 ESP_LOGD(TAG,
"Resetting AM2315C registers");
130 ESP_LOGE(TAG,
"Write failed!");
140 ESP_LOGE(TAG,
"Read failed!");
144 if ((status & 0x80) == 0x80) {
145 ESP_LOGE(TAG,
"HW still busy!");
153 ESP_LOGE(TAG,
"Read failed!");
160 for (uint8_t i : data) {
161 zeros = zeros && (i == 0);
164 ESP_LOGW(TAG,
"Data all zeros!");
171 float humidity = 0.0;
172 if (this->
convert_(data, humidity, temperature)) {
181 ESP_LOGW(TAG,
"CRC failed!");
188 ESP_LOGCONFIG(TAG,
"AM2315C:");
189 LOG_I2C_DEVICE(
this);
191 ESP_LOGE(TAG,
"Communication with AM2315C failed!");
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
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
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
bool convert_(uint8_t *data, float &humidity, float &temperature)
sensor::Sensor * temperature_sensor_
No error found during execution of method.
void status_clear_warning()
float get_setup_priority() const override
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * humidity_sensor_
bool reset_register_(uint8_t reg)
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
uint8_t crc8_(uint8_t *data, uint8_t len)
void IRAM_ATTR HOT delay(uint32_t ms)