From fcd9bda1916ee874b843ae257ba9ac1a75a63c07 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 4 Sep 2011 23:13:39 +0100 Subject: Finished off the listener implementation for the moment. Allowed the debug screen to accept button presses and show leds. The Ripple still needs more work and more effects need implementing. --- PunchingBag/src/Arduino.java | 1 - PunchingBag/src/PunchingBag.java | 76 ++++++++++++++++++++++++++++--------- PunchingBag/src/PunchingBagGUI.java | 56 +++++++++++++++++---------- 3 files changed, 94 insertions(+), 39 deletions(-) diff --git a/PunchingBag/src/Arduino.java b/PunchingBag/src/Arduino.java index aeaa107..5e6e288 100644 --- a/PunchingBag/src/Arduino.java +++ b/PunchingBag/src/Arduino.java @@ -9,7 +9,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; - import gnu.io.*; public class Arduino { diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 00a5866..d09d8e6 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -13,11 +13,14 @@ public class PunchingBag implements Runnable { private byte[] rawLeds = new byte[6 * 8]; private Colour[][] leds = new Colour[ledWidth][ledHeight]; private byte[] ledGridIntensities = new byte[6]; - private boolean[][] buttons = new boolean[8][19]; + final public int buttonHeight = 19; + final public int buttonWidth = 8; + private boolean[][] buttons = new boolean[buttonWidth][buttonHeight]; + boolean buttonsChanged = false; private ArrayList runningEffects = new ArrayList(); - enum Colour { + public enum Colour { None, Red, Yellow, Green }; @@ -42,6 +45,10 @@ public class PunchingBag implements Runnable { public void addLEDChangeListener(LEDListener l) { ledListenerList.add(LEDListener.class, l); } + + public Colour getLED(int x, int y) { + return leds[x][y]; + } public boolean setLED(int x, int y, Colour colour) { if (x >= 0 && x < ledWidth && y >= 0 && y < ledHeight) { @@ -56,12 +63,11 @@ public class PunchingBag implements Runnable { } } - 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)); + void CircleExpand(int x, int y, int intensity) { + runningEffects.add(new CircleExpand(x,y,100)); } - class Effect implements Runnable { + abstract class Effect implements Runnable { boolean stop = false; int refreshRate = 60; // Times per second to refresh @@ -81,19 +87,18 @@ public class PunchingBag implements Runnable { runningEffects.remove(this); } - private void draw() { - } + abstract public void draw(); } class CircleExpand extends Effect { - final byte x; - final byte y; - byte intensity; + final int x; + final int y; + int intensity; boolean drawnSomething = true; float currentRadius = 0; - public CircleExpand(byte x, byte y, byte intensity) { + public CircleExpand(int x, int y, int intensity) { this.x = x; this.y = y; this.intensity = intensity; @@ -110,12 +115,14 @@ public class PunchingBag implements Runnable { } else { colour = Colour.Green; } + + intensity -= 5; currentRadius += 0.1 + (currentRadius / 10); // longhand: currentRadius = currentRadius + 0.1 + (currentRadius / // 10); - if (!DrawEllipse(2, 4, (int) currentRadius, (int) currentRadius, + if (!DrawEllipse(x, y, (int) currentRadius, (int) currentRadius, colour)) stop = true; } @@ -204,11 +211,16 @@ public class PunchingBag implements Runnable { } /* Clears the led grid and stops all running effects */ - public void clearLEDGrid() { - for (Iterator iter = runningEffects.iterator(); iter.hasNext();) { + void clearLEDGrid() { + /*for (Iterator iter = runningEffects.iterator(); iter.hasNext();) { ((Effect) iter.next()).stop(); + }*/ + for (int x=0; x