bauen bauen bauen

This commit is contained in:
Lucas Pleß 2012-05-22 23:11:08 +02:00
parent 2f1842733b
commit a80cf9177e
4 changed files with 69 additions and 36 deletions

View File

@ -16,8 +16,9 @@ import java.io.UnsupportedEncodingException;
* Time: 11:03 * Time: 11:03
*/ */
public class BuntiClient { public class BuntiClient {
String baseAddress; private String baseAddress;
HttpClient client = new DefaultHttpClient(); private HttpClient client = new DefaultHttpClient();
private LampelClient lampel = new LampelClient();
public BuntiClient(String server, int port) { public BuntiClient(String server, int port) {
baseAddress = "http://" + server + ":" + port + "/"; baseAddress = "http://" + server + ":" + port + "/";
@ -51,7 +52,17 @@ public class BuntiClient {
} }
public void setLampel(boolean red, boolean yellow, boolean green) { public void setLampel(boolean red, boolean yellow, boolean green) {
try {
int value = 0;
if( green ) value |= 0x01;
if( yellow ) value |= 0x02;
if( red ) value |= 0x04;
lampel.sendCommand("io set port 2 " + Integer.toHexString(value));
/* try {
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");
@ -73,7 +84,7 @@ public class BuntiClient {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }*/
} }
} }

View File

@ -0,0 +1,36 @@
package de.ctdo.crashtest;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
public class LampelClient {
private static final int ECMD_TCP_PORT = 2701;
private static final String LAMPEL_HOST = "lampel.ctdo.de";
public void sendCommand(String command) {
try {
Socket client = new Socket(LAMPEL_HOST, ECMD_TCP_PORT);
client.setSoTimeout(2000);
DataOutputStream outToServer = new DataOutputStream(client.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(client.getInputStream()));
outToServer.writeBytes(command + '\n');
String result = inFromServer.readLine();
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -115,62 +115,46 @@ public class Statemachine {
case TABLE_GAME_ONE: case TABLE_GAME_ONE:
if(input == TABLE_TWO) { if(input == TABLE_TWO) {
retVal = state.TABLE_GAME_TWO; retVal = state.TABLE_GAME_TWO;
} else {
retVal = state.TABLE_GAME_ONE;
} }
break; break;
case TABLE_GAME_TWO: case TABLE_GAME_TWO:
if(input == TABLE_THREE) { if(input == TABLE_THREE) {
retVal = state.TABLE_GAME_THREE; retVal = state.TABLE_GAME_THREE;
} else if (input == TABLE_TWO) { } else if (input == TABLE_ONE) {
} else {
retVal = state.TABLE_GAME_ONE; retVal = state.TABLE_GAME_ONE;
} }
break; break;
case TABLE_GAME_THREE: case TABLE_GAME_THREE:
if(input == TABLE_TWO) { if(input == TABLE_TWO) {
retVal = state.TABLE_GAME_FOUR; retVal = state.TABLE_GAME_FOUR;
} else if (input == TABLE_THREE) { } else if (input == TABLE_ONE) {
} else {
retVal = state.TABLE_GAME_ONE; retVal = state.TABLE_GAME_ONE;
} }
break; break;
case TABLE_GAME_FOUR: case TABLE_GAME_FOUR:
if(input == TABLE_THREE) { if(input == TABLE_THREE) {
retVal = state.TABLE_GAME_FIVE; retVal = state.TABLE_GAME_FIVE;
} else if (input == TABLE_TWO) { } else if (input == TABLE_ONE) {
} else {
retVal = state.TABLE_GAME_ONE; retVal = state.TABLE_GAME_ONE;
} }
break; break;
case TABLE_GAME_FIVE: case TABLE_GAME_FIVE:
if(input == TABLE_ONE) { if(input == TABLE_ONE) {
retVal = state.TABLE_GAME_SIX; retVal = state.TABLE_GAME_SIX;
} else if (input == TABLE_THREE) { } else if (input == TABLE_TWO) {
} else {
retVal = state.TABLE_GAME_ONE; retVal = state.TABLE_GAME_ONE;
} }
break; break;
case TABLE_GAME_SIX: case TABLE_GAME_SIX:
if(input == TABLE_THREE) { if(input == TABLE_THREE) {
retVal = state.TABLE_GAME_SEVEN; retVal = state.TABLE_GAME_SEVEN;
} else if (input == TABLE_ONE) { } else if (input == TABLE_TWO) {
} else {
retVal = state.TABLE_GAME_ONE; retVal = state.TABLE_GAME_ONE;
} }
break; break;
case TABLE_GAME_SEVEN: case TABLE_GAME_SEVEN:
if(input == BLUE_BUTTON) { if(input == BLUE_BUTTON) {
retVal = state.FINISH; retVal = state.FINISH;
} else if (input == TABLE_THREE) {
} else {
retVal = state.TABLE_GAME_ONE;
} }
break; break;

View File

@ -18,6 +18,7 @@ public class SteuerungFrame extends JFrame implements StateChangeListener {
private MPD mpd; private MPD mpd;
private MPDPlayer player; private MPDPlayer player;
Statemachine machine = new Statemachine(); Statemachine machine = new Statemachine();
BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080); BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080);
@ -87,42 +88,43 @@ public class SteuerungFrame extends JFrame implements StateChangeListener {
switch (newState) { switch (newState) {
case IDLE: case IDLE:
setLEDs(0,0,0); setLEDs(0x40,0,0xff);
bunti.setLampel(false,false,false); bunti.setLampel(false,false,false);
break; break;
case ENTERED_ROOM: case ENTERED_ROOM:
bunti.setLampel(true,false,false); bunti.setLampel(false,false,false);
setLEDs(255,0,0); setLEDs(255,0,100);
break; break;
case TABLE_GAME_ONE: case TABLE_GAME_ONE:
bunti.setLampel(false,true,false); bunti.setLampel(true,false,false);
setLEDs(255,255,0); setLEDs(255,0,100);
break; break;
case TABLE_GAME_TWO: case TABLE_GAME_TWO:
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
setLEDs(0,255,0); setLEDs(255,0,100);
break; break;
case TABLE_GAME_THREE: case TABLE_GAME_THREE:
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
setLEDs(0,255,255); setLEDs(255,35,0);
break; break;
case TABLE_GAME_FOUR: case TABLE_GAME_FOUR:
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
setLEDs(0,0,255); setLEDs(255,55,0);
break; break;
case TABLE_GAME_FIVE: case TABLE_GAME_FIVE:
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
setLEDs(255,255,255); setLEDs(255,75,0);
break; break;
case TABLE_GAME_SIX: case TABLE_GAME_SIX:
bunti.setLampel(false,true,false); bunti.setLampel(false,true,false);
setLEDs(30,30,30); setLEDs(255,100,0);
break; break;
case TABLE_GAME_SEVEN: case TABLE_GAME_SEVEN:
bunti.setLampel(false,false,true); bunti.setLampel(false,false,true);
setLEDs(30,0,255); setLEDs(255,100,0);
break; break;
case FINISH: case FINISH:
bunti.setLampel(false,false,true);
setLEDs(0, 255, 0); setLEDs(0, 255, 0);
break; break;
} }