12static constexpr uint8_t REG_TEMPERATURE_LOW = 0x00;
13static constexpr uint8_t REG_TEMPERATURE_HIGH = 0x01;
14static constexpr uint8_t REG_HUMIDITY_LOW = 0x02;
15static constexpr uint8_t REG_HUMIDITY_HIGH = 0x03;
16static constexpr uint8_t REG_RESET_DRDY_INT_CONF = 0x0E;
17static constexpr uint8_t REG_MEASUREMENT_CONF = 0x0F;
20static constexpr uint8_t MEAS_TRIG = 0x01;
21static constexpr uint8_t MEAS_CONF_MASK = 0x06;
22static constexpr uint8_t HRES_MASK = 0x30;
23static constexpr uint8_t TRES_MASK = 0xC0;
26static constexpr uint8_t AMM_MASK = 0x70;
29 ESP_LOGCONFIG(TAG,
"Running setup");
32 uint8_t config_contents;
33 this->
read_register(REG_MEASUREMENT_CONF, &config_contents, 1);
34 config_contents &= ~(TRES_MASK | HRES_MASK | MEAS_CONF_MASK);
35 this->
write_bytes(REG_MEASUREMENT_CONF, &config_contents, 1);
38 this->
read_register(REG_RESET_DRDY_INT_CONF, &config_contents, 1);
39 config_contents &= ~AMM_MASK;
40 this->
write_bytes(REG_RESET_DRDY_INT_CONF, &config_contents, 1);
43void HDC2010Component::dump_config() {
44 ESP_LOGCONFIG(TAG,
"HDC2010:");
46 LOG_UPDATE_INTERVAL(
this);
47 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
48 LOG_SENSOR(
" ",
"Humidity", this->humidity_sensor_);
51void HDC2010Component::update() {
53 uint8_t config_contents;
54 this->
read_register(REG_MEASUREMENT_CONF, &config_contents, 1);
55 config_contents |= MEAS_TRIG;
56 this->
write_bytes(REG_MEASUREMENT_CONF, &config_contents, 1);
60 if (this->temperature_sensor_ !=
nullptr) {
61 float temp = this->read_temp();
62 this->temperature_sensor_->publish_state(temp);
63 ESP_LOGD(TAG,
"Temp=%.1f°C", temp);
66 if (this->humidity_sensor_ !=
nullptr) {
67 float humidity = this->read_humidity();
68 this->humidity_sensor_->publish_state(humidity);
69 ESP_LOGD(TAG,
"Humidity=%.1f%%", humidity);
74float HDC2010Component::read_temp() {
81 return (
float) temp * 0.0025177f - 40.0f;
84float HDC2010Component::read_humidity() {
91 return (
float) humidity * 0.001525879f;