From e3b45dbd9aff927a949f79408106d19fc3ca2deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Fri, 8 Jun 2012 04:22:22 +0200 Subject: [PATCH] added disco!!!111oneeleven --- src/de/ctdo/crashtest/TestClass.java | 46 ++++++++++------- .../ctdo/crashtest/domotics/BuntiClient.java | 49 ++++++++++++++++++- .../ctdo/crashtest/domotics/IBuntiClient.java | 1 + src/de/ctdo/crashtest/game/TheGame.java | 44 ++++++++++++++++- 4 files changed, 118 insertions(+), 22 deletions(-) diff --git a/src/de/ctdo/crashtest/TestClass.java b/src/de/ctdo/crashtest/TestClass.java index 8d90799..e36b4f6 100644 --- a/src/de/ctdo/crashtest/TestClass.java +++ b/src/de/ctdo/crashtest/TestClass.java @@ -1,6 +1,7 @@ package de.ctdo.crashtest; import de.ctdo.crashtest.domotics.BuntiClient; +import de.ctdo.crashtest.domotics.IBuntiClient; import de.ctdo.crashtest.domotics.IRelaisboard; import de.ctdo.crashtest.domotics.Relaisboard; import de.ctdo.crashtest.mpd.IMPDController; @@ -14,27 +15,34 @@ public class TestClass { public static void main(String args[]) throws InterruptedException { - IRelaisboard relaisboard = new Relaisboard("/dev/ttyUSB0"); - relaisboard.open(); + //IRelaisboard relaisboard = new Relaisboard("/dev/ttyUSB0"); + //relaisboard.open(); + //relaisboard.close(); - /* - relaisboard.setRelais(1,false); - //relaisboard.setRelais(1, true); + IBuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080); - relaisboard.toggleRelais(1, 500); - Thread.sleep(1000); - relaisboard.toggleRelais(1, 500); - Thread.sleep(1000); - relaisboard.toggleRelais(1, 500); - - //relaisboard.setRelais(1, false); - - Thread.sleep(4000); */ - - //relaisboard.blinkRelais(2, 500, 6); - - - relaisboard.close(); + for(int i = 0; i < 10; i++) { + bunti.setPar56(0, 255, 0, 0); + bunti.setPar56(1, 0, 255, 0); + bunti.setPar56(2, 0, 255, 0); + bunti.setPar56(3, 255, 0, 0); + Thread.sleep(500); + bunti.setPar56(0, 0, 0, 255); + bunti.setPar56(1, 255, 255, 0); + bunti.setPar56(2, 255, 255, 0); + bunti.setPar56(3, 0, 0, 255); + Thread.sleep(500); + bunti.setPar56(0, 255, 128, 0); + bunti.setPar56(1, 0, 255, 255); + bunti.setPar56(2, 0, 255, 255); + bunti.setPar56(3, 255, 128, 0); + Thread.sleep(500); + bunti.setPar56(0, 0, 255, 255); + bunti.setPar56(1, 0, 255, 0); + bunti.setPar56(2, 0, 255, 0); + bunti.setPar56(3, 0, 255, 255); + Thread.sleep(500); + } } diff --git a/src/de/ctdo/crashtest/domotics/BuntiClient.java b/src/de/ctdo/crashtest/domotics/BuntiClient.java index c8f1776..b34b6b9 100644 --- a/src/de/ctdo/crashtest/domotics/BuntiClient.java +++ b/src/de/ctdo/crashtest/domotics/BuntiClient.java @@ -12,7 +12,7 @@ import java.net.Socket; public class BuntiClient implements IBuntiClient { private String baseAddress; - private final HttpClient client = new DefaultHttpClient(); + //private final HttpClient client = new DefaultHttpClient(); public BuntiClient(String server, int port) { baseAddress = "http://" + server + ":" + port + "/"; @@ -25,6 +25,7 @@ public class BuntiClient implements IBuntiClient { @Override public void run() { try { + HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(baseAddress + "/control/devices"); post.addHeader("Content-Type", "application/json"); @@ -66,6 +67,52 @@ public class BuntiClient implements IBuntiClient { new Thread(r).start(); } + @Override + public void setPar56(final int par, final int red, final int green, final int blue) { + + Runnable r = new Runnable() { + @Override + public void run() { + try { + HttpClient client = new DefaultHttpClient(); + HttpPost post = new HttpPost(baseAddress + "/control/devices"); + post.addHeader("Content-Type", "application/json"); + + StringBuilder jsonString = new StringBuilder(); + + jsonString.append("{ \"timeStamp\": 0, \"updates\": [ "); + + jsonString.append(" {\"deviceId\": "); + jsonString.append(par); + jsonString.append(", \"options\": { \"red\": "); + jsonString.append(red); + jsonString.append(", \"green\": "); + jsonString.append(green); + jsonString.append(", \"blue\": "); + jsonString.append(blue); + jsonString.append(" } } "); + + jsonString.append("] }"); + + StringEntity entity = new StringEntity( jsonString.toString(), "UTF-8"); + post.setEntity(entity); + + client.execute(post); + post.abort(); + + } catch (UnsupportedEncodingException e) { + Logger.sLog("bunti error: " + e.getMessage()); + } catch (ClientProtocolException e) { + Logger.sLog("bunti error: " + e.getMessage()); + } catch (IOException e) { + Logger.sLog("bunti error: " + e.getMessage()); + } + } + }; + + new Thread(r).start(); + } + @Override public void setLampel(final boolean red, final boolean yellow, final boolean green) { diff --git a/src/de/ctdo/crashtest/domotics/IBuntiClient.java b/src/de/ctdo/crashtest/domotics/IBuntiClient.java index bff4f75..ddeb5db 100644 --- a/src/de/ctdo/crashtest/domotics/IBuntiClient.java +++ b/src/de/ctdo/crashtest/domotics/IBuntiClient.java @@ -6,6 +6,7 @@ package de.ctdo.crashtest.domotics; */ public interface IBuntiClient { void setPar56(final int red, final int green, final int blue); + void setPar56(final int par, final int red, final int green, final int blue); void setLampel(final boolean red, final boolean yellow, final boolean green); } diff --git a/src/de/ctdo/crashtest/game/TheGame.java b/src/de/ctdo/crashtest/game/TheGame.java index 21b8b94..2ba096b 100644 --- a/src/de/ctdo/crashtest/game/TheGame.java +++ b/src/de/ctdo/crashtest/game/TheGame.java @@ -163,10 +163,10 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent bunti.setLampel(false,true,false); bunti.setPar56(0, 255, 0); - ircClient.say("table game complete, r0kets now"); relaisboard.toggleRelais(0, 300); relaisboard.toggleRelais(3, 10000); + guiControl.setWall("Pizza ist fertig!"); guiControl.showCountDown(true); machine.startTimer(7*60); break; @@ -177,6 +177,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent bunti.setLampel(false,false,true); bunti.setPar56(255, 255, 255); + guiControl.setWall("willkommen im chaostreff dortmund"); guiControl.showCountDown(true); machine.pauseTimer(true); @@ -189,7 +190,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent } sayScore(); - + disco(); break; } @@ -394,4 +395,43 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent relaisboard.setRelais(6, true); // enable third green circle } + private void disco() { + + Runnable r = new Runnable() { + @Override + public void run() { + try { + for(int i = 0; i < 10; i++) { + bunti.setPar56(0, 255, 0, 0); + bunti.setPar56(1, 0, 255, 0); + bunti.setPar56(2, 0, 255, 0); + bunti.setPar56(3, 255, 0, 0); + Thread.sleep(500); + bunti.setPar56(0, 0, 0, 255); + bunti.setPar56(1, 255, 255, 0); + bunti.setPar56(2, 255, 255, 0); + bunti.setPar56(3, 0, 0, 255); + Thread.sleep(500); + bunti.setPar56(0, 255, 128, 0); + bunti.setPar56(1, 0, 255, 255); + bunti.setPar56(2, 0, 255, 255); + bunti.setPar56(3, 255, 128, 0); + Thread.sleep(500); + bunti.setPar56(0, 0, 255, 255); + bunti.setPar56(1, 0, 255, 0); + bunti.setPar56(2, 0, 255, 0); + bunti.setPar56(3, 0, 255, 255); + Thread.sleep(500); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }; + + new Thread(r).start(); + + + } + }