Skip to content

Commit 1f76c41

Browse files
committed
IO: Make waitFor throw an exception in case of a timeout
Previously, it returned a boolean indicating success. But the code on the caller-side will be nicer to read with exceptions.
1 parent 1d1232c commit 1f76c41

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

java/libraries/io/src/processing/io/GPIO.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,18 @@ public static void waitFor(int pin, int mode) {
456456

457457
/**
458458
* Waits for the value of an input pin to change
459+
*
460+
* This function will throw a RuntimeException in case of a timeout.
459461
* @param pin GPIO pin
460462
* @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
461463
* @param timeout don't wait more than timeout milliseconds
462-
* @return true if the interrupt occured, false if the timeout occured
463464
* @webref
464465
*/
465-
public static boolean waitFor(int pin, int mode, int timeout) {
466+
public static void waitFor(int pin, int mode, int timeout) {
466467
enableInterrupt(pin, mode);
467-
return waitForInterrupt(pin, timeout);
468+
if (waitForInterrupt(pin, timeout) == false) {
469+
throw new RuntimeException("Timeout occurred");
470+
}
468471
}
469472

470473

0 commit comments

Comments
 (0)