diff --git a/.idea/artifacts/crashteststeuerung_jar.xml b/.idea/artifacts/crashteststeuerung_jar.xml
index a91aff4..f9aabe3 100644
--- a/.idea/artifacts/crashteststeuerung_jar.xml
+++ b/.idea/artifacts/crashteststeuerung_jar.xml
@@ -14,6 +14,8 @@
+
+
\ No newline at end of file
diff --git a/librxtxSerial.so b/librxtxSerial.so
new file mode 100644
index 0000000..e60c5e6
Binary files /dev/null and b/librxtxSerial.so differ
diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF
index a44ebd4..d15802b 100644
--- a/src/META-INF/MANIFEST.MF
+++ b/src/META-INF/MANIFEST.MF
@@ -1,3 +1,3 @@
Manifest-Version: 1.0
-Main-Class: de.ctdo.crashtest.SteuerungFrame
+Main-Class: de.ctdo.crashtest.Steuerung
diff --git a/src/de/ctdo/crashtest/TestClass.java b/src/de/ctdo/crashtest/TestClass.java
index 878f2bf..9a74739 100644
--- a/src/de/ctdo/crashtest/TestClass.java
+++ b/src/de/ctdo/crashtest/TestClass.java
@@ -1,5 +1,7 @@
package de.ctdo.crashtest;
+import de.ctdo.crashtest.domotics.IRelaisboard;
+import de.ctdo.crashtest.domotics.Relaisboard;
import de.ctdo.crashtest.mpd.IMPDController;
import de.ctdo.crashtest.mpd.MPDController;
@@ -11,8 +13,29 @@ public class TestClass {
public static void main(String args[]) throws InterruptedException {
+ IRelaisboard board = new Relaisboard("/dev/ttyUSB0");
+ board.open();
+
+ /*
+ board.setRelais(1,false);
+ //board.setRelais(1, true);
+
+ board.toggleRelais(1, 500);
+ Thread.sleep(1000);
+ board.toggleRelais(1, 500);
+ Thread.sleep(1000);
+ board.toggleRelais(1, 500);
+
+ //board.setRelais(1, false);
+
+ Thread.sleep(4000); */
+
+ board.blinkRelais(2, 500, 6); // hint Button
+
+ Thread.sleep(6000);
+ board.close();
}
diff --git a/src/de/ctdo/crashtest/domotics/IRelaisboard.java b/src/de/ctdo/crashtest/domotics/IRelaisboard.java
index 0baee89..2bcbfaa 100644
--- a/src/de/ctdo/crashtest/domotics/IRelaisboard.java
+++ b/src/de/ctdo/crashtest/domotics/IRelaisboard.java
@@ -4,7 +4,7 @@ public interface IRelaisboard {
void setRelais(final int relais, final boolean state);
void toggleRelais(final int relais, final int milliseconds);
-
+ void blinkRelais(final int relais, final int pause, final int count);
boolean open();
void close();
diff --git a/src/de/ctdo/crashtest/domotics/Relaisboard.java b/src/de/ctdo/crashtest/domotics/Relaisboard.java
index 1e4d921..5b482da 100644
--- a/src/de/ctdo/crashtest/domotics/Relaisboard.java
+++ b/src/de/ctdo/crashtest/domotics/Relaisboard.java
@@ -11,38 +11,34 @@ public class Relaisboard implements IRelaisboard {
private OutputStream outputStream;
private Boolean serialPortGeoeffnet = false;
private String portName = "/dev/ttyUSB0";
+ private Object mLock = new Object();
public Relaisboard(final String port) {
this.portName = port;
}
- private synchronized void send(final char ch) {
- if (!serialPortGeoeffnet) return;
-
- try {
- outputStream.write(ch);
- } catch (IOException e) {
- Logger.sLog("Fehler beim Senden");
- }
- }
-
private void sendData(final int relais, final boolean state) {
- if(relais >= 0 && relais < 8) {
+ if(relais >= 0 && relais < 8 && outputStream != null) {
char charsOff[] = { 'a','b','c','d','e','f','g','h' };
char charsOn[] = { 'A','B','C','D','E','F','G','H' };
- if(state) {
- send(charsOn[relais]);
- } else {
- send(charsOff[relais]);
+ try {
+ if(state) {
+ outputStream.write(charsOn[relais]);
+ } else {
+ outputStream.write(charsOff[relais]);
+ }
+
+ outputStream.flush();
+ } catch (IOException e) {
+ Logger.sLog("Fehler beim Senden");
}
}
}
@Override
- public boolean open()
- {
+ public boolean open() {
serialPortGeoeffnet = false;
Boolean foundPort = false;
@@ -100,33 +96,73 @@ public class Relaisboard implements IRelaisboard {
public void setRelais(final int relais, final boolean state) {
if(!serialPortGeoeffnet) return;
- Runnable r = new Runnable() {
- @Override
- public void run() {
- sendData(relais, state);
- }
- };
+ synchronized (mLock) {
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ sendData(relais, state);
+ }
+ };
- new Thread(r).start();
+ new Thread(r).start();
+ }
}
@Override
public void toggleRelais(final int relais, final int milliseconds) {
if(!serialPortGeoeffnet) return;
- Runnable r = new Runnable() {
- @Override
- public void run() {
- sendData(relais, true);
+ synchronized (mLock) {
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ sendData(relais, true);
- try {
- Thread.sleep(milliseconds);
- } catch (InterruptedException e) { }
+ try {
+ Thread.sleep(milliseconds);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
- sendData(relais, false);
- }
- };
+ sendData(relais, false);
+ }
+ };
- new Thread(r).start();
+ new Thread(r).start();
+ }
+ }
+
+ @Override
+ public void blinkRelais(final int relais, final int pause, final int count) {
+ if(!serialPortGeoeffnet) return;
+
+ synchronized (mLock) {
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ int i;
+
+ for(i = 0; i< count; i++) {
+ sendData(relais, true);
+
+ try {
+ Thread.sleep(pause);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ sendData(relais, false);
+
+ try {
+ Thread.sleep(pause);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ };
+
+ new Thread(r).start();
+ }
}
}
diff --git a/src/de/ctdo/crashtest/game/TheGame.java b/src/de/ctdo/crashtest/game/TheGame.java
index a0f9e54..2a4b938 100644
--- a/src/de/ctdo/crashtest/game/TheGame.java
+++ b/src/de/ctdo/crashtest/game/TheGame.java
@@ -12,6 +12,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
private IStatemachine machine;
private IBuntiClient bunti;
private IMPDController mpdController;
+ private IRelaisboard relaisboard;
public TheGame(IGuiControl guiControl) {
this.guiControl = guiControl;
@@ -19,7 +20,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
this.ircClient = new IrcClient("crashtest", "#crashtest","irc.hackint.eu");
this.bunti = new BuntiClient("bunti.ctdo.de", 8080);
this.mpdController = new MPDController("dampfradio.raum.ctdo.de");
- this.machine = new Statemachine();
+ this.relaisboard = new Relaisboard("/dev/ttyUSB0");
+ this.machine = new Statemachine();
initGame();
}
@@ -30,6 +32,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
machine.addListener(this);
machine.reset();
+ relaisboard.open();
+ relaisboard.toggleRelais(2, 2000);
}
@@ -45,11 +49,12 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
switch (newState) {
case IDLE:
machine.stopTimer();
+ guiControl.setExtra("");
+ guiControl.setWall("");
mpdController.setVolume(45);
mpdController.playSong("start", "mix");
-
bunti.setPar56(0,0,0);
bunti.setLampel(false,false,false);
@@ -68,6 +73,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
machine.startTimer(60*8);
break;
case TABLE_GAME_ONE:
+ guiControl.setWall("64K RAM SYSTEM 38911 BASIC BYTES FREE. **** COMMODORE 64 BASIC V2 ****");
+
mpdController.setVolume(70);
mpdController.playSong("K2", "Der Berg Ruft");
@@ -120,6 +127,9 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
guiControl.showCountDown(true);
machine.pauseTimer(true);
sayScore();
+
+ relaisboard.blinkRelais(2, 500, 6); // hint Button
+
break;
case ROKET_STARTED:
mpdController.setVolume(50);
@@ -131,6 +141,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
ircClient.say("table game complete, r0kets now");
+ relaisboard.toggleRelais(0, 300);
+
guiControl.showCountDown(true);
machine.startTimer(7*60);
break;
@@ -163,7 +175,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
@Override
public void keyPress(char key) {
machine.handleInput(key);
- guiControl.setExtra("btn: " + key);
+ //guiControl.setExtra("btn: " + key);
}
@@ -175,6 +187,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
machine.reset();
bunti.setPar56(0xff,0xff,0xff);
ircClient.say("bye");
+ relaisboard.close();
}
/**