diff --git a/DHT.cpp b/DHT.cpp index 79f6a40..659dd97 100644 --- a/DHT.cpp +++ b/DHT.cpp @@ -27,10 +27,10 @@ void DHT::begin(void) { } //boolean S == Scale. True == Fahrenheit; False == Celcius -float DHT::readTemperature(bool S) { +float DHT::readTemperature(bool S, bool force) { float f = NAN; - if (read()) { + if (read(force)) { switch (_type) { case DHT11: f = data[2]; @@ -64,7 +64,7 @@ float DHT::convertFtoC(float f) { return (f - 32) * 5 / 9; } -float DHT::readHumidity(void) { +float DHT::readHumidity(bool force) { float f = NAN; if (read()) { switch (_type) { @@ -113,7 +113,7 @@ float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFah } } -boolean DHT::read(void) { +boolean DHT::read(bool force) { // Check if sensor was read less than two seconds ago and return early // to use last reading. uint32_t currenttime = millis(); @@ -121,7 +121,7 @@ boolean DHT::read(void) { // ie there was a rollover _lastreadtime = 0; } - if (!_firstreading && ((currenttime - _lastreadtime) < 2000)) { + if (!force && !_firstreading && ((currenttime - _lastreadtime) < 2000)) { return _lastresult; // return last correct measurement } _firstreading = false; diff --git a/DHT.h b/DHT.h index dd4d1f5..5040fa3 100644 --- a/DHT.h +++ b/DHT.h @@ -39,12 +39,12 @@ class DHT { public: DHT(uint8_t pin, uint8_t type, uint8_t count=6); void begin(void); - float readTemperature(bool S=false); + float readTemperature(bool S=false, bool force=false); float convertCtoF(float); float convertFtoC(float); float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true); - float readHumidity(void); - boolean read(void); + float readHumidity(bool force=false); + boolean read(bool force=false); private: uint8_t data[6];