aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/Arduino.java
diff options
context:
space:
mode:
Diffstat (limited to 'PunchingBag/src/Arduino.java')
-rw-r--r--PunchingBag/src/Arduino.java42
1 files changed, 34 insertions, 8 deletions
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();
+ }
+
+ }
+
+
+
}