aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag
diff options
context:
space:
mode:
Diffstat (limited to 'PunchingBag')
-rw-r--r--PunchingBag/.classpath7
-rw-r--r--PunchingBag/bin/Arduino$SerialReader.classbin998 -> 0 bytes
-rw-r--r--PunchingBag/bin/Arduino$SerialWriter.classbin897 -> 0 bytes
-rw-r--r--PunchingBag/bin/Arduino.classbin3875 -> 0 bytes
-rw-r--r--PunchingBag/bin/ButtonArduino.classbin360 -> 0 bytes
-rw-r--r--PunchingBag/bin/ButtonListener.classbin173 -> 0 bytes
-rw-r--r--PunchingBag/bin/Contact.classbin444 -> 0 bytes
-rw-r--r--PunchingBag/bin/PunchingBag$Colour.classbin1102 -> 0 bytes
-rw-r--r--PunchingBag/bin/PunchingBag.classbin2643 -> 0 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI$Direction.classbin1191 -> 0 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI$Mode.classbin1070 -> 0 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI.classbin3447 -> 0 bytes
-rw-r--r--PunchingBag/src/Arduino.java316
-rw-r--r--PunchingBag/src/PunchingBag.java76
-rw-r--r--PunchingBag/src/PunchingBagGUI.java1
15 files changed, 234 insertions, 166 deletions
diff --git a/PunchingBag/.classpath b/PunchingBag/.classpath
deleted file mode 100644
index 2c8ecc4..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/Christopher/My Documents/OUPunchingBag/punchingbag/PunchingBag/RXTXcomm.jar"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/PunchingBag/bin/Arduino$SerialReader.class b/PunchingBag/bin/Arduino$SerialReader.class
deleted file mode 100644
index 8b8c133..0000000
--- a/PunchingBag/bin/Arduino$SerialReader.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/Arduino$SerialWriter.class b/PunchingBag/bin/Arduino$SerialWriter.class
deleted file mode 100644
index 310f84c..0000000
--- a/PunchingBag/bin/Arduino$SerialWriter.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/Arduino.class b/PunchingBag/bin/Arduino.class
deleted file mode 100644
index 7e81456..0000000
--- a/PunchingBag/bin/Arduino.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/ButtonArduino.class b/PunchingBag/bin/ButtonArduino.class
deleted file mode 100644
index 77269cb..0000000
--- a/PunchingBag/bin/ButtonArduino.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/ButtonListener.class b/PunchingBag/bin/ButtonListener.class
deleted file mode 100644
index acd177b..0000000
--- a/PunchingBag/bin/ButtonListener.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/Contact.class b/PunchingBag/bin/Contact.class
deleted file mode 100644
index 2e6fbc5..0000000
--- a/PunchingBag/bin/Contact.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/PunchingBag$Colour.class b/PunchingBag/bin/PunchingBag$Colour.class
deleted file mode 100644
index 8524f32..0000000
--- a/PunchingBag/bin/PunchingBag$Colour.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/PunchingBag.class b/PunchingBag/bin/PunchingBag.class
deleted file mode 100644
index aa67aa2..0000000
--- a/PunchingBag/bin/PunchingBag.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI$Direction.class b/PunchingBag/bin/PunchingBagGUI$Direction.class
deleted file mode 100644
index 654a7b0..0000000
--- a/PunchingBag/bin/PunchingBagGUI$Direction.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI$Mode.class b/PunchingBag/bin/PunchingBagGUI$Mode.class
deleted file mode 100644
index 1b33757..0000000
--- a/PunchingBag/bin/PunchingBagGUI$Mode.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI.class b/PunchingBag/bin/PunchingBagGUI.class
deleted file mode 100644
index 23fe615..0000000
--- a/PunchingBag/bin/PunchingBagGUI.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/src/Arduino.java b/PunchingBag/src/Arduino.java
index 70ac608..aeaa107 100644
--- a/PunchingBag/src/Arduino.java
+++ b/PunchingBag/src/Arduino.java
@@ -1,158 +1,158 @@
-import java.util.Enumeration;
-import java.util.HashSet;
-
-import gnu.io.CommPort;
-import gnu.io.CommPortIdentifier;
-import gnu.io.SerialPort;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-
-import gnu.io.*;
-
-public class Arduino {
-
- static void listPorts()
- {
- System.out.println("Listing Comm ports:");
- java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
- while ( portEnum.hasMoreElements() )
- {
- CommPortIdentifier portIdentifier = portEnum.nextElement();
- System.out.println(portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType()) );
- }
- }
-
- static String getPortTypeName ( int portType )
- {
- switch ( portType )
- {
- case CommPortIdentifier.PORT_I2C:
- return "I2C";
- case CommPortIdentifier.PORT_PARALLEL:
- return "Parallel";
- case CommPortIdentifier.PORT_RAW:
- return "Raw";
- case CommPortIdentifier.PORT_RS485:
- return "RS485";
- case CommPortIdentifier.PORT_SERIAL:
- return "Serial";
- default:
- return "unknown type";
- }
- }
-
- /**
- * @return A HashSet containing the CommPortIdentifier for all serial ports that are not currently being used.
- */
- public static HashSet<CommPortIdentifier> getAvailableSerialPorts() {
- HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>();
- Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
- while (thePorts.hasMoreElements()) {
- CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
- switch (com.getPortType()) {
- case CommPortIdentifier.PORT_SERIAL:
- try {
- CommPort thePort = com.open("CommUtil", 50);
- thePort.close();
- h.add(com);
- System.out.println("Found a port: " + com.getPortType());
- } catch (PortInUseException e) {
- System.out.println("Port, " + com.getName() + ", is in use.");
- } catch (Exception e) {
- System.err.println("Failed to open port " + com.getName());
- e.printStackTrace();
- }
- }
- }
- return h;
- }
-
- void connect ( String portName ) throws Exception
- {
- CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
- if ( portIdentifier.isCurrentlyOwned() )
- {
- System.out.println("Error: Port is currently in use");
- }
- else
- {
- CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
-
- if ( commPort instanceof SerialPort )
- {
- SerialPort serialPort = (SerialPort) commPort;
- serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
-
- InputStream in = serialPort.getInputStream();
- OutputStream out = serialPort.getOutputStream();
-
- (new Thread(new SerialReader(in))).start();
- (new Thread(new SerialWriter(out))).start();
-
- }
- else
- {
- System.out.println("Error: Only serial ports are handled by this example.");
- }
- }
- }
-
- /** */
- public static class SerialReader implements Runnable
- {
- InputStream in;
-
- public SerialReader ( InputStream in )
- {
- this.in = in;
- }
-
- 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));
- }
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- }
- }
- }
-
- /** */
- public static class SerialWriter implements Runnable
- {
- OutputStream out;
-
- public SerialWriter ( OutputStream out )
- {
- this.out = out;
- }
-
- public void run ()
- {
- try
- {
- int c = 0;
- while ( ( c = System.in.read()) > -1 )
- {
- this.out.write(c);
- }
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- }
- }
- }
-
-}
+import java.util.Enumeration;
+import java.util.HashSet;
+
+import gnu.io.CommPort;
+import gnu.io.CommPortIdentifier;
+import gnu.io.SerialPort;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+
+import gnu.io.*;
+
+public class Arduino {
+
+ static void listPorts()
+ {
+ System.out.println("Listing Comm ports:");
+ java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
+ while ( portEnum.hasMoreElements() )
+ {
+ CommPortIdentifier portIdentifier = portEnum.nextElement();
+ System.out.println(portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType()) );
+ }
+ }
+
+ static String getPortTypeName ( int portType )
+ {
+ switch ( portType )
+ {
+ case CommPortIdentifier.PORT_I2C:
+ return "I2C";
+ case CommPortIdentifier.PORT_PARALLEL:
+ return "Parallel";
+ case CommPortIdentifier.PORT_RAW:
+ return "Raw";
+ case CommPortIdentifier.PORT_RS485:
+ return "RS485";
+ case CommPortIdentifier.PORT_SERIAL:
+ return "Serial";
+ default:
+ return "unknown type";
+ }
+ }
+
+ /**
+ * @return A HashSet containing the CommPortIdentifier for all serial ports that are not currently being used.
+ */
+ public static HashSet<CommPortIdentifier> getAvailableSerialPorts() {
+ HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>();
+ Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
+ while (thePorts.hasMoreElements()) {
+ CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
+ switch (com.getPortType()) {
+ case CommPortIdentifier.PORT_SERIAL:
+ try {
+ CommPort thePort = com.open("CommUtil", 50);
+ thePort.close();
+ h.add(com);
+ System.out.println("Found a port: " + com.getPortType());
+ } catch (PortInUseException e) {
+ System.out.println("Port, " + com.getName() + ", is in use.");
+ } catch (Exception e) {
+ System.err.println("Failed to open port " + com.getName());
+ e.printStackTrace();
+ }
+ }
+ }
+ return h;
+ }
+
+ void connect ( String portName ) throws Exception
+ {
+ CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
+ if ( portIdentifier.isCurrentlyOwned() )
+ {
+ System.out.println("Error: Port is currently in use");
+ }
+ else
+ {
+ CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
+
+ if ( commPort instanceof SerialPort )
+ {
+ SerialPort serialPort = (SerialPort) commPort;
+ serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
+
+ InputStream in = serialPort.getInputStream();
+ OutputStream out = serialPort.getOutputStream();
+
+ (new Thread(new SerialReader(in))).start();
+ (new Thread(new SerialWriter(out))).start();
+
+ }
+ else
+ {
+ System.out.println("Error: Only serial ports are handled by this example.");
+ }
+ }
+ }
+
+ /** */
+ public static class SerialReader implements Runnable
+ {
+ InputStream in;
+
+ public SerialReader ( InputStream in )
+ {
+ this.in = in;
+ }
+
+ 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));
+ }
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /** */
+ public static class SerialWriter implements Runnable
+ {
+ OutputStream out;
+
+ public SerialWriter ( OutputStream out )
+ {
+ this.out = out;
+ }
+
+ public void run ()
+ {
+ try
+ {
+ int c = 0;
+ while ( ( c = System.in.read()) > -1 )
+ {
+ this.out.write(c);
+ }
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
index 69d9fd0..b8cbfce 100644
--- a/PunchingBag/src/PunchingBag.java
+++ b/PunchingBag/src/PunchingBag.java
@@ -1,5 +1,5 @@
-import java.util.Arrays;
import javax.swing.event.EventListenerList;
+import java.util.Arrays;
public class PunchingBag implements Runnable {
private byte[] rawLeds = new byte[6*8];
@@ -25,6 +25,79 @@ public class PunchingBag implements Runnable {
* the <code>ActionListener</code> to be added
*/
public void addButtonListener(ButtonListener l) {
+ listenerList.add(ButtonListener.class, l);
+ }
+
+ public void setLED(byte x, byte y, byte intensity) {
+
+ }
+
+ public void drawRipple(byte x, byte y, byte intensity) {
+ new Ripple(x, y, intensity);
+ }
+
+ class Ripple implements Runnable {
+ double currentWidth;
+ final byte x;
+ final byte y;
+ byte intensity;
+
+ public Ripple(byte x, byte y, byte intensity) {
+ this.x = x;
+ this.y = y;
+ this.intensity = intensity;
+ new Thread(this).start();
+ }
+
+ @Override
+ public void run() {
+ Colour colour;
+ boolean drawnSomething = true;
+
+ while (drawnSomething) {
+
+ if (intensity >= 10) {
+ colour = Colour.Red;
+ } else if (intensity >= 5) {
+ colour = Colour.Yellow;
+ } else {
+ colour = Colour.Green;
+ }
+
+ drawnSomething = false;
+
+ for (double i = 0; i < 360; i++) {
+ int x = x + (int) Math.round(currentWidth * Math.cos(i));
+ int y = y + (int) Math.round(currentWidth * Math.sin(i));
+
+ if (x >= 0 && x <= 8 && y >= 0 && y <= 19) {
+ // setLED(x, y, colour);
+ drawnSomething = true;
+ }
+
+ }
+
+ currentWidth += 0.1 + (currentWidth / 10);
+ try {
+ Thread.sleep(1000/60);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+}
+
+void CirclePulsate (int x, int y)
+{
+for ( int i= 0 ; i<= 15 ; i++ ) {
+matrix. Clear ( ) ;
+matrix. DrawEllipse ( AS1107:: Maxx / x , y ,i,i ) ;
+matrix. Update ( ) ;
+delay ( d ) ;
+
buttonListenerList.add(ButtonListener.class, l);
}
@@ -84,4 +157,5 @@ public class PunchingBag implements Runnable {
public void run() {
}
+
}
diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java
index c3014ac..d7f4f9a 100644
--- a/PunchingBag/src/PunchingBagGUI.java
+++ b/PunchingBag/src/PunchingBagGUI.java
@@ -73,6 +73,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto
}
+
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub