From a80cf9177e7f17f1a0bc9726c383b37b7ef4065a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Tue, 22 May 2012 23:11:08 +0200 Subject: [PATCH] bauen bauen bauen --- src/de/ctdo/crashtest/BuntiClient.java | 19 +++++++++--- src/de/ctdo/crashtest/LampelClient.java | 36 +++++++++++++++++++++++ src/de/ctdo/crashtest/Statemachine.java | 26 ++++------------ src/de/ctdo/crashtest/SteuerungFrame.java | 24 ++++++++------- 4 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 src/de/ctdo/crashtest/LampelClient.java diff --git a/src/de/ctdo/crashtest/BuntiClient.java b/src/de/ctdo/crashtest/BuntiClient.java index ca03f20..33aaf42 100644 --- a/src/de/ctdo/crashtest/BuntiClient.java +++ b/src/de/ctdo/crashtest/BuntiClient.java @@ -16,8 +16,9 @@ import java.io.UnsupportedEncodingException; * Time: 11:03 */ public class BuntiClient { - String baseAddress; - HttpClient client = new DefaultHttpClient(); + private String baseAddress; + private HttpClient client = new DefaultHttpClient(); + private LampelClient lampel = new LampelClient(); public BuntiClient(String server, int port) { baseAddress = "http://" + server + ":" + port + "/"; @@ -51,7 +52,17 @@ public class BuntiClient { } 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"); post.addHeader("Content-Type", "application/json"); @@ -73,7 +84,7 @@ public class BuntiClient { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); - } + }*/ } } diff --git a/src/de/ctdo/crashtest/LampelClient.java b/src/de/ctdo/crashtest/LampelClient.java new file mode 100644 index 0000000..941aa8c --- /dev/null +++ b/src/de/ctdo/crashtest/LampelClient.java @@ -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(); + } + + } +} diff --git a/src/de/ctdo/crashtest/Statemachine.java b/src/de/ctdo/crashtest/Statemachine.java index 9997d31..ddf8300 100644 --- a/src/de/ctdo/crashtest/Statemachine.java +++ b/src/de/ctdo/crashtest/Statemachine.java @@ -115,62 +115,46 @@ public class Statemachine { case TABLE_GAME_ONE: if(input == TABLE_TWO) { retVal = state.TABLE_GAME_TWO; - } else { - retVal = state.TABLE_GAME_ONE; } break; case TABLE_GAME_TWO: if(input == TABLE_THREE) { retVal = state.TABLE_GAME_THREE; - } else if (input == TABLE_TWO) { - - } else { + } else if (input == TABLE_ONE) { retVal = state.TABLE_GAME_ONE; } break; case TABLE_GAME_THREE: if(input == TABLE_TWO) { retVal = state.TABLE_GAME_FOUR; - } else if (input == TABLE_THREE) { - - } else { + } else if (input == TABLE_ONE) { retVal = state.TABLE_GAME_ONE; } break; case TABLE_GAME_FOUR: if(input == TABLE_THREE) { retVal = state.TABLE_GAME_FIVE; - } else if (input == TABLE_TWO) { - - } else { + } else if (input == TABLE_ONE) { retVal = state.TABLE_GAME_ONE; } break; case TABLE_GAME_FIVE: if(input == TABLE_ONE) { retVal = state.TABLE_GAME_SIX; - } else if (input == TABLE_THREE) { - - } else { + } else if (input == TABLE_TWO) { retVal = state.TABLE_GAME_ONE; } break; case TABLE_GAME_SIX: if(input == TABLE_THREE) { retVal = state.TABLE_GAME_SEVEN; - } else if (input == TABLE_ONE) { - - } else { + } else if (input == TABLE_TWO) { retVal = state.TABLE_GAME_ONE; } break; case TABLE_GAME_SEVEN: if(input == BLUE_BUTTON) { retVal = state.FINISH; - } else if (input == TABLE_THREE) { - - } else { - retVal = state.TABLE_GAME_ONE; } break; diff --git a/src/de/ctdo/crashtest/SteuerungFrame.java b/src/de/ctdo/crashtest/SteuerungFrame.java index 22c8b2e..6c0062d 100644 --- a/src/de/ctdo/crashtest/SteuerungFrame.java +++ b/src/de/ctdo/crashtest/SteuerungFrame.java @@ -18,6 +18,7 @@ public class SteuerungFrame extends JFrame implements StateChangeListener { private MPD mpd; private MPDPlayer player; + Statemachine machine = new Statemachine(); BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080); @@ -87,42 +88,43 @@ public class SteuerungFrame extends JFrame implements StateChangeListener { switch (newState) { case IDLE: - setLEDs(0,0,0); + setLEDs(0x40,0,0xff); bunti.setLampel(false,false,false); break; case ENTERED_ROOM: - bunti.setLampel(true,false,false); - setLEDs(255,0,0); + bunti.setLampel(false,false,false); + setLEDs(255,0,100); break; case TABLE_GAME_ONE: - bunti.setLampel(false,true,false); - setLEDs(255,255,0); + bunti.setLampel(true,false,false); + setLEDs(255,0,100); break; case TABLE_GAME_TWO: bunti.setLampel(false,true,false); - setLEDs(0,255,0); + setLEDs(255,0,100); break; case TABLE_GAME_THREE: bunti.setLampel(false,true,false); - setLEDs(0,255,255); + setLEDs(255,35,0); break; case TABLE_GAME_FOUR: bunti.setLampel(false,true,false); - setLEDs(0,0,255); + setLEDs(255,55,0); break; case TABLE_GAME_FIVE: bunti.setLampel(false,true,false); - setLEDs(255,255,255); + setLEDs(255,75,0); break; case TABLE_GAME_SIX: bunti.setLampel(false,true,false); - setLEDs(30,30,30); + setLEDs(255,100,0); break; case TABLE_GAME_SEVEN: bunti.setLampel(false,false,true); - setLEDs(30,0,255); + setLEDs(255,100,0); break; case FINISH: + bunti.setLampel(false,false,true); setLEDs(0, 255, 0); break; }