2 * FILE: PietteTech_DHT.h
4 * PURPOSE: Spark Interrupt driven lib for DHT sensors
5 * LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
7 * S Piette (Piette Technologies) scott.piette@gmail.com
8 * January 2014 Original Spark Port
9 * October 2014 Added support for DHT21/22 sensors
10 * Improved timing, moved FP math out of ISR
12 * Based on adaptation by niesteszeck (github/niesteszeck)
13 * Based on original DHT11 library (http://playgroudn.adruino.cc/Main/DHT11Lib)
16 * With this library connect the DHT sensor to the following pins
17 * D0, D1, D2, D3, D4, A0, A1, A3, A5, A6, A7
18 * http://docs.spark.io/firmware/#interrupts-attachinterrupt
22 #ifndef __PIETTETECH_DHT_H__
23 #define __PIETTETECH_DHT_H__
25 // There appears to be a overrun in memory on this class. For now please leave DHT_DEBUG_TIMING enabled
26 #define DHT_DEBUG_TIMING // Enable this for edge->edge timing collection
28 #include "application.h"
30 #define DHTLIB_VERSION "0.3"
41 #define DHTLIB_ACQUIRING 1
42 #define DHTLIB_ACQUIRED 2
43 #define DHTLIB_RESPONSE_OK 3
46 #define DHTLIB_ERROR_CHECKSUM -1
47 #define DHTLIB_ERROR_ISR_TIMEOUT -2
48 #define DHTLIB_ERROR_RESPONSE_TIMEOUT -3
49 #define DHTLIB_ERROR_DATA_TIMEOUT -4
50 #define DHTLIB_ERROR_ACQUIRING -5
51 #define DHTLIB_ERROR_DELTA -6
52 #define DHTLIB_ERROR_NOTSTARTED -7
54 #define DHT_CHECK_STATE \
55 if(_state == STOPPED) \
57 else if(_state != ACQUIRED) \
58 return DHTLIB_ERROR_ACQUIRING; \
59 if(_convert) convert();
64 PietteTech_DHT(uint8_t sigPin, uint8_t dht_type, void (*isrCallback_wrapper)());
65 void begin(uint8_t sigPin, uint8_t dht_type, void (*isrCallback_wrapper)());
70 float getFahrenheit();
73 double getDewPointSlow();
77 float readTemperature();
79 #if defined(DHT_DEBUG_TIMING)
80 volatile uint8_t _edges[41];
84 void (*isrCallback_wrapper)(void);
87 enum states{RESPONSE=0,DATA=1,ACQUIRED=2,STOPPED=3,ACQUIRING=4};
88 volatile states _state;
90 volatile uint8_t _bits[5];
91 volatile uint8_t _cnt;
92 volatile uint8_t _idx;
93 volatile unsigned long _us;
94 volatile bool _convert;
95 #if defined(DHT_DEBUG_TIMING)
100 unsigned long _lastreadtime;