From ba3448fb8093afd9d298cef1123a1bedfea13999 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 7 Sep 2011 09:44:04 +0100 Subject: Added LEDMatrix.pde, this should be used to test the first matrix only! (at the moment). Also added font, this can be used only with java 1.70 and an eclipse maintantice build? --- PunchingBag/src/Arduino.java | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'PunchingBag/src/Arduino.java') diff --git a/PunchingBag/src/Arduino.java b/PunchingBag/src/Arduino.java index 5e6e288..f76bcf6 100644 --- a/PunchingBag/src/Arduino.java +++ b/PunchingBag/src/Arduino.java @@ -11,7 +11,10 @@ import java.io.OutputStream; import gnu.io.*; -public class Arduino { +public class Arduino implements Runnable { + + InputStream in; + OutputStream out; static void listPorts() { @@ -85,12 +88,10 @@ public class Arduino { SerialPort serialPort = (SerialPort) commPort; serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE); - InputStream in = serialPort.getInputStream(); - OutputStream out = serialPort.getOutputStream(); + in = serialPort.getInputStream(); + out = serialPort.getOutputStream(); - (new Thread(new SerialReader(in))).start(); - (new Thread(new SerialWriter(out))).start(); - + (new Thread(this)).start(); } else { @@ -100,7 +101,7 @@ public class Arduino { } /** */ - public static class SerialReader implements Runnable + public class SerialReader implements Runnable { InputStream in; @@ -118,6 +119,7 @@ public class Arduino { while ( ( len = this.in.read(buffer)) > -1 ) { System.out.print(new String(buffer,0,len)); + input(new String(buffer,0,len)); } } catch ( IOException e ) @@ -126,9 +128,13 @@ public class Arduino { } } } + + public static void input(String string) { + + } /** */ - public static class SerialWriter implements Runnable + public class SerialWriter implements Runnable { OutputStream out; @@ -154,4 +160,24 @@ public class Arduino { } } + public void run() { + byte[] buffer = new byte[1024]; + int len = -1; + try + { + while ( ( len = this.in.read(buffer)) > -1 ) + { + System.out.print(new String(buffer,0,len)); + input(new String(buffer,0,len)); + } + } + catch ( IOException e ) + { + e.printStackTrace(); + } + + } + + + } -- cgit v1.2.3