Skip to content

Commit e97ae9e

Browse files
committed
added force parameter to DHT read function
1 parent 9a0003d commit e97ae9e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

libraries/DHT/DHT.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2013-06-10: Initial version
2525
2013-06-12: Refactored code
2626
2013-07-01: Add a resetTimer method
27+
2016-07-20: Add force parameter - Torben Woltjen (mozzbozz)
2728
******************************************************************/
2829

2930
#include "DHT.h"
@@ -108,13 +109,15 @@ const char *DHT::getStatusString() {
108109

109110
#endif
110111

111-
void DHT::readSensor()
112+
void DHT::readSensor(bool force)
112113
{
113114
// Make sure we don't poll the sensor too often
114115
// - Max sample rate DHT11 is 1 Hz (duty cicle 1000 ms)
115116
// - Max sample rate DHT22 is 0.5 Hz (duty cicle 2000 ms)
117+
// If 'force' is true, the user has to take care of this -> this way, the
118+
// microcontroller can be set to sleep where it doesn't increase millis().
116119
unsigned long startTime = millis();
117-
if ( (unsigned long)(startTime - lastReadTime) < (model == DHT11 ? 999L : 1999L) ) {
120+
if ( !force && (unsigned long)(startTime - lastReadTime) < (model == DHT11 ? 999L : 1999L) ) {
118121
return;
119122
}
120123
lastReadTime = startTime;

libraries/DHT/DHT.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2013-06-10: Initial version
2525
2013-06-12: Refactored code
2626
2013-07-01: Add a resetTimer method
27+
2016-07-20: Add force parameter - Torben Woltjen (mozzbozz)
2728
******************************************************************/
2829

2930
#ifndef dht_h
@@ -58,6 +59,7 @@ class DHT
5859
void setup(uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);
5960
void resetTimer();
6061

62+
void readSensor(bool force=false);
6163
float getTemperature();
6264
float getHumidity();
6365

@@ -80,8 +82,6 @@ class DHT
8082
static float toCelsius(float fromFahrenheit) { return (fromFahrenheit - 32.0) / 1.8; };
8183

8284
protected:
83-
void readSensor();
84-
8585
float temperature;
8686
float humidity;
8787

0 commit comments

Comments
 (0)