From d313ac057988ab92835c70e6d5a0c9450dd4d838 Mon Sep 17 00:00:00 2001 From: Henry Bruce Date: Thu, 25 Feb 2016 13:38:28 -0800 Subject: [PATCH] java: Allows Java GPIO ISR sample to exit so IsrExit() method can be tested Signed-off-by: Henry Bruce Signed-off-by: Brendan Le Foll --- examples/java/Isr.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/java/Isr.java b/examples/java/Isr.java index a43dcc7..9634899 100644 --- a/examples/java/Isr.java +++ b/examples/java/Isr.java @@ -22,6 +22,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import mraa.Dir; import mraa.Edge; import mraa.Gpio; @@ -37,6 +40,7 @@ public class Isr { System.exit(1); } } + public static void main(String argv[]) throws InterruptedException { int pin = 6; if (argv.length == 1) { @@ -45,15 +49,17 @@ public class Isr { } catch (Exception e) { } } - System.out.println("Starting ISR for pin " + Integer.toString(pin)); + BufferedReader console = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Starting ISR for pin " + Integer.toString(pin) + ". Press ENTER to stop"); Gpio gpio = new Gpio(pin); - Runnable callback = new JavaCallback(); - gpio.isr(Edge.EDGE_RISING, callback); - while (true) - Thread.sleep(999999); - }; + try { + String input = console.readLine(); + } catch (IOException e) { + } + gpio.isrExit(); + } }