Compare commits

...
This repository has been archived on 2024-01-26. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.

14 commits
master ... push

Author SHA1 Message Date
Martin Ness
a90280ff97 Arduino Code: auslagerung in neue Funktion printState 2016-05-01 14:03:34 +02:00
Martin Ness
c7c3152108 Syntax FIX 2016-05-01 13:53:10 +02:00
Martin Ness
8efaf7df01 Komentare hinzugefügt 2016-05-01 13:52:07 +02:00
Martin Ness
18d0aa878a Warte bis Getät vorhanden 2016-05-01 13:51:57 +02:00
Martin Ness
d77264ba9e whitespace fix 2015-10-07 01:47:23 +02:00
Martin Ness
573e1ec66f shellcheck SC2162 - https://github.com/koalaman/shellcheck/wiki/SC2162 2015-10-07 01:43:54 +02:00
Martin Ness
096bb37f05 use run-parts 2015-10-07 01:32:09 +02:00
Martin Ness
f8e447a4b8 remove .sh in the name from push.d/skeleton.sh 2015-10-07 01:31:32 +02:00
Martin Ness
e92963e932 merge bugfix 2015-09-28 23:55:28 +02:00
Martin Ness
aab9eb3700 script added 2015-09-28 23:06:01 +02:00
Martin Ness
e813711ad8 FIX only newline 2015-09-24 18:12:38 +02:00
Martin Ness
cddc1d675a Auf anfrage Status senden 2015-09-24 16:37:56 +02:00
Martin Ness
41cec53d48 cleanup 2015-09-24 16:36:45 +02:00
Martin Ness
9d34f7e60b push state changes 2015-09-24 15:13:55 +02:00
3 changed files with 68 additions and 10 deletions

13
push.d/skeleton Normal file
View 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
View 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

View file

@ -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