diff options
Diffstat (limited to 'PunchingBag/src/PunchingBag.java')
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index a7b7070..ef5cb18 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -8,6 +8,7 @@ import java.awt.Rectangle; import java.awt.geom.Area; import java.io.IOException; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; @@ -400,13 +401,11 @@ public class PunchingBag implements Runnable { for (int y = 0; y < 8; y++) { if ((y % 2) == 0) { if (leds[1 + x][(grid * 4) + (y/2)] == Colour.Green || leds[1 + x][(grid * 4) + (y/2)] == Colour.Yellow ) { - //System.out.println("X: " + (x+1) + " Y: " + ((grid * 4) + (y/2)) + " : Green"); - //printlnByte((byte) (1 << (8-y))); - rawLeds[(grid*8) + x] = (byte) (rawLeds[(grid*8) + x] | (1 << (8-y))); + rawLeds[(grid*8) + x] = (byte) (rawLeds[(grid*8) + x] | (1 << (7-y))); } } else { if (leds[1 + x][(grid * 4) + (y/2)] == Colour.Red || leds[1 + x][(grid * 4) + (y/2)] == Colour.Yellow ) { - rawLeds[(grid*8) + x] = (byte) (rawLeds[(grid*8) + x] | (1 << (8-y))); + rawLeds[(grid*8) + x] = (byte) (rawLeds[(grid*8) + x] | (1 << (7-y))); } } } @@ -477,6 +476,13 @@ public class PunchingBag implements Runnable { } public boolean connectToArduinos() { + try { + ledArduino.connect("COM6"); + buttonArduino.connect("COM7"); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } HashSet<CommPortIdentifier> serialPorts = Arduino .getAvailableSerialPorts(); for (Iterator iter = serialPorts.iterator(); iter.hasNext();) { @@ -487,9 +493,8 @@ public class PunchingBag implements Runnable { System.out.println(comPort.getName()); } try { - ledArduino.connect(comPort.getName()); - // System.out.println("ID: " + buttonArduino.getID()); + System.out.println(comPort.getName()); } catch (Exception e) { e.printStackTrace(); } @@ -532,9 +537,12 @@ public class PunchingBag implements Runnable { } private void printByte(byte b) { + //System.out.println("Byte: " + b); String str; for (int j = 0; j < 8; j++) { - if ((b & (1 << (8 - j))) > 0) { + byte val = (byte) (b & (1 << (7-j))); + //System.out.println("Val: " + val + " " + (1 << (7-j))); + if (val > 0) { str = "1"; } else { str = "0"; @@ -587,7 +595,7 @@ public class PunchingBag implements Runnable { // sb.append((char) read); } // System.out.println(""); - readAccelData(str); + //readAccelData(str); // String[] nums = sbString.trim().split(" "); // System.out.println(nums); // for (int x=0; x<4; x++) { @@ -615,11 +623,13 @@ public class PunchingBag implements Runnable { } } calculateRawLeds(); - /*String str; + String str; for (int i = 0; i < (6 * 8); i++) { - printByte(rawLeds[i]); + //printByte(rawLeds[i]); } - System.out.println("");*/ + //System.out.println(""); + + //Arrays.fill(rawLeds, (byte) -42); if (ledArduino.out != null) { //calculateRawLeds(); try { |