mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
added C++ logic for enabling and disabling internal pull-up resistor from config
This commit is contained in:
parent
a223034e57
commit
ebfce9115d
2 changed files with 14 additions and 1 deletions
|
@ -24,6 +24,12 @@ void DHT::dump_config() {
|
|||
ESP_LOGCONFIG(TAG, " Model: DHT22 (or equivalent)");
|
||||
}
|
||||
|
||||
if (this->use_internal_pullup_ == true) {
|
||||
ESP_LOGCONFIG(TAG, " Internal pull-up resistor enabled.")
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " Internal pull-up resistor disabled.")
|
||||
}
|
||||
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
|
@ -101,7 +107,12 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
|||
} else {
|
||||
delayMicroseconds(800);
|
||||
}
|
||||
this->pin_->pin_mode(gpio::FLAG_INPUT);
|
||||
|
||||
if (this->use_internal_pullup_ == true) {
|
||||
this->pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
} else {
|
||||
this->pin_->pin_mode(gpio::FLAG_INPUT);
|
||||
}
|
||||
|
||||
{
|
||||
InterruptLock lock;
|
||||
|
|
|
@ -42,6 +42,7 @@ class DHT : public PollingComponent {
|
|||
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; }
|
||||
void set_internal_pullup(bool use_internal_pullup) { this->use_internal_pullup_ = use_internal_pullup; }
|
||||
|
||||
/// Set up the pins and check connection.
|
||||
void setup() override;
|
||||
|
@ -59,6 +60,7 @@ class DHT : public PollingComponent {
|
|||
bool is_auto_detect_{false};
|
||||
sensor::Sensor *temperature_sensor_{nullptr};
|
||||
sensor::Sensor *humidity_sensor_{nullptr};
|
||||
bool use_internal_pullup_{true};
|
||||
};
|
||||
|
||||
} // namespace dht
|
||||
|
|
Loading…
Reference in a new issue