aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/PunchingBag.java
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2011-09-02 10:56:45 +0100
committerChristopher Baines <cbaines8@gmail.com>2011-09-02 10:56:45 +0100
commita5dceb099dcca2eb30b663c0f8f1767e8e68343b (patch)
treedb94f22a5e9434967e175d10389d4e5fe463c962 /PunchingBag/src/PunchingBag.java
parent1d7fd079f80ad6b097aae795d74dd19e10b2e14e (diff)
downloadpunchingbag-a5dceb099dcca2eb30b663c0f8f1767e8e68343b.tar
punchingbag-a5dceb099dcca2eb30b663c0f8f1767e8e68343b.tar.gz
Inproved punching bag and general api.
Diffstat (limited to 'PunchingBag/src/PunchingBag.java')
-rw-r--r--PunchingBag/src/PunchingBag.java97
1 files changed, 80 insertions, 17 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
index 278a8fc..69d9fd0 100644
--- a/PunchingBag/src/PunchingBag.java
+++ b/PunchingBag/src/PunchingBag.java
@@ -1,24 +1,87 @@
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-
-import javax.swing.JButton;
+import java.util.Arrays;
import javax.swing.event.EventListenerList;
+public class PunchingBag implements Runnable {
+ private byte[] rawLeds = new byte[6*8];
+ private Colour[][] leds = new Colour[9][20];
+ private byte[] ledGridIntensities = new byte[6];
+ private boolean[][] buttons = new boolean[8][19];
+
+ enum Colour {
+ None, Red, Yellow, Green
+ };
+
+ private EventListenerList buttonListenerList = new EventListenerList();
+ private EventListenerList ledListenerList = new EventListenerList();
+
+ public PunchingBag() {
+ new Thread(this).start();
+ }
+
+ /**
+ * Adds an <code>ActionListener</code> to the button.
+ *
+ * @param l
+ * the <code>ActionListener</code> to be added
+ */
+ public void addButtonListener(ButtonListener l) {
+ buttonListenerList.add(ButtonListener.class, l);
+ }
+
+ public void addLEDChangeListener(ButtonListener l) {
+ ledListenerList.add(ButtonListener.class, l);
+ }
+
+ public void setLED(byte x, byte y, Colour colour) {
+ leds[x][y] = colour;
+ }
-public class PunchingBag {
- protected EventListenerList listenerList = new EventListenerList();
-
- /**
- * Adds an <code>ActionListener</code> to the button.
- * @param l the <code>ActionListener</code> to be added
- */
- public void addButtonListener(ButtonListener l) {
- listenerList.add(ButtonListener.class, l);
- }
+ private void calculateRawLeds() {
+ for (int y = 0; y <= 18; y++) {
+ for (int x = 0; x <= 6; x++) {
+ if ((y % 2) == 0) {
+ 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)));
+ }
+ } else {
+ if (leds[x][y] == Colour.Red || 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)));
+ }
+ }
+ }
+ }
+
+ public void clearLEDGrid() {
+ Arrays.fill(leds, Boolean.FALSE);
+ }
- public void setLED(byte x, byte y, byte intensity) {
-
-
+ public void setLEDGridIntensity(byte grid, byte intensity) {
+ ledGridIntensities[grid] = intensity;
}
+ public void setLEDIntensities(byte intensity) {
+ Arrays.fill(ledGridIntensities, intensity);
+ }
+
+ public void run() {
+
+ }
}