aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2011-09-12 09:54:03 +0100
committerChristopher Baines <cbaines8@gmail.com>2011-09-12 09:54:03 +0100
commit852306221f4adcaf2ea9edb68153ea6090b68803 (patch)
treeddd7ee44c62a4f22ddb30db717a86eba48596407 /PunchingBag
parent8962f50d7c24d428f0fdc2d1d90c65d4f9e7955c (diff)
downloadpunchingbag-852306221f4adcaf2ea9edb68153ea6090b68803.tar
punchingbag-852306221f4adcaf2ea9edb68153ea6090b68803.tar.gz
Commit to move to other laptop due to technical dificulties.
Diffstat (limited to 'PunchingBag')
-rw-r--r--PunchingBag/src/PunchingBag.java57
-rw-r--r--PunchingBag/src/PunchingBagGUI.java4
2 files changed, 43 insertions, 18 deletions
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));
}
}