Libery for DHT-22 temp sensor

Dependents:   Brew_Keg

Fork of DHT by Wim De Roeve

Files at this revision

API Documentation at this revision

Comitter:
gert_lauritsen
Date:
Fri Feb 05 10:03:57 2016 +0000
Parent:
0:9b5b3200688f
Commit message:
There was an error in converting to float, trunkating the value

Changed in this revision

DHT.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9b5b3200688f -r 6ddabfde1db6 DHT.cpp
--- a/DHT.cpp	Mon Jul 09 19:47:43 2012 +0000
+++ b/DHT.cpp	Fri Feb 05 10:03:57 2016 +0000
@@ -149,7 +149,7 @@
 
 float DHT::CalcTemperature() {
     int v;
-
+    float outvalue;
     switch (_DHTtype) {
         case DHT11:
             v = DHT_data[2];
@@ -158,10 +158,10 @@
             v = DHT_data[2] & 0x7F;
             v *= 256;
             v += DHT_data[3];
-            v /= 10;
+            outvalue=(float) v/10;
             if (DHT_data[2] & 0x80)
-                v *= -1;
-            return float(v);
+                outvalue *= -1;
+            return outvalue;
     }
     return 0;
 }
@@ -215,7 +215,8 @@
 
 float DHT::CalcHumidity() {
     int v;
-
+    float outvalue;
+    
     switch (_DHTtype) {
         case DHT11:
             v = DHT_data[0];
@@ -224,8 +225,8 @@
             v = DHT_data[0];
             v *= 256;
             v += DHT_data[1];
-            v /= 10;
-            return float(v);
+            outvalue=(float) v/10;
+            return outvalue;
     }
     return 0;
 }