aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/PunchingBag.java
diff options
context:
space:
mode:
Diffstat (limited to 'PunchingBag/src/PunchingBag.java')
-rw-r--r--PunchingBag/src/PunchingBag.java57
1 files changed, 41 insertions, 16 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