DHT22 library, based on Simon Cooksey's. Improved with some error checking and more rigid timing (interrupts off).
Fork of lib_dht22 by
Revision 4:30a98da09c59, committed 2016-11-03
- Comitter:
- co657_frmb
- Date:
- Thu Nov 03 11:12:51 2016 +0000
- Parent:
- 3:40df3c72813f
- Commit message:
- turned off debugging
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 Thu Nov 03 11:08:45 2016 +0000 +++ b/dht22.cpp Thu Nov 03 11:12:51 2016 +0000 @@ -160,9 +160,11 @@ if (d > DHT22_SIGNAL_HIGH_LOW_BOUNDARY) { v |= (1 << bit); +#ifdef DEBUG_DHT22 debug = 1; - } else { + } else { debug = 0; +#endif } } @@ -180,8 +182,10 @@ uint8_t buf[5]; uint16_t u_hum, u_tmp; int i; - + +#ifdef DEBUG_DHT22 debug = 0; +#endif __disable_irq (); // Send start bits send_start(); @@ -227,7 +231,10 @@ } data->checksum = buf[0]; + +#ifdef DEBUG_DHT22 debug = 0; +#endif return i; }
--- a/dht22.h Thu Nov 03 11:08:45 2016 +0000 +++ b/dht22.h Thu Nov 03 11:12:51 2016 +0000 @@ -10,6 +10,7 @@ #define DHT22_START_BIT_TIME 1000 // uS #define DHT22_START_BIT_RESPONSE 80 // uS +#undef DEBUG_DHT22 typedef struct { int temp; @@ -20,7 +21,10 @@ class DHT22 { public: - DHT22 (PinName pin) : dht22_s (pin), debug (PTB19) + DHT22 (PinName pin) : dht22_s (pin) +#ifdef DEBUG_DHT22 + , debug (PTB19) /* GROT! -- hardwired for K64F */ +#endif { dht22_s.input (); isinput = 1; @@ -30,7 +34,9 @@ private: DigitalInOut dht22_s; int isinput; +#ifdef DEBUG_DHT22 DigitalOut debug; +#endif void wait_2us (void); void setinput (void);