Serial printf removed in other to use the nRF52 without BLE Serial

Dependents:   BLE_Bike

Fork of DHT22 by HO WING KIT

Files at this revision

API Documentation at this revision

Comitter:
hwkit
Date:
Mon Jul 04 07:35:03 2011 +0000
Parent:
0:547e68daeb1b
Child:
2:340957cc8fef
Commit message:

Changed in this revision

DHT22.cpp Show annotated file Show diff for this revision Revisions of this file
DHT22.h Show annotated file Show diff for this revision Revisions of this file
--- a/DHT22.cpp	Tue Jun 21 03:44:05 2011 +0000
+++ b/DHT22.cpp	Mon Jul 04 07:35:03 2011 +0000
@@ -36,13 +36,16 @@
 
 #include "DHT22.h"
 
+
 // This should be 40, but the sensor is adding an extra bit at the start
 #define DHT22_DATA_BIT_COUNT 41
 
+Serial pc(USBTX, USBRX);   // Tx, Rx Using USB Virtual Serial Port
+                           // Read Data From /etc/ttyACM* (linux port)
+
 DHT22::DHT22(PinName Data) {
     _data = Data;                // Set Data Pin
-    DigitalInOut      VCC(_vcc);
-    _lastReadTime = time(NULL)-2;
+    _lastReadTime = time(NULL);
     _lastHumidity = 0;
     _lastTemperature = DHT22_ERROR_VALUE;
 }
@@ -52,23 +55,23 @@
 
 DHT22_ERROR DHT22::readData() {
     int i, retryCount;
-    int currentTemperature;
-    int currentHumidity;
-    unsigned int checkSum, csPart1, csPart2, csPart3, csPart4;
+    int currentTemperature=0;
+    int currentHumidity=0;
+    unsigned int checkSum = 0, csPart1, csPart2, csPart3, csPart4;
     unsigned int bitTimes[DHT22_DATA_BIT_COUNT];
-    time_t currentTime;
+    time_t currentTime = time(NULL);
 
     DigitalInOut  DATA(_data);
 
-    currentHumidity = 0;
-    currentTemperature = 0;
-    checkSum = 0;
-    currentTime = time(NULL);
+       
     for (i = 0; i < DHT22_DATA_BIT_COUNT; i++) {
         bitTimes[i] = 0;
     }
+    
     if (currentTime - _lastReadTime < 2) {
-        // Caller needs to wait 2 seconds between each call to read Data
+        // Caller needs to wait 2 seconds between each call to read Data        
+        pc.printf("Current Time: %s\n",currentTime);
+        pc.printf("Last Read Time: %s\n", _lastReadTime);
         return DHT_ERROR_TOOQUICK;
     }
     _lastReadTime = currentTime;
--- a/DHT22.h	Tue Jun 21 03:44:05 2011 +0000
+++ b/DHT22.h	Mon Jul 04 07:35:03 2011 +0000
@@ -24,6 +24,7 @@
 #define MBED_DHT22_H
 
 #include "mbed.h"
+#include "NokiaLCD.h"
 
 /**
  * Currently supports DHT22 (SparkFun Electronics)
@@ -45,6 +46,10 @@
  *
  * int main() {
  *     err=dth22.readData();
+ *     if (err==0) {
+          printf("Temperature is %f.2 C\n",dht22.getTemperature());
+          printf("Humidity is %f.2 \%\n",dht22.getHumidity());
+       }
  *
  *
  */
@@ -64,14 +69,10 @@
 
 class DHT22 {
 private:
-    uint8_t _bitmask;
-    volatile uint8_t *_baseReg;
     time_t  _lastReadTime;
-    PinName _vcc, _data;
-    int     m_addr;
+    PinName _data;
     float   _lastHumidity;
     float   _lastTemperature;
-
 public:
     DHT22(PinName Data);
     ~DHT22();