diff options
Diffstat (limited to 'PunchingBag')
19 files changed, 81 insertions, 63 deletions
diff --git a/PunchingBag/.classpath b/PunchingBag/.classpath deleted file mode 100644 index 4cb0e3c..0000000 --- a/PunchingBag/.classpath +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> - <classpathentry kind="lib" path="C:/Documents and Settings/am29567/punchingbag/PunchingBag/RXTXcomm.jar"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/PunchingBag/bin/ButtonArduino.class b/PunchingBag/bin/ButtonArduino.class Binary files differdeleted file mode 100644 index 0dd56f5..0000000 --- a/PunchingBag/bin/ButtonArduino.class +++ /dev/null diff --git a/PunchingBag/bin/ButtonListener.class b/PunchingBag/bin/ButtonListener.class Binary files differdeleted file mode 100644 index acd177b..0000000 --- a/PunchingBag/bin/ButtonListener.class +++ /dev/null diff --git a/PunchingBag/bin/Contact.class b/PunchingBag/bin/Contact.class Binary files differdeleted file mode 100644 index 2e6fbc5..0000000 --- a/PunchingBag/bin/Contact.class +++ /dev/null diff --git a/PunchingBag/bin/PunchingBag$Colour.class b/PunchingBag/bin/PunchingBag$Colour.class Binary files differdeleted file mode 100644 index 75ff538..0000000 --- a/PunchingBag/bin/PunchingBag$Colour.class +++ /dev/null diff --git a/PunchingBag/bin/PunchingBag$Ripple.class b/PunchingBag/bin/PunchingBag$Ripple.class Binary files differdeleted file mode 100644 index 3988003..0000000 --- a/PunchingBag/bin/PunchingBag$Ripple.class +++ /dev/null diff --git a/PunchingBag/bin/PunchingBag.class b/PunchingBag/bin/PunchingBag.class Binary files differdeleted file mode 100644 index e8616d9..0000000 --- a/PunchingBag/bin/PunchingBag.class +++ /dev/null diff --git a/PunchingBag/bin/PunchingBagGUI$Direction.class b/PunchingBag/bin/PunchingBagGUI$Direction.class Binary files differdeleted file mode 100644 index 654a7b0..0000000 --- a/PunchingBag/bin/PunchingBagGUI$Direction.class +++ /dev/null diff --git a/PunchingBag/bin/PunchingBagGUI$Mode.class b/PunchingBag/bin/PunchingBagGUI$Mode.class Binary files differdeleted file mode 100644 index 1b33757..0000000 --- a/PunchingBag/bin/PunchingBagGUI$Mode.class +++ /dev/null diff --git a/PunchingBag/bin/PunchingBagGUI$Ripple.class b/PunchingBag/bin/PunchingBagGUI$Ripple.class Binary files differdeleted file mode 100644 index 491ecf3..0000000 --- a/PunchingBag/bin/PunchingBagGUI$Ripple.class +++ /dev/null diff --git a/PunchingBag/bin/PunchingBagGUI.class b/PunchingBag/bin/PunchingBagGUI.class Binary files differdeleted file mode 100644 index fb8d093..0000000 --- a/PunchingBag/bin/PunchingBagGUI.class +++ /dev/null diff --git a/PunchingBag/bin/SlaveArduino$Colour.class b/PunchingBag/bin/SlaveArduino$Colour.class Binary files differdeleted file mode 100644 index b70919a..0000000 --- a/PunchingBag/bin/SlaveArduino$Colour.class +++ /dev/null diff --git a/PunchingBag/bin/SlaveArduino$SerialReader.class b/PunchingBag/bin/SlaveArduino$SerialReader.class Binary files differdeleted file mode 100644 index 52b0fda..0000000 --- a/PunchingBag/bin/SlaveArduino$SerialReader.class +++ /dev/null diff --git a/PunchingBag/bin/SlaveArduino$SerialWriter.class b/PunchingBag/bin/SlaveArduino$SerialWriter.class Binary files differdeleted file mode 100644 index a313e5f..0000000 --- a/PunchingBag/bin/SlaveArduino$SerialWriter.class +++ /dev/null diff --git a/PunchingBag/bin/SlaveArduino.class b/PunchingBag/bin/SlaveArduino.class Binary files differdeleted file mode 100644 index 8d24c5a..0000000 --- a/PunchingBag/bin/SlaveArduino.class +++ /dev/null diff --git a/PunchingBag/src/SlaveArduino.java b/PunchingBag/src/Arduino.java index e3016c5..aeaa107 100644 --- a/PunchingBag/src/SlaveArduino.java +++ b/PunchingBag/src/Arduino.java @@ -5,7 +5,6 @@ import gnu.io.CommPort; import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
-import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -13,17 +12,7 @@ import java.io.OutputStream; import gnu.io.*;
-public class SlaveArduino {
-
- enum Colour {None, Red, Yellow, Green};
-
- static Colour[][] LED = new Colour[9][20];
-
- public static void setLED(Colour colour, int x, int y) {
- if (x < 0 || x > 8 || y < 0 || y > 19) return;
- LED[x][y] = colour;
- }
-
+public class Arduino {
static void listPorts()
{
diff --git a/PunchingBag/src/ButtonArduino.java b/PunchingBag/src/ButtonArduino.java index 415f370..b56a9ed 100644 --- a/PunchingBag/src/ButtonArduino.java +++ b/PunchingBag/src/ButtonArduino.java @@ -1,5 +1,9 @@ -public class ButtonArduino {
- public boolean[][] buttons = new boolean[4][7];
+public class ButtonArduino extends Arduino {
+
+ void setButtons(boolean[][] buttons) {
+
+
+ }
}
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 7629afe..b8cbfce 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -1,12 +1,23 @@ import javax.swing.event.EventListenerList; +import java.util.Arrays; -public class PunchingBag { - protected EventListenerList listenerList = new EventListenerList(); +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]; enum Colour { None, Red, Yellow, Green }; + private EventListenerList buttonListenerList = new EventListenerList(); + private EventListenerList ledListenerList = new EventListenerList(); + + public PunchingBag() { + new Thread(this).start(); + } + /** * Adds an <code>ActionListener</code> to the button. * @@ -86,4 +97,65 @@ matrix. Clear ( ) ; matrix. DrawEllipse ( AS1107:: Maxx / x , y ,i,i ) ; matrix. Update ( ) ; delay ( d ) ; + + buttonListenerList.add(ButtonListener.class, l); + } + + public void addLEDChangeListener(ButtonListener l) { + ledListenerList.add(ButtonListener.class, l); + } + + public void setLED(byte x, byte y, Colour colour) { + leds[x][y] = colour; + } + + private void calculateRawLeds() { + for (int y = 0; y <= 18; y++) { + for (int x = 0; x <= 6; x++) { + if ((y % 2) == 0) { + if (leds[x][y] == Colour.Green + || leds[x][y] == Colour.Yellow) { + rawLeds[(int) Math.floor(y / 4)] = (byte) (rawLeds[(int) Math + .floor(y / 4)] | (1 << (7 - x))); + } + } else { + if (leds[x][y] == Colour.Red || leds[x][y] == Colour.Yellow) { + rawLeds[(int) Math.floor(y / 4)] = (byte) (rawLeds[(int) Math + .floor(y / 4)] | (1 << (7 - x))); + } + } + } + } + int x = 7; + // TODO: Complete and test, or rethink the following? + for (int startY = 0; startY <= 4; startY++) { + for (int y = 0; y <= 3; y++) { + if (leds[x][startY + (y * 4)] == Colour.Red || leds[x][startY + (y * 4)] == Colour.Yellow) { + rawLeds[(5 * 8) + startY] = (byte) (rawLeds[(int) Math + .floor(y / 4)] | (1 << (7 - x))); + } + if (leds[x][y] == Colour.Green || leds[x][y] == Colour.Yellow) { + rawLeds[(int) Math.floor(y / 4)] = (byte) (rawLeds[(int) Math + .floor(y / 4)] | (1 << (7 - x))); + } + } + } + } + + public void clearLEDGrid() { + Arrays.fill(leds, Boolean.FALSE); + } + + public void setLEDGridIntensity(byte grid, byte intensity) { + ledGridIntensities[grid] = intensity; + } + + public void setLEDIntensities(byte intensity) { + Arrays.fill(ledGridIntensities, intensity); + } + + public void run() { + + } + } diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java index 180beed..d7f4f9a 100644 --- a/PunchingBag/src/PunchingBagGUI.java +++ b/PunchingBag/src/PunchingBagGUI.java @@ -70,47 +70,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto }
public void runInteractively(Contact contact) {
- bagSimFrame.add(new Ripple(contact));
- }
-
- class Ripple extends JPanel {
- // TODO Make this not shit.
- final Contact contact;
- double currentWidth;
-
- Ripple(Contact contact) {
- super();
- this.contact = contact;
- }
-
- public void paintComponent(Graphics g) {
- // Max size of ripple is 60cm
- // Ripple will expand 60cm * strength/100
-
- SlaveArduino.Colour colour = SlaveArduino.Colour.Red;
- g.setColor(new Color(255, 0, 0, 255));
- boolean drawnSomething = false;
- for (double i = 0; i < 360; i++) {
- int x = contact.x
- + (int) Math.round(currentWidth * Math.cos(i));
- int y = contact.y
- + (int) Math.round(currentWidth * Math.sin(i));
-
- if (x >= 0 && x <= 8 && y >= 0 && y <= 19) {
- SlaveArduino.setLED(colour, x, y);
- drawnSomething =true;
- }
-
- if (useDebugScreen) {
- g.fillOval(40 * x, 40 * y, 6, 6);
-
- }
- }
- if (!drawnSomething) bagSimFrame.remove(this);
-
- currentWidth += 0.1 + (currentWidth/10) + (contact.strength/130) ;
- }
}
|