From 9d34f7e60be67ea15764f72490b54f23b192eb8d Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Thu, 24 Sep 2015 15:13:55 +0200 Subject: [PATCH 01/13] push state changes --- status/status.ino | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/status/status.ino b/status/status.ino index 041eb58..90343e1 100644 --- a/status/status.ino +++ b/status/status.ino @@ -83,6 +83,7 @@ boolean transition() { if (state_previous == STATE_OFF && state_current == STATE_ON) { digitalWrite(LED_R, LOW); digitalWrite(LED_G, HIGH); + Serial.println("ON"); stateBegan = millis(); return true; } @@ -93,22 +94,26 @@ boolean transition() { if (state_previous == STATE_ON && state_current == STATE_HALF) { digitalWrite(LED_G, LOW); digitalWrite(LED_Y, HIGH); + Serial.println("HALF"); return true; } if (state_previous == STATE_ON && state_current == STATE_OFF) { digitalWrite(LED_G, LOW); digitalWrite(LED_R, HIGH); + Serial.println("OFF"); return true; } if (state_previous == STATE_HALF && state_current == STATE_OFF) { digitalWrite(LED_Y, LOW); digitalWrite(LED_R, HIGH); + Serial.println("OFF"); return true; } if (state_previous == NULL && state_current == STATE_OFF) { digitalWrite(LED_G, LOW); digitalWrite(LED_Y, LOW); digitalWrite(LED_R, HIGH); + Serial.println("OFF"); return true; } return false; @@ -152,10 +157,6 @@ void loop() { } else if (state_current == STATE_HALF && calcStateTime() >= TIME_OFF) { changeStateTo(STATE_OFF); } - - // kommunizieren - sendState(); - delay(10); } // Debouncer Klasse From 41cec53d48d731dac6e06750f354b7e03cc0926f Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Thu, 24 Sep 2015 16:36:45 +0200 Subject: [PATCH 02/13] cleanup --- status/status.ino | 8 -------- 1 file changed, 8 deletions(-) diff --git a/status/status.ino b/status/status.ino index 90343e1..6a4c3fc 100644 --- a/status/status.ino +++ b/status/status.ino @@ -119,14 +119,6 @@ boolean transition() { 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"); - } -} unsigned long calcStateTime() { // Variablen überlauf von millis erkennen From cddc1d675aa3cc32b5240547ae2f4e4981059bb0 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Thu, 24 Sep 2015 16:37:56 +0200 Subject: [PATCH 03/13] Auf anfrage Status senden --- status/status.ino | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/status/status.ino b/status/status.ino index 6a4c3fc..0671841 100644 --- a/status/status.ino +++ b/status/status.ino @@ -119,6 +119,23 @@ boolean transition() { return false; } +void handleSerial() { + if (Serial.read() != -1) { + switch (state_current) { + case STATE_OFF: + Serial.println("OFF"); + break; + case STATE_HALF: + Serial.println("HALF"); + break; + case STATE_ON: + Serial.println("ON"); + } + do { + delay(10); + } while (Serial.read() != -1); + } +} unsigned long calcStateTime() { // Variablen überlauf von millis erkennen @@ -149,6 +166,8 @@ void loop() { } else if (state_current == STATE_HALF && calcStateTime() >= TIME_OFF) { changeStateTo(STATE_OFF); } + // auf Eingaben auf der Serialenverbindung reagieren + handleSerial(); } // Debouncer Klasse From e813711ad8634bba03166cf838cb30b28d4dde98 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Thu, 24 Sep 2015 18:12:38 +0200 Subject: [PATCH 04/13] FIX only newline --- status/status.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/status/status.ino b/status/status.ino index 0671841..28fdf2b 100644 --- a/status/status.ino +++ b/status/status.ino @@ -83,7 +83,7 @@ boolean transition() { if (state_previous == STATE_OFF && state_current == STATE_ON) { digitalWrite(LED_R, LOW); digitalWrite(LED_G, HIGH); - Serial.println("ON"); + Serial.print("ON\n"); stateBegan = millis(); return true; } @@ -94,26 +94,26 @@ boolean transition() { if (state_previous == STATE_ON && state_current == STATE_HALF) { digitalWrite(LED_G, LOW); digitalWrite(LED_Y, HIGH); - Serial.println("HALF"); + Serial.print("HALF\n"); return true; } if (state_previous == STATE_ON && state_current == STATE_OFF) { digitalWrite(LED_G, LOW); digitalWrite(LED_R, HIGH); - Serial.println("OFF"); + Serial.print("OFF\n"); return true; } if (state_previous == STATE_HALF && state_current == STATE_OFF) { digitalWrite(LED_Y, LOW); digitalWrite(LED_R, HIGH); - Serial.println("OFF"); + Serial.print("OFF\n"); return true; } if (state_previous == NULL && state_current == STATE_OFF) { digitalWrite(LED_G, LOW); digitalWrite(LED_Y, LOW); digitalWrite(LED_R, HIGH); - Serial.println("OFF"); + Serial.print("OFF\n"); return true; } return false; @@ -123,13 +123,13 @@ void handleSerial() { if (Serial.read() != -1) { switch (state_current) { case STATE_OFF: - Serial.println("OFF"); + Serial.print("OFF\n"); break; case STATE_HALF: - Serial.println("HALF"); + Serial.print("HALF\n"); break; case STATE_ON: - Serial.println("ON"); + Serial.print("ON\n"); } do { delay(10); From aab9eb370072155be8397ef500d28f46334b8d6a Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Mon, 28 Sep 2015 23:06:01 +0200 Subject: [PATCH 05/13] script added --- push.d/skeleton.sh | 13 +++++++++++++ push.sh | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 push.d/skeleton.sh create mode 100755 push.sh diff --git a/push.d/skeleton.sh b/push.d/skeleton.sh new file mode 100644 index 0000000..86a9ac3 --- /dev/null +++ b/push.d/skeleton.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +case "$1" in + ON) + echo 'ON' + ;; + HALF) + echo 'HALF' + ;; + OFF) + echo 'OFF' + ;; +esac diff --git a/push.sh b/push.sh new file mode 100755 index 0000000..7e0f756 --- /dev/null +++ b/push.sh @@ -0,0 +1,24 @@ +#!/bin/sh -e + +DEV='/dev/ttyUSB0' +DIR='push.d' +stty -F "$DEV" 9600 -brkint -icrnl -imaxbel -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke + +if [ -c "$DEV" ]; then + sleep 2 && echo '?' >> "$DEV" & +fi + +while true; do + if [ -c "$DEV" ]; then + read state < "$DEV" + case "$state" in + ON|HALF|OFF) + for f in $(find -O3 -P "$DIR" -type f -executable | sort -n); do + "$f" "$state" || echo "File $f exited with error $?" + done + ;; + esac + else + sleep 10 + fi +done From f8e447a4b8714e0e2821088aa9ae7d836b1ca30c Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Wed, 7 Oct 2015 01:31:32 +0200 Subject: [PATCH 06/13] remove .sh in the name from push.d/skeleton.sh --- push.d/{skeleton.sh => skeleton} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename push.d/{skeleton.sh => skeleton} (100%) diff --git a/push.d/skeleton.sh b/push.d/skeleton similarity index 100% rename from push.d/skeleton.sh rename to push.d/skeleton From 096bb37f05fc3c171d8380c376a4a61c6c1a9c69 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Wed, 7 Oct 2015 01:32:09 +0200 Subject: [PATCH 07/13] use run-parts --- push.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/push.sh b/push.sh index 7e0f756..88d7dd9 100755 --- a/push.sh +++ b/push.sh @@ -13,9 +13,7 @@ while true; do read state < "$DEV" case "$state" in ON|HALF|OFF) - for f in $(find -O3 -P "$DIR" -type f -executable | sort -n); do - "$f" "$state" || echo "File $f exited with error $?" - done + run-parts --arg="$state" "$DIR" ;; esac else From 573e1ec66f319f85ffc58e6437481a4470d1a797 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Wed, 7 Oct 2015 01:43:54 +0200 Subject: [PATCH 08/13] shellcheck SC2162 - https://github.com/koalaman/shellcheck/wiki/SC2162 --- push.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push.sh b/push.sh index 88d7dd9..64f3425 100755 --- a/push.sh +++ b/push.sh @@ -10,7 +10,7 @@ fi while true; do if [ -c "$DEV" ]; then - read state < "$DEV" + read -r state < "$DEV" case "$state" in ON|HALF|OFF) run-parts --arg="$state" "$DIR" From d77264ba9e00ab8446f25de087c61bf6c338c268 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Wed, 7 Oct 2015 01:47:23 +0200 Subject: [PATCH 09/13] whitespace fix --- push.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push.sh b/push.sh index 64f3425..375ce3a 100755 --- a/push.sh +++ b/push.sh @@ -4,7 +4,7 @@ DEV='/dev/ttyUSB0' DIR='push.d' stty -F "$DEV" 9600 -brkint -icrnl -imaxbel -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke -if [ -c "$DEV" ]; then +if [ -c "$DEV" ]; then sleep 2 && echo '?' >> "$DEV" & fi From 18d0aa878aa4f63d356de52f517bdf3276337403 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sun, 1 May 2016 13:51:57 +0200 Subject: [PATCH 10/13] =?UTF-8?q?Warte=20bis=20Get=C3=A4t=20vorhanden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/push.sh b/push.sh index 375ce3a..d2ab67c 100755 --- a/push.sh +++ b/push.sh @@ -4,9 +4,10 @@ DEV='/dev/ttyUSB0' DIR='push.d' stty -F "$DEV" 9600 -brkint -icrnl -imaxbel -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke -if [ -c "$DEV" ]; then - sleep 2 && echo '?' >> "$DEV" & -fi +while [ ! -c "$DEV" ]; then + sleep 2 +done +echo '?' >> "$DEV" & while true; do if [ -c "$DEV" ]; then From 8efaf7df01200c7f4c9cfb3997067f65588d6461 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sun, 1 May 2016 13:52:07 +0200 Subject: [PATCH 11/13] =?UTF-8?q?Komentare=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/push.sh b/push.sh index d2ab67c..6d4e88f 100755 --- a/push.sh +++ b/push.sh @@ -4,13 +4,17 @@ 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" ]; then 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) @@ -18,6 +22,7 @@ while true; do ;; esac else + # sonst warte sleep 10 fi done From c7c31521087620d3f4c6f86333ad4e5dcb752798 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sun, 1 May 2016 13:53:10 +0200 Subject: [PATCH 12/13] Syntax FIX --- push.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push.sh b/push.sh index 6d4e88f..ac0128d 100755 --- a/push.sh +++ b/push.sh @@ -5,7 +5,7 @@ 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" ]; then +while [ ! -c "$DEV" ]; do sleep 2 done # sende beliebiges Zeichen an $DEV From a90280ff975eca417ea93cf4b3f07213cdbf40ce Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sun, 1 May 2016 14:03:34 +0200 Subject: [PATCH 13/13] Arduino Code: auslagerung in neue Funktion printState --- status/status.ino | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/status/status.ino b/status/status.ino index 35df87d..40d4302 100644 --- a/status/status.ino +++ b/status/status.ino @@ -83,7 +83,7 @@ boolean transition() { if (state_previous == STATE_OFF && state_current == STATE_ON) { digitalWrite(LED_R, LOW); digitalWrite(LED_G, HIGH); - Serial.print("ON\n"); + printState(state_current); stateBegan = millis(); return true; } @@ -94,19 +94,19 @@ boolean transition() { if (state_previous == STATE_ON && state_current == STATE_HALF) { digitalWrite(LED_G, LOW); digitalWrite(LED_Y, HIGH); - Serial.print("HALF\n"); + printState(state_current); return true; } if (state_previous == STATE_ON && state_current == STATE_OFF) { digitalWrite(LED_G, LOW); digitalWrite(LED_R, HIGH); - Serial.print("OFF\n"); + printState(state_current); return true; } if (state_previous == STATE_HALF && state_current == STATE_OFF) { digitalWrite(LED_Y, LOW); digitalWrite(LED_R, HIGH); - Serial.print("OFF\n"); + printState(state_current); return true; } if (state_previous == STATE_HALF && state_current == STATE_ON) { @@ -119,24 +119,29 @@ boolean transition() { digitalWrite(LED_G, LOW); digitalWrite(LED_Y, LOW); digitalWrite(LED_R, HIGH); - Serial.print("OFF\n"); + printState(state_current); return true; } return false; } +// 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) { - switch (state_current) { - case STATE_OFF: - Serial.print("OFF\n"); - break; - case STATE_HALF: - Serial.print("HALF\n"); - break; - case STATE_ON: - Serial.print("ON\n"); - } + printState(state_current); do { delay(10); } while (Serial.read() != -1);