added disco!!!111oneeleven

This commit is contained in:
Lucas Pleß 2012-06-08 04:22:22 +02:00
parent 4fbf9f91fc
commit e3b45dbd9a
4 changed files with 118 additions and 22 deletions

View File

@ -1,6 +1,7 @@
package de.ctdo.crashtest; package de.ctdo.crashtest;
import de.ctdo.crashtest.domotics.BuntiClient; import de.ctdo.crashtest.domotics.BuntiClient;
import de.ctdo.crashtest.domotics.IBuntiClient;
import de.ctdo.crashtest.domotics.IRelaisboard; import de.ctdo.crashtest.domotics.IRelaisboard;
import de.ctdo.crashtest.domotics.Relaisboard; import de.ctdo.crashtest.domotics.Relaisboard;
import de.ctdo.crashtest.mpd.IMPDController; import de.ctdo.crashtest.mpd.IMPDController;
@ -14,27 +15,34 @@ public class TestClass {
public static void main(String args[]) throws InterruptedException { public static void main(String args[]) throws InterruptedException {
IRelaisboard relaisboard = new Relaisboard("/dev/ttyUSB0"); //IRelaisboard relaisboard = new Relaisboard("/dev/ttyUSB0");
relaisboard.open(); //relaisboard.open();
//relaisboard.close();
/* IBuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080);
relaisboard.setRelais(1,false);
//relaisboard.setRelais(1, true);
relaisboard.toggleRelais(1, 500); for(int i = 0; i < 10; i++) {
Thread.sleep(1000); bunti.setPar56(0, 255, 0, 0);
relaisboard.toggleRelais(1, 500); bunti.setPar56(1, 0, 255, 0);
Thread.sleep(1000); bunti.setPar56(2, 0, 255, 0);
relaisboard.toggleRelais(1, 500); bunti.setPar56(3, 255, 0, 0);
Thread.sleep(500);
//relaisboard.setRelais(1, false); bunti.setPar56(0, 0, 0, 255);
bunti.setPar56(1, 255, 255, 0);
Thread.sleep(4000); */ bunti.setPar56(2, 255, 255, 0);
bunti.setPar56(3, 0, 0, 255);
//relaisboard.blinkRelais(2, 500, 6); Thread.sleep(500);
bunti.setPar56(0, 255, 128, 0);
bunti.setPar56(1, 0, 255, 255);
relaisboard.close(); 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);
}
} }

View File

@ -12,7 +12,7 @@ import java.net.Socket;
public class BuntiClient implements IBuntiClient { public class BuntiClient implements IBuntiClient {
private String baseAddress; private String baseAddress;
private final HttpClient client = new DefaultHttpClient(); //private final HttpClient client = new DefaultHttpClient();
public BuntiClient(String server, int port) { public BuntiClient(String server, int port) {
baseAddress = "http://" + server + ":" + port + "/"; baseAddress = "http://" + server + ":" + port + "/";
@ -25,6 +25,7 @@ public class BuntiClient implements IBuntiClient {
@Override @Override
public void run() { public void run() {
try { try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(baseAddress + "/control/devices"); HttpPost post = new HttpPost(baseAddress + "/control/devices");
post.addHeader("Content-Type", "application/json"); post.addHeader("Content-Type", "application/json");
@ -66,6 +67,52 @@ public class BuntiClient implements IBuntiClient {
new Thread(r).start(); 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 @Override
public void setLampel(final boolean red, final boolean yellow, final boolean green) { public void setLampel(final boolean red, final boolean yellow, final boolean green) {

View File

@ -6,6 +6,7 @@ package de.ctdo.crashtest.domotics;
*/ */
public interface IBuntiClient { public interface IBuntiClient {
void setPar56(final int red, final int green, final int blue); 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); void setLampel(final boolean red, final boolean yellow, final boolean green);
} }

View File

@ -163,10 +163,10 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
bunti.setPar56(0, 255, 0); bunti.setPar56(0, 255, 0);
ircClient.say("table game complete, r0kets now");
relaisboard.toggleRelais(0, 300); relaisboard.toggleRelais(0, 300);
relaisboard.toggleRelais(3, 10000); relaisboard.toggleRelais(3, 10000);
guiControl.setWall("Pizza ist fertig!");
guiControl.showCountDown(true); guiControl.showCountDown(true);
machine.startTimer(7*60); machine.startTimer(7*60);
break; break;
@ -177,6 +177,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
bunti.setLampel(false,false,true); bunti.setLampel(false,false,true);
bunti.setPar56(255, 255, 255); bunti.setPar56(255, 255, 255);
guiControl.setWall("willkommen im chaostreff dortmund");
guiControl.showCountDown(true); guiControl.showCountDown(true);
machine.pauseTimer(true); machine.pauseTimer(true);
@ -189,7 +190,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
} }
sayScore(); sayScore();
disco();
break; break;
} }
@ -394,4 +395,43 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
relaisboard.setRelais(6, true); // enable third green circle 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();
}
} }