added C++ logic for enabling and disabling internal pull-up resistor from config

This commit is contained in:
minomy13 2024-11-13 16:48:52 +01:00
parent a223034e57
commit ebfce9115d
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View file

@ -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);
}
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;

View file

@ -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