diff options
author | Adam Martindale <awiamartindale@googlemail.com> | 2011-09-07 11:31:02 +0100 |
---|---|---|
committer | Adam Martindale <awiamartindale@googlemail.com> | 2011-09-07 11:31:02 +0100 |
commit | cd0fdd04f3108f61482919309b2a2da5c33f6872 (patch) | |
tree | 99710b299a02fa58382df101766892c0c3b679a7 /PunchingBag/src/PunchingBag.java | |
parent | dc16d95ed5a4b5f15f327cbe609414dc9e5d6225 (diff) | |
parent | ba3448fb8093afd9d298cef1123a1bedfea13999 (diff) | |
download | punchingbag-cd0fdd04f3108f61482919309b2a2da5c33f6872.tar punchingbag-cd0fdd04f3108f61482919309b2a2da5c33f6872.tar.gz |
Merge branch 'master' of gitorious.org:punchingbag/punchingbag
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 d6eca55..bcaf220 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -20,6 +20,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 @@ -32,6 +34,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(); @@ -50,6 +54,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]; @@ -75,7 +83,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; @@ -254,16 +263,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(); } |