diff options
author | Adam Martindale <awiamartindale@googlemail.com> | 2011-09-02 11:38:05 +0100 |
---|---|---|
committer | Adam Martindale <awiamartindale@googlemail.com> | 2011-09-02 11:38:05 +0100 |
commit | 68c2bc40f25810ce01bdebcd3bfe90b7a76b5413 (patch) | |
tree | bdb4422c58d2ff35a803ddb3bad73d21425ad9cf /PunchingBag/src/PunchingBag.java | |
parent | f5f7d3ca20f102e704f8d0705158ea58a3e4c305 (diff) | |
parent | a5dceb099dcca2eb30b663c0f8f1767e8e68343b (diff) | |
download | punchingbag-68c2bc40f25810ce01bdebcd3bfe90b7a76b5413.tar punchingbag-68c2bc40f25810ce01bdebcd3bfe90b7a76b5413.tar.gz |
Merge branch 'master' of git://gitorious.org/punchingbag/punchingbag
Conflicts:
PunchingBag/.classpath
PunchingBag/bin/PunchingBag$Colour.class
PunchingBag/bin/PunchingBag.class
PunchingBag/bin/PunchingBagGUI$Ripple.class
PunchingBag/bin/PunchingBagGUI.class
PunchingBag/src/Arduino.java
PunchingBag/src/PunchingBag.java
PunchingBag/src/PunchingBagGUI.java
Diffstat (limited to 'PunchingBag/src/PunchingBag.java')
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 7629afe..b8cbfce 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -1,12 +1,23 @@ import javax.swing.event.EventListenerList; +import java.util.Arrays; -public class PunchingBag { - protected EventListenerList listenerList = new 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. * @@ -86,4 +97,65 @@ matrix. Clear ( ) ; matrix. DrawEllipse ( AS1107:: Maxx / x , y ,i,i ) ; matrix. Update ( ) ; delay ( d ) ; + + 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; + } + + 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 setLEDGridIntensity(byte grid, byte intensity) { + ledGridIntensities[grid] = intensity; + } + + public void setLEDIntensities(byte intensity) { + Arrays.fill(ledGridIntensities, intensity); + } + + public void run() { + + } + } |