aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--PunchingBag/src/PunchingBag.java31
1 files changed, 17 insertions, 14 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
index f141c26..8408225 100644
--- a/PunchingBag/src/PunchingBag.java
+++ b/PunchingBag/src/PunchingBag.java
@@ -1,11 +1,18 @@
import javax.swing.event.EventListenerList;
+
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
+
+// TODO: Loads of threads in this class, make sure everything is thread safe.
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];
+
+ private ArrayList<Effect> runningEffects = new ArrayList<Effect>();
enum Colour {
None, Red, Yellow, Green
@@ -37,10 +44,8 @@ public class PunchingBag implements Runnable {
}
void CircleExpand(int x, int y, int delay, Colour colour) {
- for (int i = 0; i <= 15; i++) {
- DrawEllipse(x, y, i, i, colour);
-
- }
+ // TODO: Adam correct CircleExpand constructor, or this method?
+ //runningEffects.add(new CircleExpand(x,y,delay,colour));
}
class Effect implements Runnable {
@@ -60,10 +65,10 @@ public class PunchingBag implements Runnable {
e.printStackTrace();
}
}
+ runningEffects.remove(this);
}
private void draw() {
-
}
}
@@ -105,16 +110,10 @@ public class PunchingBag implements Runnable {
}
- if (!drawnSomething)
- stop = true;
-
currentWidth += 0.1 + (currentWidth / 10);
- try {
- Thread.sleep(1000 / 60);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ if (!drawnSomething)
+ stop = true;
}
}
@@ -186,14 +185,18 @@ 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(); ) {
+ ((Effect) iter.next()).stop();
+ }
Arrays.fill(leds, Boolean.FALSE);
}
public void setLEDGridIntensity(byte grid, byte intensity) {
ledGridIntensities[grid] = intensity;
}
-
+
public void setLEDIntensities(byte intensity) {
Arrays.fill(ledGridIntensities, intensity);
}