diff options
Diffstat (limited to 'PunchingBag/src/PunchingBag.java')
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index b36f562..0f08276 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -19,6 +19,8 @@ public class PunchingBag implements Runnable { boolean buttonsChanged = false; private ArrayList<Effect> runningEffects = new ArrayList<Effect>(); + + ButtonArduino buttonArduino = new ButtonArduino(); public enum Colour { None, Red, Yellow, Green @@ -27,6 +29,8 @@ public class PunchingBag implements Runnable { // 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(); + private EventListenerList accelListenerList = new EventListenerList(); + public PunchingBag() { new Thread(this).start(); @@ -45,6 +49,10 @@ public class PunchingBag implements Runnable { public void addLEDChangeListener(LEDListener l) { ledListenerList.add(LEDListener.class, l); } + + public void addLEDChangeListener(AccelListener l) { + accelListenerList.add(AccelListener.class, l); + } public Colour getLED(int x, int y) { return leds[x][y]; @@ -70,7 +78,8 @@ public class PunchingBag implements Runnable { abstract class Effect { long lastRefresh = 0; boolean stop = false; - int refreshRate = 60; // Times per second to refresh + + // int refreshRate = 60; // Times per second to refresh public void stop() { stop = true; @@ -229,16 +238,16 @@ public class PunchingBag implements Runnable { public void run() { while (true) { synchronized (runningEffects) { // Should prevent - // ConcurrentModificationException's - // (havent managed to produce one - // though + // ConcurrentModificationException's + // (havent managed to produce one + // though for (Iterator<Effect> iter = runningEffects.iterator(); iter .hasNext();) { Effect ef = (Effect) iter.next(); if (ef.stop) { iter.remove(); - } else if ((ef.lastRefresh + (1000 / ef.refreshRate)) <= System - .currentTimeMillis()) { + } else {// if ((ef.lastRefresh + (1000 / ef.refreshRate)) <= + // Systems.currentTimeMillis()) { ef.draw(); ef.lastRefresh = System.currentTimeMillis(); } |