From fca8c8c1f8b0dc2febd1b1cfba6ffc4ab46da026 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 2 Sep 2011 17:17:55 +0100 Subject: Inproved, but not yet completed listener system. --- PunchingBag/src/PunchingBag.java | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 8408225..8ea984e 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -7,17 +7,19 @@ import java.util.Iterator; // TODO: Loads of threads in this class, make sure everything is thread safe. public class PunchingBag implements Runnable { + boolean ledsChanged = false; 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]; - + private ArrayList runningEffects = new ArrayList(); enum Colour { None, Red, Yellow, Green }; + // Is there a better class for this? One that it is not a swing class. private EventListenerList buttonListenerList = new EventListenerList(); private EventListenerList ledListenerList = new EventListenerList(); @@ -40,12 +42,15 @@ public class PunchingBag implements Runnable { } public void setLED(int i, int j, Colour colour) { - leds[i][j] = colour; + if (leds[i][j] != colour) { + ledsChanged = true; + leds[i][j] = colour; + } } void CircleExpand(int x, int y, int delay, Colour colour) { // TODO: Adam correct CircleExpand constructor, or this method? - //runningEffects.add(new CircleExpand(x,y,delay,colour)); + // runningEffects.add(new CircleExpand(x,y,delay,colour)); } class Effect implements Runnable { @@ -187,7 +192,7 @@ public class PunchingBag implements Runnable { /* Clears the led grid and stops all running effects */ public void clearLEDGrid() { - for (Iterator iter = runningEffects.iterator(); iter.hasNext(); ) { + for (Iterator iter = runningEffects.iterator(); iter.hasNext();) { ((Effect) iter.next()).stop(); } Arrays.fill(leds, Boolean.FALSE); @@ -196,13 +201,24 @@ public class PunchingBag implements Runnable { public void setLEDGridIntensity(byte grid, byte intensity) { ledGridIntensities[grid] = intensity; } - + public void setLEDIntensities(byte intensity) { Arrays.fill(ledGridIntensities, intensity); } public void run() { + while (true) { + if (ledsChanged) { + LEDListeners = + ledListenerList. + } + try { + Thread.sleep(1000 / 120); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } } -- cgit v1.2.3