diff --git a/code/espurna/sensors/DHTSensor.h b/code/espurna/sensors/DHTSensor.h index 24559252..e36cf829 100644 --- a/code/espurna/sensors/DHTSensor.h +++ b/code/espurna/sensors/DHTSensor.h @@ -15,6 +15,7 @@ #define DHT_MIN_INTERVAL 2000 #define DHT_CHIP_DHT11 11 +#define DHT_CHIP_DHT12 12 #define DHT_CHIP_DHT22 22 #define DHT_CHIP_DHT21 21 #define DHT_CHIP_AM2301 21 @@ -145,7 +146,7 @@ class DHTSensor : public BaseSensor { pinMode(_gpio, OUTPUT); noInterrupts(); digitalWrite(_gpio, LOW); - if (_type == DHT_CHIP_DHT11) { + if ((_type == DHT_CHIP_DHT11) || (_type == DHT_CHIP_DHT12)) { nice_delay(20); } else { delayMicroseconds(500); @@ -201,6 +202,9 @@ class DHTSensor : public BaseSensor { // Get humidity from Data[0] and Data[1] if (_type == DHT_CHIP_DHT11) { _humidity = dhtData[0]; + } else if (_type == DHT_CHIP_DHT12) { + _humidity = dhtData[0]; + _humidity += dhtData[1] * 0.1; } else { _humidity = dhtData[0] * 256 + dhtData[1]; _humidity /= 10; @@ -209,6 +213,10 @@ class DHTSensor : public BaseSensor { // Get temp from Data[2] and Data[3] if (_type == DHT_CHIP_DHT11) { _temperature = dhtData[2]; + } else if (_type == DHT_CHIP_DHT12) { + _temperature = (dhtData[2] & 0x7F); + _temperature += dhtData[3] * 0.1; + if (dhtData[2] & 0x80) _temperature *= -1; } else { _temperature = (dhtData[2] & 0x7F) * 256 + dhtData[3]; _temperature /= 10; @@ -238,7 +246,7 @@ class DHTSensor : public BaseSensor { unsigned char _errors = 0; double _temperature = 0; - unsigned int _humidity = 0; + double _humidity = 0; };