mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 19:54:14 +01:00
8e75980ebd
* Cleanup dashboard JS * Add vscode * Save start_mark/end_mark * Updates * Updates * Remove need for cv.nameable It's a bit hacky but removes so much bloat from integrations * Add enum helper * Document APIs, and Improvements * Fixes * Fixes * Update PULL_REQUEST_TEMPLATE.md * Updates * Updates * Updates
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
namespace esphome {
|
|
namespace dht {
|
|
|
|
enum DHTModel {
|
|
DHT_MODEL_AUTO_DETECT = 0,
|
|
DHT_MODEL_DHT11,
|
|
DHT_MODEL_DHT22,
|
|
DHT_MODEL_AM2302,
|
|
DHT_MODEL_RHT03,
|
|
DHT_MODEL_SI7021
|
|
};
|
|
|
|
/// Component for reading temperature/humidity measurements from DHT11/DHT22 sensors.
|
|
class DHT : public PollingComponent {
|
|
public:
|
|
/** Manually select the DHT model.
|
|
*
|
|
* Valid values are:
|
|
*
|
|
* - DHT_MODEL_AUTO_DETECT (default)
|
|
* - DHT_MODEL_DHT11
|
|
* - DHT_MODEL_DHT22
|
|
* - DHT_MODEL_AM2302
|
|
* - DHT_MODEL_RHT03
|
|
* - DHT_MODEL_SI7021
|
|
*
|
|
* @param model The DHT model.
|
|
*/
|
|
void set_dht_model(DHTModel model);
|
|
|
|
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
|
void set_model(DHTModel model) { model_ = model; }
|
|
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
|
|
void set_humidity_sensor(sensor::Sensor *humidity_sensor) { humidity_sensor_ = humidity_sensor; }
|
|
|
|
/// Set up the pins and check connection.
|
|
void setup() override;
|
|
void dump_config() override;
|
|
/// Update sensor values and push them to the frontend.
|
|
void update() override;
|
|
/// HARDWARE_LATE setup priority.
|
|
float get_setup_priority() const override;
|
|
|
|
protected:
|
|
bool read_sensor_(float *temperature, float *humidity, bool report_errors);
|
|
|
|
GPIOPin *pin_;
|
|
DHTModel model_{DHT_MODEL_AUTO_DETECT};
|
|
bool is_auto_detect_{false};
|
|
sensor::Sensor *temperature_sensor_{nullptr};
|
|
sensor::Sensor *humidity_sensor_{nullptr};
|
|
};
|
|
|
|
} // namespace dht
|
|
} // namespace esphome
|