From 82e0c8764d5dc76734014730a7cb024a9722bd8b Mon Sep 17 00:00:00 2001 From: gohai Date: Fri, 24 Feb 2017 11:21:02 +0100 Subject: [PATCH] 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. --- java/libraries/io/src/processing/io/GPIO.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/java/libraries/io/src/processing/io/GPIO.java b/java/libraries/io/src/processing/io/GPIO.java index 856bdb228..a4042122d 100644 --- a/java/libraries/io/src/processing/io/GPIO.java +++ b/java/libraries/io/src/processing/io/GPIO.java @@ -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"); + } }