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) {
|
||||
digitalWrite(LED_R, LOW);
|
||||
digitalWrite(LED_G, HIGH);
|
||||
printState(state_current);
|
||||
stateBegan = millis();
|
||||
return true;
|
||||
}
|
||||
|
@ -93,16 +94,19 @@ boolean transition() {
|
|||
if (state_previous == STATE_ON && state_current == STATE_HALF) {
|
||||
digitalWrite(LED_G, LOW);
|
||||
digitalWrite(LED_Y, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
if (state_previous == STATE_ON && state_current == STATE_OFF) {
|
||||
digitalWrite(LED_G, LOW);
|
||||
digitalWrite(LED_R, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
if (state_previous == STATE_HALF && state_current == STATE_OFF) {
|
||||
digitalWrite(LED_Y, LOW);
|
||||
digitalWrite(LED_R, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
if (state_previous == STATE_HALF && state_current == STATE_ON) {
|
||||
|
@ -115,17 +119,32 @@ boolean transition() {
|
|||
digitalWrite(LED_G, LOW);
|
||||
digitalWrite(LED_Y, LOW);
|
||||
digitalWrite(LED_R, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// information über aktuellen Zustand auf die Serielle Verbindung schreiben
|
||||
void sendState() {
|
||||
if (state_current == STATE_ON || state_current == STATE_HALF) {
|
||||
Serial.print("1");
|
||||
} else {
|
||||
Serial.print("0");
|
||||
// schreibt den aktuellen Zustand auf die Serialeverbindung
|
||||
void printState(byte state) {
|
||||
switch (state) {
|
||||
case STATE_OFF:
|
||||
Serial.print("OFF\n");
|
||||
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) {
|
||||
changeStateTo(STATE_OFF);
|
||||
}
|
||||
|
||||
// kommunizieren
|
||||
sendState();
|
||||
delay(10);
|
||||
// auf Eingaben auf der Serialenverbindung reagieren
|
||||
handleSerial();
|
||||
}
|
||||
|
||||
// Debouncer Klasse
|
||||
|
|
Reference in a new issue