'view gpio' + disp-led + disp-relay

This commit is contained in:
xdrm-brackets 2018-01-28 17:03:12 +01:00
parent dbed7e5692
commit 590fcb0e91
3 changed files with 98 additions and 0 deletions

21
ioemu/src/disp-led Executable file
View File

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

19
ioemu/src/disp-relay Executable file
View File

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

58
ioemu/sub-view/gpio Executable file
View File

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