|
@ -30,6 +30,10 @@ class DHTSensor : public BaseSensor { |
|
|
_sensor_id = SENSOR_DHTXX_ID; |
|
|
_sensor_id = SENSOR_DHTXX_ID; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~DHTSensor() { |
|
|
|
|
|
if (_previous != 0xFF) gpioReleaseLock(_previous); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------- |
|
|
// --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
void setGPIO(unsigned char gpio) { |
|
|
void setGPIO(unsigned char gpio) { |
|
@ -54,6 +58,24 @@ class DHTSensor : public BaseSensor { |
|
|
// Sensor API |
|
|
// Sensor API |
|
|
// --------------------------------------------------------------------- |
|
|
// --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
// Initialization method, must be idempotent |
|
|
|
|
|
void begin() { |
|
|
|
|
|
|
|
|
|
|
|
_count = 0; |
|
|
|
|
|
|
|
|
|
|
|
// Manage GPIO lock |
|
|
|
|
|
if (_previous != 0xFF) gpioReleaseLock(_previous); |
|
|
|
|
|
_previous = 0xFF; |
|
|
|
|
|
if (!gpioGetLock(_gpio)) { |
|
|
|
|
|
_error = SENSOR_ERROR_GPIO_USED; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
_previous = _gpio; |
|
|
|
|
|
|
|
|
|
|
|
_count = 2; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Pre-read hook (usually to populate registers with up-to-date data) |
|
|
// Pre-read hook (usually to populate registers with up-to-date data) |
|
|
void pre() { |
|
|
void pre() { |
|
|
_read(); |
|
|
_read(); |
|
@ -194,6 +216,7 @@ class DHTSensor : public BaseSensor { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
unsigned char _gpio; |
|
|
unsigned char _gpio; |
|
|
|
|
|
unsigned char _previous = 0xFF; |
|
|
unsigned char _type; |
|
|
unsigned char _type; |
|
|
|
|
|
|
|
|
unsigned long _last_ok = 0; |
|
|
unsigned long _last_ok = 0; |
|
|