mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
commit
fa129747e8
8
DHT.cpp
8
DHT.cpp
@ -39,7 +39,12 @@ float DHT::readTemperature(bool S, bool force) {
|
||||
if (read(force)) {
|
||||
switch (_type) {
|
||||
case DHT11:
|
||||
case DHT12:
|
||||
f = data[2];
|
||||
f += (data[3] & 0x0f) * 0.1;
|
||||
if (data[2] & 0x80) {
|
||||
f *= -1;
|
||||
}
|
||||
if(S) {
|
||||
f = convertCtoF(f);
|
||||
}
|
||||
@ -73,7 +78,8 @@ float DHT::readHumidity(bool force) {
|
||||
if (read(force)) {
|
||||
switch (_type) {
|
||||
case DHT11:
|
||||
f = data[0];
|
||||
case DHT12:
|
||||
f = data[0] + data[1] * 0.1;
|
||||
break;
|
||||
case DHT22:
|
||||
case DHT21:
|
||||
|
1
DHT.h
1
DHT.h
@ -30,6 +30,7 @@ written by Adafruit Industries
|
||||
|
||||
// Define types of sensors.
|
||||
#define DHT11 11
|
||||
#define DHT12 12
|
||||
#define DHT22 22
|
||||
#define DHT21 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:
|
||||
strncpy(sensor->name, "DHT11", sizeof(sensor->name) - 1);
|
||||
break;
|
||||
case DHT12:
|
||||
strncpy(sensor->name, "DHT12", sizeof(sensor->name) - 1);
|
||||
break;
|
||||
case DHT21:
|
||||
strncpy(sensor->name, "DHT21", sizeof(sensor->name) - 1);
|
||||
break;
|
||||
@ -57,6 +60,9 @@ void DHT_Unified::setMinDelay(sensor_t* sensor) {
|
||||
case DHT11:
|
||||
sensor->min_delay = 1000000L; // 1 second (in microseconds)
|
||||
break;
|
||||
case DHT12:
|
||||
sensor->min_delay = 2000000L; // 2 second (in microseconds)
|
||||
break;
|
||||
case DHT21:
|
||||
sensor->min_delay = 2000000L; // 2 seconds (in microseconds)
|
||||
break;
|
||||
@ -105,6 +111,11 @@ void DHT_Unified::Temperature::getSensor(sensor_t* sensor) {
|
||||
sensor->min_value = 0.0F;
|
||||
sensor->resolution = 2.0F;
|
||||
break;
|
||||
case DHT12:
|
||||
sensor->max_value = 60.0F;
|
||||
sensor->min_value = -20.0F;
|
||||
sensor->resolution = 0.5F;
|
||||
break;
|
||||
case DHT21:
|
||||
sensor->max_value = 80.0F;
|
||||
sensor->min_value = -40.0F;
|
||||
@ -159,6 +170,11 @@ void DHT_Unified::Humidity::getSensor(sensor_t* sensor) {
|
||||
sensor->min_value = 20.0F;
|
||||
sensor->resolution = 5.0F;
|
||||
break;
|
||||
case DHT12:
|
||||
sensor->max_value = 95.0F;
|
||||
sensor->min_value = 20.0F;
|
||||
sensor->resolution = 5.0F;
|
||||
break;
|
||||
case DHT21:
|
||||
sensor->max_value = 100.0F;
|
||||
sensor->min_value = 0.0F;
|
||||
|
Loading…
Reference in New Issue
Block a user