diff options
Diffstat (limited to 'PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java')
-rw-r--r-- | PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java index 7f0fe06..7477f0c 100644 --- a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java +++ b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBag.java @@ -108,7 +108,7 @@ public class PunchingBag implements Runnable { * linux) */ String buttonArduinoDeviceAddress = "COM4"; // TODO: This should be cached - // localy + // localy /** * The Arduino managing the led drivers */ @@ -117,7 +117,8 @@ public class PunchingBag implements Runnable { * The device address of the led arduino (COM* on Windows, /dev/tty* on * linux) */ - String ledArduinoDeviceAddress = "COM3"; // TODO: This should be cached localy + String ledArduinoDeviceAddress = "COM3"; // TODO: This should be cached + // localy /** * Turn on to activate the command line messages regarding the run loop @@ -334,7 +335,7 @@ public class PunchingBag implements Runnable { public void noise(Rectangle rect, long time) { runningEffects.add(new Noise(rect, System.currentTimeMillis() + time)); } - + /** * @param rect * @param time @@ -359,7 +360,7 @@ public class PunchingBag implements Runnable { /** * Set when the effect should stop (use <code>stop()</code> to set). */ - private boolean stop = false; + protected boolean stop = false; /** * Used to stop the effect, removing it from the list of effects @@ -535,14 +536,16 @@ public class PunchingBag implements Runnable { this.area = area; this.endTime = endTime; } - + public Noise(Rectangle area) { this(area, (long) 0); } @Override public void draw() { - if (endTime >= System.currentTimeMillis() && endTime != 0) { + if (endTime <= System.currentTimeMillis() && endTime != 0) { + stop(); + } else { for (int y = area.y; y < (area.y + area.height); y++) { for (int x = area.x; x < (area.x + area.width); x++) { double random = Math.random(); @@ -557,8 +560,7 @@ public class PunchingBag implements Runnable { } } } - } else { - stop(); + } } } @@ -889,7 +891,8 @@ public class PunchingBag implements Runnable { /** * Processes the serial data regarding accelerations * - * @param data The data string to be processed + * @param data + * The data string to be processed */ private void readAccelData(String data) { // System.out.println("Data: " + data); @@ -928,7 +931,8 @@ public class PunchingBag implements Runnable { /** * Processes the serial data regarding buttons * - * @param data The data string to be processed + * @param data + * The data string to be processed */ private void readButtonData(String data) { // System.out.println("Data: " + data); @@ -970,13 +974,15 @@ public class PunchingBag implements Runnable { System.out.println(""); } - /* - * The run method starts a loop which processes the serial data, effects and events + /* + * The run method starts a loop which processes the serial data, effects and + * events * * @see java.lang.Runnable#run() */ public void run() { - long timeToSleep = 10; // The time slept at the end of the loop (to maintain the refresh rate) + long timeToSleep = 10; // The time slept at the end of the loop (to + // maintain the refresh rate) while (true) { if (debugTimings) { |