mirror of
https://github.com/niesteszeck/idDHT11.git
synced 2025-03-15 04:27:29 +03:00
Merge pull request #1 from WurdahMekanik/master
Adds error codes to differentiate between timeout possibilities, fixes delta range for data acquisition, and updates example code.
This commit is contained in:
commit
e2f34b0ec7
@ -47,8 +47,14 @@ void loop()
|
||||
case IDDHTLIB_ERROR_CHECKSUM:
|
||||
Serial.println("Error\n\r\tChecksum error");
|
||||
break;
|
||||
case IDDHTLIB_ERROR_TIMEOUT:
|
||||
Serial.println("Error\n\r\tTime out error");
|
||||
case IDDHTLIB_ERROR_ISR_TIMEOUT:
|
||||
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;
|
||||
case IDDHTLIB_ERROR_ACQUIRING:
|
||||
Serial.println("Error\n\r\tAcquiring");
|
||||
|
@ -47,8 +47,14 @@ void loop()
|
||||
case IDDHTLIB_ERROR_CHECKSUM:
|
||||
Serial.println("Error\n\r\tChecksum error");
|
||||
break;
|
||||
case IDDHTLIB_ERROR_TIMEOUT:
|
||||
Serial.println("Error\n\r\tTime out error");
|
||||
case IDDHTLIB_ERROR_ISR_TIMEOUT:
|
||||
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;
|
||||
case IDDHTLIB_ERROR_ACQUIRING:
|
||||
Serial.println("Error\n\r\tAcquiring");
|
||||
|
@ -67,7 +67,7 @@ void idDHT11::isrCallback() {
|
||||
int delta = (newUs-us);
|
||||
us = newUs;
|
||||
if (delta>6000) {
|
||||
status = IDDHTLIB_ERROR_TIMEOUT;
|
||||
status = IDDHTLIB_ERROR_ISR_TIMEOUT;
|
||||
state = STOPPED;
|
||||
detachInterrupt(intNumber);
|
||||
return;
|
||||
@ -81,7 +81,7 @@ void idDHT11::isrCallback() {
|
||||
state = DATA;
|
||||
} else {
|
||||
detachInterrupt(intNumber);
|
||||
status = IDDHTLIB_ERROR_TIMEOUT;
|
||||
status = IDDHTLIB_ERROR_RESPONSE_TIMEOUT;
|
||||
state = STOPPED;
|
||||
}
|
||||
break;
|
||||
@ -90,7 +90,7 @@ void idDHT11::isrCallback() {
|
||||
detachInterrupt(intNumber);
|
||||
status = IDDHTLIB_ERROR_DELTA;
|
||||
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
|
||||
bits[idx] |= (1 << cnt);
|
||||
if (cnt == 0) { // whe have fullfilled the byte, go to next
|
||||
@ -114,7 +114,7 @@ void idDHT11::isrCallback() {
|
||||
} else cnt--;
|
||||
} else {
|
||||
detachInterrupt(intNumber);
|
||||
status = IDDHTLIB_ERROR_TIMEOUT;
|
||||
status = IDDHTLIB_ERROR_DATA_TIMEOUT;
|
||||
state = STOPPED;
|
||||
}
|
||||
break;
|
||||
|
10
idDHT11.h
10
idDHT11.h
@ -28,10 +28,12 @@
|
||||
|
||||
// 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 IDDHTLIB_ERROR_ISR_TIMEOUT -2
|
||||
#define IDDHTLIB_ERROR_RESPONSE_TIMEOUT -3
|
||||
#define IDDHTLIB_ERROR_DATA_TIMEOUT -4
|
||||
#define IDDHTLIB_ERROR_ACQUIRING -5
|
||||
#define IDDHTLIB_ERROR_DELTA -6
|
||||
#define IDDHTLIB_ERROR_NOTSTARTED -7
|
||||
|
||||
#define IDDHT11_CHECK_STATE if(state == STOPPED) \
|
||||
return status; \
|
||||
|
Loading…
x
Reference in New Issue
Block a user