mirror of
https://github.com/processing/processing4.git
synced 2026-01-27 18:31:07 +01:00
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.
This commit is contained in:
@@ -456,15 +456,18 @@ public class GPIO {
|
||||
|
||||
/**
|
||||
* Waits for the value of an input pin to change
|
||||
*
|
||||
* This function will throw a RuntimeException in case of a timeout.
|
||||
* @param pin GPIO pin
|
||||
* @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
|
||||
* @param timeout don't wait more than timeout milliseconds
|
||||
* @return true if the interrupt occured, false if the timeout occured
|
||||
* @webref
|
||||
*/
|
||||
public static boolean waitFor(int pin, int mode, int timeout) {
|
||||
public static void waitFor(int pin, int mode, int timeout) {
|
||||
enableInterrupt(pin, mode);
|
||||
return waitForInterrupt(pin, timeout);
|
||||
if (waitForInterrupt(pin, timeout) == false) {
|
||||
throw new RuntimeException("Timeout occurred");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user