Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
|
a90280ff97 | ||
|
c7c3152108 | ||
|
8efaf7df01 | ||
|
18d0aa878a | ||
|
d77264ba9e | ||
|
573e1ec66f | ||
|
096bb37f05 | ||
|
f8e447a4b8 | ||
|
e92963e932 | ||
|
aab9eb3700 | ||
|
e813711ad8 | ||
|
cddc1d675a | ||
|
41cec53d48 | ||
|
9d34f7e60b |
3 changed files with 68 additions and 10 deletions
13
push.d/skeleton
Normal file
13
push.d/skeleton
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
ON)
|
||||||
|
echo 'ON'
|
||||||
|
;;
|
||||||
|
HALF)
|
||||||
|
echo 'HALF'
|
||||||
|
;;
|
||||||
|
OFF)
|
||||||
|
echo 'OFF'
|
||||||
|
;;
|
||||||
|
esac
|
28
push.sh
Executable file
28
push.sh
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
DEV='/dev/ttyUSB0'
|
||||||
|
DIR='push.d'
|
||||||
|
stty -F "$DEV" 9600 -brkint -icrnl -imaxbel -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
|
||||||
|
|
||||||
|
# Warte bis Device $DEV vorhanden ist
|
||||||
|
while [ ! -c "$DEV" ]; do
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
# sende beliebiges Zeichen an $DEV
|
||||||
|
echo '?' >> "$DEV" &
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
# wenn $DEV vorhanden
|
||||||
|
if [ -c "$DEV" ]; then
|
||||||
|
# dann lese zustand
|
||||||
|
read -r state < "$DEV"
|
||||||
|
case "$state" in
|
||||||
|
ON|HALF|OFF)
|
||||||
|
run-parts --arg="$state" "$DIR"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
# sonst warte
|
||||||
|
sleep 10
|
||||||
|
fi
|
||||||
|
done
|
|
@ -83,6 +83,7 @@ boolean transition() {
|
||||||
if (state_previous == STATE_OFF && state_current == STATE_ON) {
|
if (state_previous == STATE_OFF && state_current == STATE_ON) {
|
||||||
digitalWrite(LED_R, LOW);
|
digitalWrite(LED_R, LOW);
|
||||||
digitalWrite(LED_G, HIGH);
|
digitalWrite(LED_G, HIGH);
|
||||||
|
printState(state_current);
|
||||||
stateBegan = millis();
|
stateBegan = millis();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -93,16 +94,19 @@ boolean transition() {
|
||||||
if (state_previous == STATE_ON && state_current == STATE_HALF) {
|
if (state_previous == STATE_ON && state_current == STATE_HALF) {
|
||||||
digitalWrite(LED_G, LOW);
|
digitalWrite(LED_G, LOW);
|
||||||
digitalWrite(LED_Y, HIGH);
|
digitalWrite(LED_Y, HIGH);
|
||||||
|
printState(state_current);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (state_previous == STATE_ON && state_current == STATE_OFF) {
|
if (state_previous == STATE_ON && state_current == STATE_OFF) {
|
||||||
digitalWrite(LED_G, LOW);
|
digitalWrite(LED_G, LOW);
|
||||||
digitalWrite(LED_R, HIGH);
|
digitalWrite(LED_R, HIGH);
|
||||||
|
printState(state_current);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (state_previous == STATE_HALF && state_current == STATE_OFF) {
|
if (state_previous == STATE_HALF && state_current == STATE_OFF) {
|
||||||
digitalWrite(LED_Y, LOW);
|
digitalWrite(LED_Y, LOW);
|
||||||
digitalWrite(LED_R, HIGH);
|
digitalWrite(LED_R, HIGH);
|
||||||
|
printState(state_current);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (state_previous == STATE_HALF && state_current == STATE_ON) {
|
if (state_previous == STATE_HALF && state_current == STATE_ON) {
|
||||||
|
@ -115,17 +119,32 @@ boolean transition() {
|
||||||
digitalWrite(LED_G, LOW);
|
digitalWrite(LED_G, LOW);
|
||||||
digitalWrite(LED_Y, LOW);
|
digitalWrite(LED_Y, LOW);
|
||||||
digitalWrite(LED_R, HIGH);
|
digitalWrite(LED_R, HIGH);
|
||||||
|
printState(state_current);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// information über aktuellen Zustand auf die Serielle Verbindung schreiben
|
// schreibt den aktuellen Zustand auf die Serialeverbindung
|
||||||
void sendState() {
|
void printState(byte state) {
|
||||||
if (state_current == STATE_ON || state_current == STATE_HALF) {
|
switch (state) {
|
||||||
Serial.print("1");
|
case STATE_OFF:
|
||||||
} else {
|
Serial.print("OFF\n");
|
||||||
Serial.print("0");
|
break;
|
||||||
|
case STATE_HALF:
|
||||||
|
Serial.print("HALF\n");
|
||||||
|
break;
|
||||||
|
case STATE_ON:
|
||||||
|
Serial.print("ON\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleSerial() {
|
||||||
|
if (Serial.read() != -1) {
|
||||||
|
printState(state_current);
|
||||||
|
do {
|
||||||
|
delay(10);
|
||||||
|
} while (Serial.read() != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,10 +177,8 @@ void loop() {
|
||||||
} else if (state_current == STATE_HALF && calcStateTime() >= TIME_OFF) {
|
} else if (state_current == STATE_HALF && calcStateTime() >= TIME_OFF) {
|
||||||
changeStateTo(STATE_OFF);
|
changeStateTo(STATE_OFF);
|
||||||
}
|
}
|
||||||
|
// auf Eingaben auf der Serialenverbindung reagieren
|
||||||
// kommunizieren
|
handleSerial();
|
||||||
sendState();
|
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debouncer Klasse
|
// Debouncer Klasse
|
||||||
|
|
Reference in a new issue