From b96fb8f5d5ba51cc62055fc115231c66ed9eedfb Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 13 Sep 2011 12:13:25 +0100 Subject: Fixed the button array, also added some timing stuff, going to now up the serial data rate. --- PunchingBag/src/PunchingBag.java | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'PunchingBag') diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 271ef60..723d373 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -35,6 +35,8 @@ public class PunchingBag implements Runnable { int topAccelY = 0; boolean acccelChanged = false; + private long lastRefresh = 0; + private ArrayList runningEffects = new ArrayList(); Arduino buttonArduino = new Arduino(); @@ -166,7 +168,6 @@ public class PunchingBag implements Runnable { double currentRadius = 0.5; public CircleExpand(int x, int y, int intensity) { - System.out.println("Circle Expand"); this.x = x + 0.5; this.y = y + 0.5; this.intensity = intensity; @@ -185,7 +186,7 @@ public class PunchingBag implements Runnable { intensity -= 5; - currentRadius += 0.2 + (currentRadius / 20); + currentRadius += 0.4 + (currentRadius / 20); // currentRadius += 0.01; // longhand: currentRadius = currentRadius + 0.1 + (currentRadius / // 10); @@ -558,11 +559,12 @@ public class PunchingBag implements Runnable { private void readButtonData(String data) { if (data.replaceAll("[^0-9]", "").length() > 0) { - // System.out.print(data + " length " + data.replaceAll("[^0-9]", - // "").length()); + // System.out.print(data); int num = Integer.valueOf(data.replaceAll("[^0-9]", "")); - int x = (num % 8) - 1; - int y = num / 8; + int x = (num % 9); + if (num != 0) + x--; + int y = num / 9; // System.out.println("X: " + x + " Y: " + y); buttons[x][y] = true; buttonsChanged = true; @@ -590,12 +592,26 @@ public class PunchingBag implements Runnable { } public void run() { + long timeToSleep = 0; + while (true) { + System.out.println("Time since last refresh: " + + (System.currentTimeMillis() - lastRefresh)); + if (timeToSleep > 0) { + if ((System.currentTimeMillis() - lastRefresh) > (1000 / 60)) { + timeToSleep--; + } else { + timeToSleep++; + } + } + System.out.println("Sleeping: " + timeToSleep); + lastRefresh = System.currentTimeMillis(); + // System.out.println("R"); synchronized (leds) { clearLEDGrid(); // clearButtonGrid(); - + long beginTimeForEffects = System.currentTimeMillis(); synchronized (runningEffects) { // Should prevent // ConcurrentModificationException's // (havent managed to produce one @@ -613,8 +629,10 @@ public class PunchingBag implements Runnable { } } } + System.out.println("Effects: " + (System.currentTimeMillis() - beginTimeForEffects)); } + long beginTimeButtonIn = System.currentTimeMillis(); if (buttonArduino.in != null) { try { int read; @@ -655,6 +673,8 @@ public class PunchingBag implements Runnable { e.printStackTrace(); } } + System.out.println("Button: " + (System.currentTimeMillis() - beginTimeButtonIn)); + calculateRawLeds(); String str; for (int i = 0; i < (6 * 8); i++) { -- cgit v1.2.3