aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2011-09-07 09:44:04 +0100
committerChristopher Baines <cbaines8@gmail.com>2011-09-07 09:44:04 +0100
commitba3448fb8093afd9d298cef1123a1bedfea13999 (patch)
treedc4ea674c977a5e76789146aa0de62e758078b9f /PunchingBag
parentcfa29ad09cc9974a0a55e5b25bcc5f59a71d5950 (diff)
downloadpunchingbag-ba3448fb8093afd9d298cef1123a1bedfea13999.tar
punchingbag-ba3448fb8093afd9d298cef1123a1bedfea13999.tar.gz
Added LEDMatrix.pde, this should be used to test the first matrix only! (at the moment). Also added font, this can be used only with java 1.70 and an eclipse maintantice build?
Diffstat (limited to 'PunchingBag')
-rw-r--r--PunchingBag/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--PunchingBag/src/AccelListener.java7
-rw-r--r--PunchingBag/src/Arduino.java42
-rw-r--r--PunchingBag/src/Font.java374
-rw-r--r--PunchingBag/src/PunchingBag.java21
-rw-r--r--PunchingBag/src/PunchingBagGUI.java4
6 files changed, 436 insertions, 20 deletions
diff --git a/PunchingBag/.settings/org.eclipse.jdt.core.prefs b/PunchingBag/.settings/org.eclipse.jdt.core.prefs
index 9fd8280..394e4df 100644
--- a/PunchingBag/.settings/org.eclipse.jdt.core.prefs
+++ b/PunchingBag/.settings/org.eclipse.jdt.core.prefs
@@ -1,12 +1,12 @@
-#Wed Jul 13 14:12:05 BST 2011
+#Tue Sep 06 14:26:41 BST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/PunchingBag/src/AccelListener.java b/PunchingBag/src/AccelListener.java
new file mode 100644
index 0000000..a3ad465
--- /dev/null
+++ b/PunchingBag/src/AccelListener.java
@@ -0,0 +1,7 @@
+import java.util.EventListener;
+
+interface AccelListener extends EventListener {
+
+ void AccelChanged();
+
+}
diff --git a/PunchingBag/src/Arduino.java b/PunchingBag/src/Arduino.java
index 5e6e288..f76bcf6 100644
--- a/PunchingBag/src/Arduino.java
+++ b/PunchingBag/src/Arduino.java
@@ -11,7 +11,10 @@ import java.io.OutputStream;
import gnu.io.*;
-public class Arduino {
+public class Arduino implements Runnable {
+
+ InputStream in;
+ OutputStream out;
static void listPorts()
{
@@ -85,12 +88,10 @@ public class Arduino {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
- InputStream in = serialPort.getInputStream();
- OutputStream out = serialPort.getOutputStream();
+ in = serialPort.getInputStream();
+ out = serialPort.getOutputStream();
- (new Thread(new SerialReader(in))).start();
- (new Thread(new SerialWriter(out))).start();
-
+ (new Thread(this)).start();
}
else
{
@@ -100,7 +101,7 @@ public class Arduino {
}
/** */
- public static class SerialReader implements Runnable
+ public class SerialReader implements Runnable
{
InputStream in;
@@ -118,6 +119,7 @@ public class Arduino {
while ( ( len = this.in.read(buffer)) > -1 )
{
System.out.print(new String(buffer,0,len));
+ input(new String(buffer,0,len));
}
}
catch ( IOException e )
@@ -126,9 +128,13 @@ public class Arduino {
}
}
}
+
+ public static void input(String string) {
+
+ }
/** */
- public static class SerialWriter implements Runnable
+ public class SerialWriter implements Runnable
{
OutputStream out;
@@ -154,4 +160,24 @@ public class Arduino {
}
}
+ public void run() {
+ byte[] buffer = new byte[1024];
+ int len = -1;
+ try
+ {
+ while ( ( len = this.in.read(buffer)) > -1 )
+ {
+ System.out.print(new String(buffer,0,len));
+ input(new String(buffer,0,len));
+ }
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+
+ }
+
+
+
}
diff --git a/PunchingBag/src/Font.java b/PunchingBag/src/Font.java
new file mode 100644
index 0000000..a8996bf
--- /dev/null
+++ b/PunchingBag/src/Font.java
@@ -0,0 +1,374 @@
+
+public class Font {
+ char font[] = {
+ // -------- Space
+ 0b00000000,
+ 0b00000000,
+ 0b00000000,
+ 0b00000000,
+ // -------- A
+ 0b01111110,
+ 0b10010000,
+ 0b10010000,
+ 0b01111110,
+ // -------- B
+ 0b01101100,
+ 0b10010010,
+ 0b10010010,
+ 0b11111110,
+ // -------- C
+ 0b10000010,
+ 0b10000010,
+ 0b01111100,
+ // -------- D
+ 0b00111000,
+ 0b01000100,
+ 0b10000010,
+ 0b11111110,
+ // -------- E
+ 0b10000010,
+ 0b10010010,
+ 0b11111110,
+ // -------- F
+ 0b10000000,
+ 0b10010000,
+ 0b11111110,
+ // -------- G
+ 0b01011100,
+ 0b10010010,
+ 0b10000010,
+ 0b01111100,
+ // -------- H
+ 0b11111110,
+ 0b00010000,
+ 0b00010000,
+ 0b11111110,
+ // -------- I
+ 0b10000010,
+ 0b11111110,
+ 0b10000010,
+ // -------- J
+ 0b11111100,
+ 0b00000010,
+ 0b00001100,
+ // -------- K
+ 0b10000110,
+ 0b01001000,
+ 0b00110000,
+ 0b11111110,
+ // -------- L
+ 0b00000010,
+ 0b00000010,
+ 0b11111110,
+ // -------- M
+ 0b11111110,
+ 0b01100000,
+ 0b00111100,
+ 0b01100000,
+ 0b11111110,
+ // -------- N
+ 0b11111110,
+ 0b00011000,
+ 0b01100000,
+ 0b11111110,
+ // -------- O
+ 0b01111100,
+ 0b10000010,
+ 0b10000010,
+ 0b01111100,
+ // -------- P
+ 0b01100000,
+ 0b10010000,
+ 0b10010000,
+ 0b11111110,
+ // -------- Q
+ 0b01111010,
+ 0b10000100,
+ 0b10001010,
+ 0b01111100,
+ // -------- R
+ 0b01100110,
+ 0b10011000,
+ 0b10010000,
+ 0b11111110,
+ // -------- S
+ 0b10001100,
+ 0b10010010,
+ 0b01100010,
+ // -------- T
+ 0b10000000,
+ 0b11111110,
+ 0b10000000,
+ // -------- U
+ 0b11111100,
+ 0b00000010,
+ 0b00000010,
+ 0b11111100,
+ // -------- V
+ 0b11000000,
+ 0b00111000,
+ 0b00000110,
+ 0b00111000,
+ 0b11000000,
+ // -------- W
+ 0b11111110,
+ 0b00001100,
+ 0b00111000,
+ 0b00001100,
+ 0b11111110,
+ // -------- X
+ 0b11000110,
+ 0b00111000,
+ 0b00111000,
+ 0b11000110,
+ // -------- Y
+ 0b11100000,
+ 0b00011110,
+ 0b11100000,
+ // -------- Z
+ 0b11000010,
+ 0b10110010,
+ 0b10001110,
+ // -------- Unknown character
+ 0b00111000,
+ 0b00111000,
+ 0b00111000,
+ // -------- 0
+ 0b01111100,
+ 0b10100010,
+ 0b10010010,
+ 0b01111100,
+ // -------- 1
+ 0b11111110,
+ 0b01000000,
+ // -------- 2
+ 0b01100010,
+ 0b10010010,
+ 0b10001110,
+ // -------- 3
+ 0b01101100,
+ 0b10010010,
+ 0b10000010,
+ // -------- 4
+ 0b11111110,
+ 0b00010000,
+ 0b11110000,
+ // -------- 5
+ 0b10001100,
+ 0b10010010,
+ 0b11110010,
+ // -------- 6
+ 0b01001100,
+ 0b10010010,
+ 0b10010010,
+ 0b01111100,
+ // -------- 7
+ 0b11100000,
+ 0b10011110,
+ 0b10000000,
+ // -------- 8
+ 0b01101100,
+ 0b10010010,
+ 0b10010010,
+ 0b01101100,
+ // -------- 9
+ 0b01111100,
+ 0b10010010,
+ 0b10010010,
+ 0b01100100,
+ // -------- :
+ 0b00100100,
+ // -------- ;
+ 0b00100110,
+ 0b00000001,
+ // -------- !
+ 0b01100000,
+ 0b11111010,
+ 0b01100000,
+ // -------- Heart
+ 0b01111000,
+ 0b11111100,
+ 0b11111110,
+ 0b01111111,
+ 0b11111110,
+ 0b11111100,
+ 0b01111000,
+ // -------- <
+ 0b01000100,
+ 0b00101000,
+ 0b00010000,
+ // -------- =
+ 0b00101000,
+ 0b00101000,
+ 0b00101000,
+ 0b00101000,
+ // -------- >
+ 0b00010000,
+ 0b00101000,
+ 0b01000100,
+ // -------- ?
+ 0b01100000,
+ 0b10011010,
+ 0b10000000,
+ // -------- @
+ 0b01111100,
+ 0b10000010,
+ 0b10111010,
+ 0b10100010,
+ 0b01011100,
+ // -------- (
+ 0b10000010,
+ 0b01111100,
+ // -------- )
+ 0b01111100,
+ 0b10000010,
+ // -------- *
+ 0b00101000,
+ 0b00010000,
+ 0b00101000,
+ // -------- +
+ 0b00010000,
+ 0b00010000,
+ 0b01111100,
+ 0b00010000,
+ 0b00010000,
+ // -------- ,
+ 0b00000110,
+ 0b00000001,
+ // -------- -
+ 0b00010000,
+ 0b00010000,
+ 0b00010000,
+ 0b00010000,
+ // -------- .
+ 0b00000010,
+ // -------- /
+ 0b11000000,
+ 0b00111000,
+ 0b00000110,
+ // -------- a
+ 0b00111110,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- b
+ 0b00011100,
+ 0b00100010,
+ 0b00100010,
+ 0b11111110,
+ // -------- c
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- d
+ 0b11111110,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- e
+ 0b00011000,
+ 0b00101010,
+ 0b00101010,
+ 0b00011100,
+ // -------- f
+ 0b10010000,
+ 0b01111110,
+ 0b00010000,
+ // -------- g
+ 0b00111110,
+ 0b00100101,
+ 0b00100101,
+ 0b00011000,
+ // -------- h
+ 0b00011110,
+ 0b00100000,
+ 0b00100000,
+ 0b11111110,
+ // -------- i
+ 0b00000010,
+ 0b01011110,
+ 0b00010010,
+ // -------- j
+ 0b01011110,
+ 0b00000001,
+ 0b00000001,
+ // -------- k
+ 0b00100010,
+ 0b00010100,
+ 0b00001000,
+ 0b11111110,
+ // -------- l
+ 0b00000010,
+ 0b11111100,
+ // -------- m
+ 0b00011110,
+ 0b00100000,
+ 0b00111110,
+ 0b00100000,
+ 0b00111110,
+ // -------- n
+ 0b00011110,
+ 0b00100000,
+ 0b00100000,
+ 0b00111110,
+ // -------- o
+ 0b00011100,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- p
+ 0b00011100,
+ 0b00100010,
+ 0b00100010,
+ 0b00111111,
+ // -------- q
+ 0b00111111,
+ 0b00100010,
+ 0b00100010,
+ 0b00011100,
+ // -------- r
+ 0b00010000,
+ 0b00100000,
+ 0b00111110,
+ // -------- s
+ 0b00100100,
+ 0b00101010,
+ 0b00101010,
+ 0b00010010,
+ // -------- t
+ 0b00100010,
+ 0b11111100,
+ 0b00100000,
+ // -------- u
+ 0b00111110,
+ 0b00000010,
+ 0b00000010,
+ 0b00111100,
+ // -------- v
+ 0b00111000,
+ 0b00000110,
+ 0b00111000,
+ // -------- w
+ 0b00111110,
+ 0b00000010,
+ 0b00011110,
+ 0b00000010,
+ 0b00111100,
+ // -------- x
+ 0b00110110,
+ 0b00001000,
+ 0b00110110,
+ // -------- y
+ 0b00111110,
+ 0b00000101,
+ 0b00000101,
+ 0b00111001,
+ // -------- z
+ 0b00110010,
+ 0b00101010,
+ 0b00100110,
+ 0b00100010,
+ 0b11000001
+ };
+
+}
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();
}
diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java
index 1db9d68..63f05ae 100644
--- a/PunchingBag/src/PunchingBagGUI.java
+++ b/PunchingBag/src/PunchingBagGUI.java
@@ -21,12 +21,12 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
static JFrame frame;
static JFrame bagSimFrame;
- static PunchingBag bag = new PunchingBag();
-
// Contact
public enum Direction {
None, Up, Down, Left, Right
};
+
+ PunchingBag bag = new PunchingBag();
final boolean useDebugScreen = true;