diff options
author | Adam Martindale <awiamartindale@googlemail.com> | 2011-09-07 17:13:09 +0100 |
---|---|---|
committer | Adam Martindale <awiamartindale@googlemail.com> | 2011-09-07 17:13:09 +0100 |
commit | 0924d5ff228cf801522d8d3c770516baf577a6ca (patch) | |
tree | d1213edd3e6235880eeb9b613fe9de94a6511c27 /PunchingBag/src | |
parent | c13af0b6901ce6478a21233d0868969d06a6bc9a (diff) | |
parent | a09647f50841e23e4783ef8c34faa9219054234f (diff) | |
download | punchingbag-0924d5ff228cf801522d8d3c770516baf577a6ca.tar punchingbag-0924d5ff228cf801522d8d3c770516baf577a6ca.tar.gz |
Merge branch 'master' of gitorious.org:punchingbag/punchingbag
Conflicts:
PunchingBag/src/PunchingBag.java
Diffstat (limited to 'PunchingBag/src')
-rw-r--r-- | PunchingBag/src/Arduino.java | 11 | ||||
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 58 |
2 files changed, 50 insertions, 19 deletions
diff --git a/PunchingBag/src/Arduino.java b/PunchingBag/src/Arduino.java index f76bcf6..12df25f 100644 --- a/PunchingBag/src/Arduino.java +++ b/PunchingBag/src/Arduino.java @@ -179,5 +179,16 @@ public class Arduino implements Runnable { }
+ public void write(byte[] bytes) throws IOException {
+ out.write(bytes);
+ }
+
+ public void write(byte b) throws IOException {
+ out.write(b);
+ }
+
+ public int read() throws IOException {
+ return in.read();
+ }
}
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index bcaf220..00be6e0 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -1,6 +1,9 @@ import javax.swing.event.EventListenerList; import java.awt.geom.Area; + +import java.io.IOException; + import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -20,8 +23,9 @@ public class PunchingBag implements Runnable { boolean buttonsChanged = false; private ArrayList<Effect> runningEffects = new ArrayList<Effect>(); - - ButtonArduino buttonArduino = new ButtonArduino(); + + Arduino buttonArduino = new Arduino(); + Arduino ledArduino = new Arduino(); public enum Colour { None, Red, Yellow, Green @@ -36,7 +40,6 @@ public class PunchingBag implements Runnable { private EventListenerList ledListenerList = new EventListenerList(); private EventListenerList accelListenerList = new EventListenerList(); - public PunchingBag() { new Thread(this).start(); } @@ -54,7 +57,7 @@ public class PunchingBag implements Runnable { public void addLEDChangeListener(LEDListener l) { ledListenerList.add(LEDListener.class, l); } - + public void addLEDChangeListener(AccelListener l) { accelListenerList.add(AccelListener.class, l); } @@ -216,21 +219,16 @@ public class PunchingBag implements Runnable { } } } - int x = 7; - // TODO: Complete and test, or rethink the following? - for (int startY = 0; startY <= 4; startY++) { - for (int y = 0; y <= 3; y++) { - if (leds[x][startY + (y * 4)] == Colour.Red - || leds[x][startY + (y * 4)] == Colour.Yellow) { - rawLeds[(5 * 8) + startY] = (byte) (rawLeds[(int) Math - .floor(y / 4)] | (1 << (7 - x))); - } - if (leds[x][y] == Colour.Green || leds[x][y] == Colour.Yellow) { - rawLeds[(int) Math.floor(y / 4)] = (byte) (rawLeds[(int) Math - .floor(y / 4)] | (1 << (7 - x))); - } - } - } + /* + * int x = 7; // TODO: Complete and test, or rethink the following? for + * (int startY = 0; startY <= 4; startY++) { for (int y = 0; y <= 3; + * y++) { if (leds[x][startY + (y * 4)] == Colour.Red || leds[x][startY + * + (y * 4)] == Colour.Yellow) { rawLeds[(5 * 8) + startY] = (byte) + * (rawLeds[(int) Math .floor(y / 4)] | (1 << (7 - x))); } if + * (leds[x][y] == Colour.Green || leds[x][y] == Colour.Yellow) { + * rawLeds[(int) Math.floor(y / 4)] = (byte) (rawLeds[(int) Math + * .floor(y / 4)] | (1 << (7 - x))); } } } + */ } /* Clears the led grid and stops all running effects */ @@ -279,6 +277,28 @@ public class PunchingBag implements Runnable { } } + 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 (ledsChanged) { LEDListener[] LEDListeners = ledListenerList .getListeners(LEDListener.class); |