9static const char *
const TAG =
"hdc302x.sensor";
12static const uint8_t HDC302X_CMD_SOFT_RESET[2] = {0x30, 0xa2};
13static const uint8_t HDC302X_CMD_CLEAR_STATUS_REGISTER[2] = {0x30, 0x41};
15static const uint8_t HDC302X_CMD_TRIGGER_MSB = 0x24;
17static const uint8_t HDC302X_CMD_HEATER_ENABLE[2] = {0x30, 0x6d};
18static const uint8_t HDC302X_CMD_HEATER_DISABLE[2] = {0x30, 0x66};
19static const uint8_t HDC302X_CMD_HEATER_CONFIGURE[2] = {0x30, 0x6e};
43 LOG_UPDATE_INTERVAL(
this);
50 HDC302X_CMD_TRIGGER_MSB,
64 ESP_LOGD(TAG,
"Heater disable before start failed");
67 ESP_LOGW(TAG,
"Heater start failed");
72 if (duration_ms > 0) {
80 ESP_LOGW(TAG,
"Heater stop failed");
87 ESP_LOGE(TAG,
"Enable heater failed");
94 if (power_level > 0x3fff) {
95 ESP_LOGW(TAG,
"Heater power 0x%04x exceeds max 0x3fff", power_level);
101 static_cast<uint8_t
>((power_level >> 8) & 0xff),
102 static_cast<uint8_t
>(power_level & 0xff)
107 HDC302X_CMD_HEATER_CONFIGURE[0], HDC302X_CMD_HEATER_CONFIGURE[1], config[0], config[1],
108 crc8(config, 2, 0xff, 0x31,
true),
111 ESP_LOGE(TAG,
"Configure heater failed");
120 ESP_LOGE(TAG,
"Disable heater failed");
134 if (
crc8(buf, 2, 0xff, 0x31,
true) != buf[2] ||
crc8(buf + 3, 2, 0xff, 0x31,
true) != buf[5]) {
144 float temp = -45 + 175 * (float(raw_t) / 65535.0f);
151 float humidity = 100 * (float(raw_rh) / 65535.0f);
void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
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.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_timeout(const std boo cancel_timeout)(const char *name)
Cancel a timeout function.
void status_clear_warning()
sensor::Sensor * humidity_sensor_
void start_heater(uint16_t power, uint32_t duration_ms)
sensor::Sensor * temp_sensor_
void dump_config() override
HDC302XPowerMode power_mode_
uint32_t conversion_delay_ms_()
bool configure_heater_(uint16_t power_level)
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
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.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
void HOT delay(uint32_t ms)