|
@ -20,6 +20,8 @@ |
|
|
#define DHT_CHIP_DHT21 21 |
|
|
#define DHT_CHIP_DHT21 21 |
|
|
#define DHT_CHIP_AM2301 21 |
|
|
#define DHT_CHIP_AM2301 21 |
|
|
|
|
|
|
|
|
|
|
|
#define DHT_DUMMY_VALUE -255 |
|
|
|
|
|
|
|
|
class DHTSensor : public BaseSensor { |
|
|
class DHTSensor : public BaseSensor { |
|
|
|
|
|
|
|
|
public: |
|
|
public: |
|
@ -75,6 +77,9 @@ class DHTSensor : public BaseSensor { |
|
|
} |
|
|
} |
|
|
_previous = _gpio; |
|
|
_previous = _gpio; |
|
|
|
|
|
|
|
|
|
|
|
// Set now to fail the check in _read at least once |
|
|
|
|
|
_last_ok = millis(); |
|
|
|
|
|
|
|
|
_count = 2; |
|
|
_count = 2; |
|
|
_ready = true; |
|
|
_ready = true; |
|
|
|
|
|
|
|
@ -126,7 +131,11 @@ class DHTSensor : public BaseSensor { |
|
|
void _read() { |
|
|
void _read() { |
|
|
|
|
|
|
|
|
if ((_last_ok > 0) && (millis() - _last_ok < DHT_MIN_INTERVAL)) { |
|
|
if ((_last_ok > 0) && (millis() - _last_ok < DHT_MIN_INTERVAL)) { |
|
|
_error = SENSOR_ERROR_OK; |
|
|
|
|
|
|
|
|
if ((_temperature == DHT_DUMMY_VALUE) && (_humidity == DHT_DUMMY_VALUE)) { |
|
|
|
|
|
_error = SENSOR_ERROR_WARM_UP; |
|
|
|
|
|
} else { |
|
|
|
|
|
_error = SENSOR_ERROR_OK; |
|
|
|
|
|
} |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -246,8 +255,8 @@ class DHTSensor : public BaseSensor { |
|
|
unsigned long _last_ok = 0; |
|
|
unsigned long _last_ok = 0; |
|
|
unsigned char _errors = 0; |
|
|
unsigned char _errors = 0; |
|
|
|
|
|
|
|
|
double _temperature = 0; |
|
|
|
|
|
double _humidity = 0; |
|
|
|
|
|
|
|
|
double _temperature = DHT_DUMMY_VALUE; |
|
|
|
|
|
double _humidity = DHT_DUMMY_VALUE; |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|