From 852306221f4adcaf2ea9edb68153ea6090b68803 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 12 Sep 2011 09:54:03 +0100 Subject: Commit to move to other laptop due to technical dificulties. --- PunchingBag/src/PunchingBag.java | 57 ++++++++++++++++++++++++++----------- PunchingBag/src/PunchingBagGUI.java | 4 +-- 2 files changed, 43 insertions(+), 18 deletions(-) (limited to 'PunchingBag') diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 198e709..85553a5 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -346,9 +346,20 @@ public class PunchingBag implements Runnable { } return true; } + + private void readAccelData(String data) { + //System.out.print("Data: "); + System.out.println(data); + //String[] nums = data.split(" "); + /*System.out.println(nums); + for (int x=0; x<4; x++) { + System.out.println(nums[x]); + }*/ + } public void run() { while (true) { + //System.out.println("R"); synchronized (leds) { clearLEDGrid(); @@ -373,29 +384,43 @@ public class PunchingBag implements Runnable { if (buttonArduino.in != null) { try { - int read = buttonArduino.read(); - if (read != -1) { - System.out.println(read); + int read; + while ((read = buttonArduino.read()) != -1) { + //System.out.print((char) read); + if ((char) read == 'A') { + String str = ""; + //StringBuilder sb = new StringBuilder(20); + while ((read = buttonArduino.read()) != '\n') { + str = str + String.valueOf((char) read); + //sb.append((char) read); + } + //System.out.println(""); + readAccelData(str); + //String[] nums = sbString.trim().split(" "); + //System.out.println(nums); + //for (int x=0; x<4; x++) { + // System.out.println(nums[x]); + //} + } else { + //System.out.println((char) read); + } + //System.out.print("|"); } - byte[] bA = { 0x49 }; - if (Math.random() > 0.9) - buttonArduino.write(bA); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } - /* - * try { ledArduino.write(((byte) 108)); ledArduino.write(((byte) - * 101)); ledArduino.write(rawLeds); } catch (IOException e1) { - * e1.printStackTrace(); } - * - * try { while (true) { int value = ledArduino.read(); if (value != - * -1) { System.out.print(ledArduino.read()); } else { break; } } } - * catch (IOException e1) { // TODO Auto-generated catch block - * e1.printStackTrace(); } - */ + /*if (ledArduino.out != null) { + try { + ledArduino.write(((byte) 108)); + ledArduino.write(((byte) 101)); + ledArduino.write(rawLeds); + } catch (IOException e1) { + e1.printStackTrace(); + } + }*/ if (ledsChanged) { LEDListener[] LEDListeners = ledListenerList diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java index aacb2ac..9a23741 100644 --- a/PunchingBag/src/PunchingBagGUI.java +++ b/PunchingBag/src/PunchingBagGUI.java @@ -184,7 +184,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, @Override public void serialWriteEvent(byte b) { - buttonOut.append(String.valueOf(b)); + buttonOut.append(String.valueOf((char) b)); } @Override @@ -195,7 +195,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, @Override public void serialReadEvent(int b) { if (b != -1) - buttonIn.append(String.valueOf(b)); + buttonIn.append(String.valueOf((char) b)); } } -- cgit v1.2.3