Jan Wolfsberger / HygroClip2

Dependents:   Sensor

Files at this revision

API Documentation at this revision

Comitter:
wolfsberger
Date:
Tue Mar 15 07:45:31 2016 +0000
Parent:
0:0f5101a649db
Commit message:
If no communication was possible the functions now return NaN

Changed in this revision

HygroClip2.cpp Show annotated file Show diff for this revision Revisions of this file
HygroClip2.h Show annotated file Show diff for this revision Revisions of this file
diff -r 0f5101a649db -r 810b9b0dd9a4 HygroClip2.cpp
--- a/HygroClip2.cpp	Tue Feb 16 11:34:37 2016 +0000
+++ b/HygroClip2.cpp	Tue Mar 15 07:45:31 2016 +0000
@@ -1,4 +1,5 @@
 #include "HygroClip2.h"
+#include <cmath>
 
 HygroClip2::HygroClip2(PinName tx, PinName rx)
     : uart_(tx, rx), temperature_(0.0f), humidity_(0.0f), dataReadyToPars_(false)
@@ -12,7 +13,7 @@
 {
     static size_t index = 0;
     uint8_t data = uart_.getc();
-    
+
     if (dataReadyToPars_) {
         return;
     }
@@ -38,13 +39,15 @@
         dataReadyToPars_ = false;
         humidity_ = atof(reinterpret_cast<char *>(&buffer_[11]));
         temperature_ = atof(reinterpret_cast<char *>(&buffer_[29]));
+        isDataValid_ = true;
     }
     else
     {
-        humidity_ = -1.0f;
-        temperature_ = -1.0f;
+        humidity_ = NAN;
+        temperature_ = NAN;
+        isDataValid_ = false;
     }
-    
+
     uart_.printf("{F00RDD}\r");
 }
 
@@ -67,3 +70,7 @@
     float absoluteHumidity = partialPressure / (461.51f * (getTemperature() + 273.15f));
     return absoluteHumidity*1000;
 }
+bool HygroClip2::isDataValid()
+{
+    return isDataValid_;
+}
diff -r 0f5101a649db -r 810b9b0dd9a4 HygroClip2.h
--- a/HygroClip2.h	Tue Feb 16 11:34:37 2016 +0000
+++ b/HygroClip2.h	Tue Mar 15 07:45:31 2016 +0000
@@ -14,16 +14,18 @@
     float getHumidity();
     float getDewPoint();
     float getAbsolutHumidity();
+    bool isDataValid();
 private:
     // Private functions
     void uartCallback();
-        
+
     // Variables
     Serial uart_;
     float temperature_;
     float humidity_;
     bool dataReadyToPars_;
     int8_t buffer_[HYGROCLIP_BUFFER_SIZE + 1];
+    bool isDataValid_;
 };
 
-#endif
\ No newline at end of file
+#endif