mirror of
https://github.com/niesteszeck/idDHT11.git
synced 2025-03-15 04:27:29 +03:00
merged remote
This commit is contained in:
commit
dba784e36e
@ -12,7 +12,7 @@ int idDHT11pin = 2; //Digital pin for comunications
|
|||||||
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
|
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
|
||||||
|
|
||||||
//declaration
|
//declaration
|
||||||
void dht11_wrapper();
|
void dht11_wrapper(); // must be declared before the lib initialization
|
||||||
|
|
||||||
// Lib instantiate
|
// Lib instantiate
|
||||||
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
|
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
|
||||||
@ -25,6 +25,8 @@ void setup()
|
|||||||
Serial.println(IDDHT11LIB_VERSION);
|
Serial.println(IDDHT11LIB_VERSION);
|
||||||
Serial.println("---------------");
|
Serial.println("---------------");
|
||||||
}
|
}
|
||||||
|
// This wrapper is in charge of calling
|
||||||
|
// mus be defined like this for the lib work
|
||||||
void dht11_wrapper() {
|
void dht11_wrapper() {
|
||||||
DHT11.isrCallback();
|
DHT11.isrCallback();
|
||||||
}
|
}
|
||||||
@ -45,8 +47,14 @@ void loop()
|
|||||||
case IDDHTLIB_ERROR_CHECKSUM:
|
case IDDHTLIB_ERROR_CHECKSUM:
|
||||||
Serial.println("Error\n\r\tChecksum error");
|
Serial.println("Error\n\r\tChecksum error");
|
||||||
break;
|
break;
|
||||||
case IDDHTLIB_ERROR_TIMEOUT:
|
case IDDHTLIB_ERROR_ISR_TIMEOUT:
|
||||||
Serial.println("Error\n\r\tTime out error");
|
Serial.println("Error\n\r\tISR Time out error");
|
||||||
|
break;
|
||||||
|
case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
|
||||||
|
Serial.println("Error\n\r\tResponse time out error");
|
||||||
|
break;
|
||||||
|
case IDDHTLIB_ERROR_DATA_TIMEOUT:
|
||||||
|
Serial.println("Error\n\r\tData time out error");
|
||||||
break;
|
break;
|
||||||
case IDDHTLIB_ERROR_ACQUIRING:
|
case IDDHTLIB_ERROR_ACQUIRING:
|
||||||
Serial.println("Error\n\r\tAcquiring");
|
Serial.println("Error\n\r\tAcquiring");
|
||||||
|
@ -14,7 +14,7 @@ int idDHT11pin = 2; //Digital pin for comunications
|
|||||||
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
|
int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above)
|
||||||
|
|
||||||
//declaration
|
//declaration
|
||||||
void dht11_wrapper();
|
void dht11_wrapper(); // must be declared before the lib initialization
|
||||||
|
|
||||||
// Lib instantiate
|
// Lib instantiate
|
||||||
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
|
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);
|
||||||
@ -27,6 +27,8 @@ void setup()
|
|||||||
Serial.println(IDDHT11LIB_VERSION);
|
Serial.println(IDDHT11LIB_VERSION);
|
||||||
Serial.println("---------------");
|
Serial.println("---------------");
|
||||||
}
|
}
|
||||||
|
// This wrapper is in charge of calling
|
||||||
|
// mus be defined like this for the lib work
|
||||||
void dht11_wrapper() {
|
void dht11_wrapper() {
|
||||||
DHT11.isrCallback();
|
DHT11.isrCallback();
|
||||||
}
|
}
|
||||||
@ -45,8 +47,14 @@ void loop()
|
|||||||
case IDDHTLIB_ERROR_CHECKSUM:
|
case IDDHTLIB_ERROR_CHECKSUM:
|
||||||
Serial.println("Error\n\r\tChecksum error");
|
Serial.println("Error\n\r\tChecksum error");
|
||||||
break;
|
break;
|
||||||
case IDDHTLIB_ERROR_TIMEOUT:
|
case IDDHTLIB_ERROR_ISR_TIMEOUT:
|
||||||
Serial.println("Error\n\r\tTime out error");
|
Serial.println("Error\n\r\tISR time out error");
|
||||||
|
break;
|
||||||
|
case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
|
||||||
|
Serial.println("Error\n\r\tResponse time out error");
|
||||||
|
break;
|
||||||
|
case IDDHTLIB_ERROR_DATA_TIMEOUT:
|
||||||
|
Serial.println("Error\n\r\tData time out error");
|
||||||
break;
|
break;
|
||||||
case IDDHTLIB_ERROR_ACQUIRING:
|
case IDDHTLIB_ERROR_ACQUIRING:
|
||||||
Serial.println("Error\n\r\tAcquiring");
|
Serial.println("Error\n\r\tAcquiring");
|
||||||
|
@ -67,7 +67,7 @@ void idDHT11::isrCallback() {
|
|||||||
int delta = (newUs-us);
|
int delta = (newUs-us);
|
||||||
us = newUs;
|
us = newUs;
|
||||||
if (delta>6000) {
|
if (delta>6000) {
|
||||||
status = IDDHTLIB_ERROR_TIMEOUT;
|
status = IDDHTLIB_ERROR_ISR_TIMEOUT;
|
||||||
state = STOPPED;
|
state = STOPPED;
|
||||||
detachInterrupt(intNumber);
|
detachInterrupt(intNumber);
|
||||||
return;
|
return;
|
||||||
@ -81,7 +81,7 @@ void idDHT11::isrCallback() {
|
|||||||
state = DATA;
|
state = DATA;
|
||||||
} else {
|
} else {
|
||||||
detachInterrupt(intNumber);
|
detachInterrupt(intNumber);
|
||||||
status = IDDHTLIB_ERROR_TIMEOUT;
|
status = IDDHTLIB_ERROR_RESPONSE_TIMEOUT;
|
||||||
state = STOPPED;
|
state = STOPPED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -90,7 +90,7 @@ void idDHT11::isrCallback() {
|
|||||||
detachInterrupt(intNumber);
|
detachInterrupt(intNumber);
|
||||||
status = IDDHTLIB_ERROR_DELTA;
|
status = IDDHTLIB_ERROR_DELTA;
|
||||||
state = STOPPED;
|
state = STOPPED;
|
||||||
} else if(60<delta && delta<135) { //valid in timing
|
} else if(60<delta && delta<155) { //valid in timing
|
||||||
if(delta>90) //is a one
|
if(delta>90) //is a one
|
||||||
bits[idx] |= (1 << cnt);
|
bits[idx] |= (1 << cnt);
|
||||||
if (cnt == 0) { // whe have fullfilled the byte, go to next
|
if (cnt == 0) { // whe have fullfilled the byte, go to next
|
||||||
@ -114,7 +114,7 @@ void idDHT11::isrCallback() {
|
|||||||
} else cnt--;
|
} else cnt--;
|
||||||
} else {
|
} else {
|
||||||
detachInterrupt(intNumber);
|
detachInterrupt(intNumber);
|
||||||
status = IDDHTLIB_ERROR_TIMEOUT;
|
status = IDDHTLIB_ERROR_DATA_TIMEOUT;
|
||||||
state = STOPPED;
|
state = STOPPED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
16
idDHT11.h
16
idDHT11.h
@ -21,17 +21,19 @@
|
|||||||
#define IDDHT11LIB_VERSION "0.1"
|
#define IDDHT11LIB_VERSION "0.1"
|
||||||
|
|
||||||
// state codes
|
// state codes
|
||||||
#define IDDHTLIB_OK 0
|
#define IDDHTLIB_OK 0
|
||||||
#define IDDHTLIB_ACQUIRING 1
|
#define IDDHTLIB_ACQUIRING 1
|
||||||
#define IDDHTLIB_ACQUIRED 2
|
#define IDDHTLIB_ACQUIRED 2
|
||||||
#define IDDHTLIB_RESPONSE_OK 3
|
#define IDDHTLIB_RESPONSE_OK 3
|
||||||
|
|
||||||
// error codes
|
// error codes
|
||||||
#define IDDHTLIB_ERROR_CHECKSUM -1
|
#define IDDHTLIB_ERROR_CHECKSUM -1
|
||||||
#define IDDHTLIB_ERROR_TIMEOUT -2
|
#define IDDHTLIB_ERROR_ISR_TIMEOUT -2
|
||||||
#define IDDHTLIB_ERROR_ACQUIRING -3
|
#define IDDHTLIB_ERROR_RESPONSE_TIMEOUT -3
|
||||||
#define IDDHTLIB_ERROR_DELTA -4
|
#define IDDHTLIB_ERROR_DATA_TIMEOUT -4
|
||||||
#define IDDHTLIB_ERROR_NOTSTARTED -5
|
#define IDDHTLIB_ERROR_ACQUIRING -5
|
||||||
|
#define IDDHTLIB_ERROR_DELTA -6
|
||||||
|
#define IDDHTLIB_ERROR_NOTSTARTED -7
|
||||||
|
|
||||||
#define IDDHT11_CHECK_STATE if(state == STOPPED) \
|
#define IDDHT11_CHECK_STATE if(state == STOPPED) \
|
||||||
return status; \
|
return status; \
|
||||||
@ -71,4 +73,4 @@ private:
|
|||||||
volatile float hum;
|
volatile float hum;
|
||||||
volatile float temp;
|
volatile float temp;
|
||||||
};
|
};
|
||||||
#endif // idDHT11_H__
|
#endif // idDHT11_H__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user