mirror of
https://github.com/esphome/esphome.git
synced 2026-05-24 09:56:46 +08:00
[shtcx] Code clean-up (#15261)
This commit is contained in:
@@ -2,16 +2,15 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace shtcx {
|
||||
namespace esphome::shtcx {
|
||||
|
||||
static const char *const TAG = "shtcx";
|
||||
|
||||
static const uint16_t SHTCX_COMMAND_SLEEP = 0xB098;
|
||||
static const uint16_t SHTCX_COMMAND_WAKEUP = 0x3517;
|
||||
static const uint16_t SHTCX_COMMAND_READ_ID_REGISTER = 0xEFC8;
|
||||
static const uint16_t SHTCX_COMMAND_SOFT_RESET = 0x805D;
|
||||
static const uint16_t SHTCX_COMMAND_POLLING_H = 0x7866;
|
||||
static constexpr uint16_t SHTCX_COMMAND_SLEEP = 0xB098;
|
||||
static constexpr uint16_t SHTCX_COMMAND_WAKEUP = 0x3517;
|
||||
static constexpr uint16_t SHTCX_COMMAND_READ_ID_REGISTER = 0xEFC8;
|
||||
static constexpr uint16_t SHTCX_COMMAND_SOFT_RESET = 0x805D;
|
||||
static constexpr uint16_t SHTCX_COMMAND_POLLING_H = 0x7866;
|
||||
|
||||
static const LogString *shtcx_type_to_string(SHTCXType type) {
|
||||
switch (type) {
|
||||
@@ -91,8 +90,6 @@ void SHTCXComponent::update() {
|
||||
} else {
|
||||
temperature = 175.0f * float(raw_data[0]) / 65536.0f - 45.0f;
|
||||
humidity = 100.0f * float(raw_data[1]) / 65536.0f;
|
||||
|
||||
ESP_LOGD(TAG, "Temperature=%.2f°C Humidity=%.2f%%", temperature, humidity);
|
||||
}
|
||||
if (this->temperature_sensor_ != nullptr)
|
||||
this->temperature_sensor_->publish_state(temperature);
|
||||
@@ -117,5 +114,4 @@ void SHTCXComponent::wake_up() {
|
||||
delayMicroseconds(200);
|
||||
}
|
||||
|
||||
} // namespace shtcx
|
||||
} // namespace esphome
|
||||
} // namespace esphome::shtcx
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/sensirion_common/i2c_sensirion.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace shtcx {
|
||||
namespace esphome::shtcx {
|
||||
|
||||
enum SHTCXType { SHTCX_TYPE_SHTC3 = 0, SHTCX_TYPE_SHTC1, SHTCX_TYPE_UNKNOWN };
|
||||
enum SHTCXType : uint8_t {
|
||||
SHTCX_TYPE_SHTC3 = 0,
|
||||
SHTCX_TYPE_SHTC1,
|
||||
SHTCX_TYPE_UNKNOWN,
|
||||
};
|
||||
|
||||
/// This class implements support for the SHT3x-DIS family of temperature+humidity i2c sensors.
|
||||
class SHTCXComponent : public PollingComponent, public sensirion_common::SensirionI2CDevice {
|
||||
@@ -23,11 +26,10 @@ class SHTCXComponent : public PollingComponent, public sensirion_common::Sensiri
|
||||
void wake_up();
|
||||
|
||||
protected:
|
||||
SHTCXType type_;
|
||||
uint16_t sensor_id_;
|
||||
sensor::Sensor *temperature_sensor_{nullptr};
|
||||
sensor::Sensor *humidity_sensor_{nullptr};
|
||||
uint16_t sensor_id_;
|
||||
SHTCXType type_;
|
||||
};
|
||||
|
||||
} // namespace shtcx
|
||||
} // namespace esphome
|
||||
} // namespace esphome::shtcx
|
||||
|
||||
Reference in New Issue
Block a user