idDHT11/idDHT11.h
niesteszeck b958c6e1f6 v 0.1.1 Optimization by pylon
added a changelog
2013-07-04 10:14:49 -04:00

80 lines
1.8 KiB
C++

/*
FILE: idDHT11.h
VERSION: 0.1.1
PURPOSE: Interrupt driven Lib for DHT11 with Arduino.
LICENCE: GPL v3 (http://www.gnu.org/licenses/gpl.html)
DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib
Changelog:
v 0.1
First version, added Functionality to DHT11 sensor
v 0.1.1
Optimizacion on shift var (pylon from Arduino Forum)
*/
#ifndef idDHT11_H__
#define idDHT11_H__
#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define IDDHT11LIB_VERSION "0.1.1"
// state codes
#define IDDHTLIB_OK 0
#define IDDHTLIB_ACQUIRING 1
#define IDDHTLIB_ACQUIRED 2
#define IDDHTLIB_RESPONSE_OK 3
// error codes
#define IDDHTLIB_ERROR_CHECKSUM -1
#define IDDHTLIB_ERROR_TIMEOUT -2
#define IDDHTLIB_ERROR_ACQUIRING -3
#define IDDHTLIB_ERROR_DELTA -4
#define IDDHTLIB_ERROR_NOTSTARTED -5
#define IDDHT11_CHECK_STATE if(state == STOPPED) \
return status; \
else if(state != ACQUIRED) \
return IDDHTLIB_ERROR_ACQUIRING;
class idDHT11
{
public:
idDHT11(int pin, int intNumber,void (*isrCallback_wrapper)());
void init(int pin, int intNumber,void (*isrCallback_wrapper)());
void isrCallback();
int acquire();
int acquireAndWait();
float getCelsius();
float getFahrenheit();
float getKelvin();
double getDewPoint();
double getDewPointSlow();
float getHumidity();
bool acquiring();
int getStatus();
private:
void (*isrCallback_wrapper)(void);
enum states{RESPONSE=0,DATA=1,ACQUIRED=2,STOPPED=3,ACQUIRING=4};
volatile states state;
volatile int status;
volatile byte bits[5];
volatile byte cnt;
volatile byte idx;
volatile int us;
int intNumber;
int pin;
volatile float hum;
volatile float temp;
};
#endif // idDHT11_H__