diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/libraries/commons_codec_1_4.xml b/.idea/libraries/commons_codec_1_4.xml
new file mode 100644
index 0000000..2688973
--- /dev/null
+++ b/.idea/libraries/commons_codec_1_4.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 99b8601..b1d3b5f 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -11,21 +11,5 @@
-
-
-
-
- 1.6
-
-
-
-
-
-
-
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
index 3b00020..d2d2623 100644
--- a/.idea/uiDesigner.xml
+++ b/.idea/uiDesigner.xml
@@ -8,9 +8,6 @@
-
- -
-
-
-
@@ -26,6 +23,9 @@
+ -
+
+
-
diff --git a/crashteststeuerung.iml b/crashteststeuerung.iml
index d5c0743..2ab6dea 100644
--- a/crashteststeuerung.iml
+++ b/crashteststeuerung.iml
@@ -7,6 +7,8 @@
+
+
diff --git a/libs/commons-codec-1.4.jar b/libs/commons-codec-1.4.jar
new file mode 100644
index 0000000..458d432
Binary files /dev/null and b/libs/commons-codec-1.4.jar differ
diff --git a/libs/commons-logging-1.1.1.jar b/libs/commons-logging-1.1.1.jar
new file mode 100644
index 0000000..1deef14
Binary files /dev/null and b/libs/commons-logging-1.1.1.jar differ
diff --git a/libs/httpclient-4.1.3.jar b/libs/httpclient-4.1.3.jar
new file mode 100644
index 0000000..dfa8793
Binary files /dev/null and b/libs/httpclient-4.1.3.jar differ
diff --git a/libs/httpclient-cache-4.1.3.jar b/libs/httpclient-cache-4.1.3.jar
new file mode 100644
index 0000000..83ae3ea
Binary files /dev/null and b/libs/httpclient-cache-4.1.3.jar differ
diff --git a/libs/httpcore-4.1.4.jar b/libs/httpcore-4.1.4.jar
new file mode 100644
index 0000000..1606a2e
Binary files /dev/null and b/libs/httpcore-4.1.4.jar differ
diff --git a/libs/httpmime-4.1.3.jar b/libs/httpmime-4.1.3.jar
new file mode 100644
index 0000000..ff2014f
Binary files /dev/null and b/libs/httpmime-4.1.3.jar differ
diff --git a/src/de/ctdo/crashtest/BuntiClient.java b/src/de/ctdo/crashtest/BuntiClient.java
new file mode 100644
index 0000000..ca03f20
--- /dev/null
+++ b/src/de/ctdo/crashtest/BuntiClient.java
@@ -0,0 +1,79 @@
+package de.ctdo.crashtest;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * User: lpless
+ * Date: 10.05.12
+ * Time: 11:03
+ */
+public class BuntiClient {
+ String baseAddress;
+ HttpClient client = new DefaultHttpClient();
+
+ public BuntiClient(String server, int port) {
+ baseAddress = "http://" + server + ":" + port + "/";
+ }
+
+ public void setPar56(int id, int red, int green, int blue) {
+ try {
+ HttpPost post = new HttpPost(baseAddress + "/control/devices");
+ post.addHeader("Content-Type", "application/json");
+
+ StringEntity entity = new StringEntity(
+ "{ \"timeStamp\": 0, \"updates\": [ {\"deviceId\": "+id+", \"options\": { \"red\": "+
+ red+", \"green\": "+green+", \"blue\": "+blue+" } } ] }" ,
+ "UTF-8");
+
+ post.setEntity(entity);
+
+ HttpResponse response = client.execute(post);
+ System.out.println(response);
+
+ post.abort();
+
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void setLampel(boolean red, boolean yellow, boolean green) {
+ try {
+ HttpPost post = new HttpPost(baseAddress + "/control/devices");
+ post.addHeader("Content-Type", "application/json");
+
+ StringEntity entity = new StringEntity(
+ "{ \"timeStamp\": 0, \"updates\": [ {\"deviceId\": 4, \"options\": { \"red\": "+
+ red+", \"green\": "+green+", \"yellow\": "+yellow+" } } ] }" ,
+ "UTF-8");
+
+ post.setEntity(entity);
+
+ HttpResponse response = client.execute(post);
+ System.out.println(response);
+
+ post.abort();
+
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/de/ctdo/crashtest/StateChangeListener.java b/src/de/ctdo/crashtest/StateChangeListener.java
new file mode 100644
index 0000000..f6c6ad3
--- /dev/null
+++ b/src/de/ctdo/crashtest/StateChangeListener.java
@@ -0,0 +1,10 @@
+package de.ctdo.crashtest;
+
+/**
+ * User: lpless
+ * Date: 10.05.12
+ * Time: 13:37
+ */
+public interface StateChangeListener {
+ void stateChanged(Statemachine.state newState);
+}
diff --git a/src/de/ctdo/crashtest/Statemachine.java b/src/de/ctdo/crashtest/Statemachine.java
index 602fcf3..d48fab6 100644
--- a/src/de/ctdo/crashtest/Statemachine.java
+++ b/src/de/ctdo/crashtest/Statemachine.java
@@ -1,11 +1,21 @@
package de.ctdo.crashtest;
+import java.util.ArrayList;
+import java.util.List;
+
public class Statemachine {
private final char BLUE_BUTTON = 'd';
private final char LIGHT_BARRIER = 'k';
private final char TABLE_ONE = 'c';
private final char TABLE_TWO = 'v';
private final char TABLE_THREE = 'b';
+ private long lastHandleInput = 0;
+ private final List stateChangeListenerList = new ArrayList();
+ private int stateChangeCounter = 0;
+
+ public void addStateChangedListener(StateChangeListener listener) {
+ stateChangeListenerList.add(listener);
+ }
public enum state {
IDLE,
@@ -27,13 +37,64 @@ public class Statemachine {
return currentState;
}
+ public int getStateChangeCounter() {
+ return stateChangeCounter;
+ }
+
+ public void reset() {
+ stateChangeCounter = 0;
+ currentState = state.IDLE;
+ }
+
public void handleInput(char input) {
+ if(System.currentTimeMillis() - lastHandleInput < 200 ) return;
state newState = getNewState(input);
- System.out.println("newState = " + newState);
+ if( newState != currentState ) {
+ stateChangeCounter++;
+ System.out.println("newState = " + newState);
- currentState = newState;
+ workForState(newState);
+
+
+ currentState = newState;
+ onStateChanged();
+ }
+
+
+ lastHandleInput = System.currentTimeMillis();
+ }
+
+ private void onStateChanged() {
+ for(StateChangeListener listener: stateChangeListenerList) {
+ listener.stateChanged(currentState);
+ }
+ }
+
+ private void workForState(state newState) {
+ switch (newState) {
+ case IDLE:
+ break;
+ case ENTERED_ROOM:
+
+
+ break;
+ case TABLE_GAME_ONE:
+ break;
+ case TABLE_GAME_TWO:
+ break;
+ case TABLE_GAME_THREE:
+ break;
+ case TABLE_GAME_FOUR:
+ break;
+ case TABLE_GAME_FIVE:
+ break;
+ case TABLE_GAME_SIX:
+ break;
+ case TABLE_GAME_SEVEN:
+ break;
+ }
}
private state getNewState(char input) {
diff --git a/src/de/ctdo/crashtest/SteuerungFrame.java b/src/de/ctdo/crashtest/SteuerungFrame.java
index f7faa93..999ffba 100644
--- a/src/de/ctdo/crashtest/SteuerungFrame.java
+++ b/src/de/ctdo/crashtest/SteuerungFrame.java
@@ -1,29 +1,133 @@
package de.ctdo.crashtest;
+import org.bff.javampd.MPD;
+import org.bff.javampd.MPDPlayer;
+import org.bff.javampd.exception.MPDConnectionException;
+import org.bff.javampd.exception.MPDResponseException;
+
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
+import java.net.UnknownHostException;
-public class SteuerungFrame extends JFrame {
+public class SteuerungFrame extends JFrame implements StateChangeListener {
+ private JPanel pnlRoot;
+ private JLabel lblState;
+ private char lastKey = ' ';
+ private MPD mpd;
+ private MPDPlayer player;
Statemachine machine = new Statemachine();
+ BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080);
public SteuerungFrame() {
//setType(Type.UTILITY);
setBackground(Color.black);
- setBounds(200,200, 200, 200);
+ setBounds(200,200, 400, 200);
+
+ machine.addStateChangedListener(this);
+
+ initGui();
+
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+ setVisible(true);
+
+ try {
+ mpd = new MPD("dampfradio.raum.chaostreff-dortmund.de", 6600);
+ player = mpd.getMPDPlayer();
+
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ return;
+ } catch (MPDConnectionException e) {
+ e.printStackTrace();
+ return;
+ }
addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
+ lastKey = e.getKeyChar();
//System.out.println(e.getKeyChar());
machine.handleInput(e.getKeyChar());
+ //bunti.setPar56(1, 0xff, 0xff, 0xff);
+
+ updateGui();
+ }
+ });
+
+ addWindowStateListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ try {
+ if(mpd != null) mpd.close();
+ } catch (MPDConnectionException e1) {
+ e1.printStackTrace();
+ } catch (MPDResponseException e1) {
+ e1.printStackTrace();
+ }
}
});
-
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setVisible(true);
}
+ @Override
+ public void stateChanged(Statemachine.state newState) {
+ updateGui();
+
+ switch (newState) {
+ case IDLE:
+ bunti.setPar56(0,0,0,0);
+ bunti.setPar56(1,0,0,0);
+ bunti.setPar56(2,0,0,0);
+ bunti.setPar56(3,0,0,0);
+ bunti.setLampel(false,false,false);
+ break;
+ case ENTERED_ROOM:
+ bunti.setLampel(true,false,false);
+
+ break;
+ case TABLE_GAME_ONE:
+ bunti.setLampel(false,true,false);
+ break;
+ case TABLE_GAME_TWO:
+ bunti.setLampel(false,true,false);
+ break;
+ case TABLE_GAME_THREE:
+ bunti.setLampel(false,true,false);
+ break;
+ case TABLE_GAME_FOUR:
+ bunti.setLampel(false,true,false);
+ break;
+ case TABLE_GAME_FIVE:
+ bunti.setLampel(false,true,false);
+ break;
+ case TABLE_GAME_SIX:
+ bunti.setLampel(false,true,false);
+ break;
+ case TABLE_GAME_SEVEN:
+ bunti.setLampel(false,false,true);
+ break;
+ }
+
+ }
+
+ private void initGui() {
+ Container pane = getContentPane();
+
+ pnlRoot = new JPanel(new FlowLayout());
+ lblState = new JLabel("", JLabel.LEFT);
+ pnlRoot.add(lblState);
+
+ pane.add(pnlRoot);
+
+ updateGui();
+ }
+
+ private void updateGui() {
+ lblState.setText("LastKey: " + lastKey + "
CurrentState: " +
+ machine.getCurrentState() + "
ChangeCounter: " +
+ machine.getStateChangeCounter() + "");
+
+ }
}