Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. /*
  2.     FILE:       idDHT11.h
  3.     VERSION:    0.1
  4.     PURPOSE:    Interrupt driven Lib for DHT11 with Arduino.
  5.     LICENCE:    GPL v3 (http://www.gnu.org/licenses/gpl.html)
  6.     DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
  7.    
  8.     Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib
  9. */
  10.  
  11.  
  12. #ifndef idDHT11_H__
  13. #define idDHT11_H__
  14.  
  15. #if defined(ARDUINO) && (ARDUINO >= 100)
  16. #include <Arduino.h>
  17. #else
  18. #include <WProgram.h>
  19. #endif
  20.  
  21. #define IDDHT11LIB_VERSION "0.1"
  22.  
  23. // state codes
  24. #define IDDHTLIB_OK         0
  25. #define IDDHTLIB_ACQUIRING      1
  26. #define IDDHTLIB_ACQUIRED       2
  27. #define IDDHTLIB_RESPONSE_OK        3
  28.  
  29. // error codes
  30. #define IDDHTLIB_ERROR_CHECKSUM     -1
  31. #define IDDHTLIB_ERROR_ISR_TIMEOUT  -2
  32. #define IDDHTLIB_ERROR_RESPONSE_TIMEOUT -3
  33. #define IDDHTLIB_ERROR_DATA_TIMEOUT -4
  34. #define IDDHTLIB_ERROR_ACQUIRING    -5
  35. #define IDDHTLIB_ERROR_DELTA        -6
  36. #define IDDHTLIB_ERROR_NOTSTARTED   -7
  37.  
  38. #define IDDHT11_CHECK_STATE     if(state == STOPPED)                                                    \
  39.                                     return status;                                                  \
  40.                                 else if(state != ACQUIRED)              \
  41.                                     return IDDHTLIB_ERROR_ACQUIRING;
  42.                                    
  43. class idDHT11
  44. {
  45. public:
  46.     idDHT11(int pin, int intNumber,void (*isrCallback_wrapper)());
  47.     void init(int pin, int intNumber,void (*isrCallback_wrapper)());
  48.     void isrCallback();
  49.     int acquire();
  50.     int acquireAndWait();
  51.     float getCelsius();
  52.     float getFahrenheit();
  53.     float getKelvin();
  54.     double getDewPoint();
  55.     double getDewPointSlow();
  56.     float getHumidity();
  57.     bool acquiring();
  58.     int getStatus();
  59.    
  60. private:
  61.    
  62.     void (*isrCallback_wrapper)(void);
  63.    
  64.     enum states{RESPONSE=0,DATA=1,ACQUIRED=2,STOPPED=3,ACQUIRING=4};
  65.     volatile states state;
  66.     volatile int status;
  67.     volatile byte bits[5];
  68.     volatile byte cnt;
  69.     volatile byte idx;
  70.     volatile int us;
  71.     int intNumber;
  72.     int pin;
  73.     volatile float hum;
  74.     volatile float temp;
  75. };
  76. #endif // idDHT11_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement