aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--PunchingBag/src/PunchingBag.java26
1 files 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<Effect> runningEffects = new ArrayList<Effect>();
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<Effect> iter = runningEffects.iterator(); iter.hasNext(); ) {
+ for (Iterator<Effect> 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();
+ }
+ }
}
}