Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DHT by
Revision 4:3ad8f6b4d2f8, committed 2018-07-24
- Comitter:
- lamell
- Date:
- Tue Jul 24 19:48:51 2018 +0000
- Parent:
- 3:6937e130feca
- Commit message:
- No changes
Changed in this revision
| DHT.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/DHT.cpp Sat May 28 11:11:34 2016 +0000
+++ b/DHT.cpp Tue Jul 24 19:48:51 2018 +0000
@@ -118,8 +118,11 @@
}
// uncomment to see the checksum error if it exists
- //printf(" 0x%02x + 0x%02x + 0x%02x + 0x%02x = 0x%02x \n", DHT_data[0], DHT_data[1], DHT_data[2], DHT_data[3], DHT_data[4]);
data_valid = DHT_data[0] + DHT_data[1] + DHT_data[2] + DHT_data[3];
+
+ //printf(" 0x%02X + 0x%02X + 0x%02X + 0x%02X => Snsr Chk: 0x%02X Rcvd Chk: 0x%02X\n", DHT_data[0], DHT_data[1],
+ // DHT_data[2], DHT_data[3], DHT_data[4], data_valid);
+
if (DHT_data[4] == data_valid) {
_lastReadTime = currentTime;
_lastTemperature = CalcTemperature();
@@ -136,19 +139,18 @@
float DHT::CalcTemperature()
{
int v;
-
+ float result;
+
switch (_DHTtype) {
case DHT11:
v = DHT_data[2];
return float(v);
case DHT22:
- v = DHT_data[2] & 0x7F;
- v *= 256;
- v += DHT_data[3];
- v /= 10;
- if (DHT_data[2] & 0x80)
- v *= -1;
- return float(v);
+ //v = DHT_data[0];
+ //v *= 256;
+ //v += DHT_data[1];
+ result = ((DHT_data[2] * 256)+ DHT_data[3]) /10.0f;
+ return float(result);
}
return 0;
}
@@ -208,17 +210,18 @@
float DHT::CalcHumidity()
{
int v;
-
+ float result;
+
switch (_DHTtype) {
case DHT11:
v = DHT_data[0];
return float(v);
case DHT22:
- v = DHT_data[0];
- v *= 256;
- v += DHT_data[1];
- v /= 10;
- return float(v);
+ //v = DHT_data[0];
+ //v *= 256;
+ //v += DHT_data[1];
+ result = ((DHT_data[0] * 256)+ DHT_data[1]) /10.0f;
+ return float(result);
}
return 0;
}
