mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Add support for DHT12.
Change DHT11 temperature resolution to 0.1 instead of 1.
This commit is contained in:
parent
c978977718
commit
a607a50475
8
DHT.cpp
8
DHT.cpp
@ -38,7 +38,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);
|
||||||
}
|
}
|
||||||
@ -74,7 +79,8 @@ float DHT::readHumidity(bool force) {
|
|||||||
if (read()) {
|
if (read()) {
|
||||||
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
1
DHT.h
@ -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
|
||||||
|
16
DHT_U.cpp
16
DHT_U.cpp
@ -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; // 1 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user