From a27a8dc5b8703d49799b2b5fa86ba74fd7356def Mon Sep 17 00:00:00 2001 From: optimusprimespace <62800678+optimusprimespace@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:55:52 -0400 Subject: [PATCH] updated code with "this->" and removed unused code --- esphome/components/hdc2010/hdc2010.cpp | 35 +++++++++++++++++--------- esphome/components/hdc2010/hdc2010.h | 2 -- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/esphome/components/hdc2010/hdc2010.cpp b/esphome/components/hdc2010/hdc2010.cpp index 46e640f4df..2ef0b4620f 100644 --- a/esphome/components/hdc2010/hdc2010.cpp +++ b/esphome/components/hdc2010/hdc2010.cpp @@ -34,22 +34,22 @@ void HDC2010Component::setup() { // Set measurement mode to temperature and humidity uint8_t config_contents; - read_register(MEASUREMENT_CONFIG, &config_contents, 1); + this->read_register(MEASUREMENT_CONFIG, &config_contents, 1); config_contents = (config_contents & 0xF9); // Always set to TEMP_AND_HUMID mode this->write_bytes(MEASUREMENT_CONFIG, &config_contents, 1); // Set rate to manual - read_register(CONFIG, &config_contents, 1); + this->read_register(CONFIG, &config_contents, 1); config_contents &= 0x8F; this->write_bytes(CONFIG, &config_contents, 1); // Set temperature resolution to 14bit - read_register(CONFIG, &config_contents, 1); + this->read_register(CONFIG, &config_contents, 1); config_contents &= 0x3F; this->write_bytes(CONFIG, &config_contents, 1); // Set humidity resolution to 14bit - read_register(CONFIG, &config_contents, 1); + this->read_register(CONFIG, &config_contents, 1); config_contents &= 0xCF; this->write_bytes(CONFIG, &config_contents, 1); @@ -63,14 +63,14 @@ void HDC2010Component::dump_config() { ESP_LOGE(TAG, "Communication with HDC2010 failed!"); } LOG_UPDATE_INTERVAL(this); - LOG_SENSOR(" ", "Temperature", this->temperature_); - LOG_SENSOR(" ", "Humidity", this->humidity_); + LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); + LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); } void HDC2010Component::update() { // Trigger measurement uint8_t config_contents; - read_register(CONFIG, &config_contents, 1); + this->read_register(CONFIG, &config_contents, 1); config_contents |= 0x01; this->write_bytes(MEASUREMENT_CONFIG, &config_contents, 1); @@ -93,8 +93,19 @@ float HDC2010Component::read_temp() { uint8_t byte[2]; uint16_t temp; - read_register(HDC2010_CMD_TEMPERATURE_LOW, &byte[0], 1); - read_register(HDC2010_CMD_TEMPERATURE_HIGH, &byte[1], 1); + this->read_register(HDC2010_CMD_TEMPERATURE_LOW, &byte[0], 1); + this->read_register(HDC2010_CMD_TEMPERATURE_HIGH, &byte[1], 1); + + temp = (unsigned int) byte[1] << 8 | byte[0]; + return (float) temp * 0.0025177f - 40.0f; +} + +float HDC2010Component::read_temp() { + uint8_t byte[2]; + uint16_t temp; + + this->read_register(HDC2010_CMD_TEMPERATURE_LOW, &byte[0], 1); + this->read_register(HDC2010_CMD_TEMPERATURE_HIGH, &byte[1], 1); temp = (unsigned int) byte[1] << 8 | byte[0]; return (float) temp * 0.0025177f - 40.0f; @@ -104,13 +115,13 @@ float HDC2010Component::read_humidity() { uint8_t byte[2]; uint16_t humidity; - read_register(HDC2010_CMD_HUMIDITY_LOW, &byte[0], 1); - read_register(HDC2010_CMD_HUMIDITY_HIGH, &byte[1], 1); + this->read_register(HDC2010_CMD_HUMIDITY_LOW, &byte[0], 1); + this->read_register(HDC2010_CMD_HUMIDITY_HIGH, &byte[1], 1); humidity = (unsigned int) byte[1] << 8 | byte[0]; return (float) humidity * 0.001525879f; } -float HDC2010Component::get_setup_priority() const { return setup_priority::DATA; } +float HDC2010Component::get_setup_priority() const { return this->setup_priority::DATA; } } // namespace hdc2010 } // namespace esphome diff --git a/esphome/components/hdc2010/hdc2010.h b/esphome/components/hdc2010/hdc2010.h index 882162f44a..9b4f7f61b6 100644 --- a/esphome/components/hdc2010/hdc2010.h +++ b/esphome/components/hdc2010/hdc2010.h @@ -28,8 +28,6 @@ class HDC2010Component : public PollingComponent, public i2c::I2CDevice { protected: sensor::Sensor *temperature_sensor_{nullptr}; sensor::Sensor *humidity_sensor_{nullptr}; - uint16_t heater_temperature_{100}; - uint16_t heater_duration_{30}; }; } // namespace hdc2010