| 38 | */ |
| 39 | |
| 40 | static int maxDetectLowHighWait (const int pin) |
| 41 | { |
| 42 | struct timeval now, timeOut, timeUp ; |
| 43 | |
| 44 | // If already high then wait for pin to go low |
| 45 | |
| 46 | gettimeofday (&now, NULL) ; |
| 47 | timerclear (&timeOut) ; |
| 48 | timeOut.tv_usec = 1000 ; |
| 49 | timeradd (&now, &timeOut, &timeUp) ; |
| 50 | |
| 51 | while (digitalRead (pin) == HIGH) |
| 52 | { |
| 53 | gettimeofday (&now, NULL) ; |
| 54 | if (timercmp (&now, &timeUp, >)) |
| 55 | return false ; |
| 56 | } |
| 57 | |
| 58 | // Wait for it to go HIGH |
| 59 | |
| 60 | gettimeofday (&now, NULL) ; |
| 61 | timerclear (&timeOut) ; |
| 62 | timeOut.tv_usec = 1000 ; |
| 63 | timeradd (&now, &timeOut, &timeUp) ; |
| 64 | |
| 65 | while (digitalRead (pin) == LOW) |
| 66 | { |
| 67 | gettimeofday (&now, NULL) ; |
| 68 | if (timercmp (&now, &timeUp, >)) |
| 69 | return false ; |
| 70 | } |
| 71 | |
| 72 | return true ; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | /* |
no test coverage detected