Merge pull request #95 from fanthos/master

Add support for DHT12.
This commit is contained in:
Paint Your Dragon 2019-01-11 16:22:00 -08:00 committed by GitHub
commit fa129747e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -39,7 +39,12 @@ float DHT::readTemperature(bool S, bool force) {
if (read(force)) { if (read(force)) {
switch (_type) { switch (_type) {
case DHT11: case DHT11:
case DHT12:
f = data[2]; f = data[2];
f += (data[3] & 0x0f) * 0.1;
if (data[2] & 0x80) {
f *= -1;
}
if(S) { if(S) {
f = convertCtoF(f); f = convertCtoF(f);
} }
@ -73,7 +78,8 @@ float DHT::readHumidity(bool force) {
if (read(force)) { if (read(force)) {
switch (_type) { switch (_type) {
case DHT11: case DHT11:
f = data[0]; case DHT12:
f = data[0] + data[1] * 0.1;
break; break;
case DHT22: case DHT22:
case DHT21: case DHT21:

1
DHT.h
View File

@ -30,6 +30,7 @@ written by Adafruit Industries
// Define types of sensors. // Define types of sensors.
#define DHT11 11 #define DHT11 11
#define DHT12 12
#define DHT22 22 #define DHT22 22
#define DHT21 21 #define DHT21 21
#define AM2301 21 #define AM2301 21

View File

@ -37,6 +37,9 @@ void DHT_Unified::setName(sensor_t* sensor) {
case DHT11: case DHT11:
strncpy(sensor->name, "DHT11", sizeof(sensor->name) - 1); strncpy(sensor->name, "DHT11", sizeof(sensor->name) - 1);
break; break;
case DHT12:
strncpy(sensor->name, "DHT12", sizeof(sensor->name) - 1);
break;
case DHT21: case DHT21:
strncpy(sensor->name, "DHT21", sizeof(sensor->name) - 1); strncpy(sensor->name, "DHT21", sizeof(sensor->name) - 1);
break; break;
@ -57,6 +60,9 @@ void DHT_Unified::setMinDelay(sensor_t* sensor) {
case DHT11: case DHT11:
sensor->min_delay = 1000000L; // 1 second (in microseconds) sensor->min_delay = 1000000L; // 1 second (in microseconds)
break; break;
case DHT12:
sensor->min_delay = 2000000L; // 2 second (in microseconds)
break;
case DHT21: case DHT21:
sensor->min_delay = 2000000L; // 2 seconds (in microseconds) sensor->min_delay = 2000000L; // 2 seconds (in microseconds)
break; break;
@ -105,6 +111,11 @@ void DHT_Unified::Temperature::getSensor(sensor_t* sensor) {
sensor->min_value = 0.0F; sensor->min_value = 0.0F;
sensor->resolution = 2.0F; sensor->resolution = 2.0F;
break; break;
case DHT12:
sensor->max_value = 60.0F;
sensor->min_value = -20.0F;
sensor->resolution = 0.5F;
break;
case DHT21: case DHT21:
sensor->max_value = 80.0F; sensor->max_value = 80.0F;
sensor->min_value = -40.0F; sensor->min_value = -40.0F;
@ -159,6 +170,11 @@ void DHT_Unified::Humidity::getSensor(sensor_t* sensor) {
sensor->min_value = 20.0F; sensor->min_value = 20.0F;
sensor->resolution = 5.0F; sensor->resolution = 5.0F;
break; break;
case DHT12:
sensor->max_value = 95.0F;
sensor->min_value = 20.0F;
sensor->resolution = 5.0F;
break;
case DHT21: case DHT21:
sensor->max_value = 100.0F; sensor->max_value = 100.0F;
sensor->min_value = 0.0F; sensor->min_value = 0.0F;