From 590fcb0e918970e9d3de4161f930b07e9526d0ff Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 28 Jan 2018 17:03:12 +0100 Subject: [PATCH] 'view gpio' + disp-led + disp-relay --- ioemu/src/disp-led | 21 ++++++++++++++++ ioemu/src/disp-relay | 19 +++++++++++++++ ioemu/sub-view/gpio | 58 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100755 ioemu/src/disp-led create mode 100755 ioemu/src/disp-relay create mode 100755 ioemu/sub-view/gpio diff --git a/ioemu/src/disp-led b/ioemu/src/disp-led new file mode 100755 index 0000000..b9b4a49 --- /dev/null +++ b/ioemu/src/disp-led @@ -0,0 +1,21 @@ +#!/bin/bash + + +# (1) Declare association state <-> color_id +#--------------------------------------------------------# +# (1) Create associative array # +declare -A COLCODE; + +# (2) States # +COLCODE[0]=90; +COLCODE[R]=31; +COLCODE[G]=32; +COLCODE[B]=34; + +# (2) Check argument + display led +#--------------------------------------------------------# +# (1) Check argument # +test $# -ge 1 && state="$1" || state="0"; + +# (2) Display led # +echo -e "\e[${COLCODE[$state]}m⬤\e[0m"; \ No newline at end of file diff --git a/ioemu/src/disp-relay b/ioemu/src/disp-relay new file mode 100755 index 0000000..4e76594 --- /dev/null +++ b/ioemu/src/disp-relay @@ -0,0 +1,19 @@ +#!/bin/bash + + +# (1) Declare association state <-> color_id +#--------------------------------------------------------# +# (1) Create associative array # +declare -A COLCODE; + +# (2) States # +COLCODE[0]=90; +COLCODE[1]=32; + +# (2) Check argument + display led +#--------------------------------------------------------# +# (1) Check argument # +test $# -ge 1 && state="$1" || state="0"; + +# (2) Display led # +echo -e "\e[${COLCODE[$state]}m⏺\e[0m"; \ No newline at end of file diff --git a/ioemu/sub-view/gpio b/ioemu/sub-view/gpio new file mode 100755 index 0000000..5c43bb6 --- /dev/null +++ b/ioemu/sub-view/gpio @@ -0,0 +1,58 @@ +#!/bin/bash + + +# (1) Primary init. +#--------------------------------------------------------# +# (1) Get absolute folder # +ROOT=$(dirname `realpath $0`); +ROOT=`dirname $ROOT`; + +# (2) Check lock file # +test ! -f $ROOT/.lock && echo "Daemon not started" && exit 1; + + + +# (2) While viewing loop +#--------------------------------------------------------# +# (1) Initialise vars # +BUFFER=""; +LED="0"; Rx=(0 0 0); # led; relays +SYSTD_TREE=""; # service_log + + +while sleep 2; clear; do + + # (1) Read buffer into local one (but without flushing buffers) # + BUFFER="$BUFFER`$ROOT/com/read ioemu -`"; + + # (2) Parse each line # + line_id=0; + + while IFS= read -r line; do + + # check if line is about GSTA + if [ "${line:0:4}" = "GSTA" ]; then + test "${line:4:1}" != "x" && LED="${line:4:1}"; # if set to 'x', ignore + test "${line:5:1}" != "x" && Rx[1]="${line:5:1}"; # if set to 'x', ignore + test "${line:6:1}" != "x" && Rx[2]="${line:6:1}"; # if set to 'x', ignore + test "${line:7:1}" != "x" && Rx[3]="${line:7:1}"; # if set to 'x', ignore + + BUFFER=""; # empty buffer + break; + fi; + + # increment line count + line_id=`expr $line_id + 1`; + + done <<< "$BUFFER"; + + + # (3) Display led # + echo -n "LED: "; $ROOT/src/disp-led $LED; + + # (4) Display relays # + echo -n "R1: "; $ROOT/src/disp-relay ${Rx[1]}; + echo -n "R2: "; $ROOT/src/disp-relay ${Rx[2]}; + echo -n "R3: "; $ROOT/src/disp-relay ${Rx[3]}; + +done; \ No newline at end of file