setup/ioemu/sub-view/gpio

50 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-01-28 16:03:12 +00:00
#!/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 #
LED="0"; Rx=(0 0 0); # led; relays
SYSTD_TREE=""; # service_log
2018-01-28 16:16:54 +00:00
# (2) Get BUF_IN #
source $ROOT/com/config_ioemu;
2018-01-28 16:03:12 +00:00
2018-01-28 16:16:54 +00:00
while sleep 2; clear; do
2018-01-28 16:03:12 +00:00
2018-01-28 16:16:54 +00:00
# (3) Get last value from lines beginning by 'GSTA' #
STATE="`cat $BUF_IN | grep -Po "^GPIO(.+)$" | sed 's/^GPIO\(....\)$/\1/g' | tail -n1`";
2018-01-28 16:03:12 +00:00
2018-01-28 16:16:54 +00:00
echo "state: $STATE";
2018-01-28 16:03:12 +00:00
2018-01-28 16:16:54 +00:00
# (4) Apply to values if not 'x' (means 'ignore' that chip) #
if [ ! -z "$STATE" ]; then
2018-01-28 16:03:12 +00:00
2018-01-28 16:16:54 +00:00
test "${STATE:0:1}" != "x" && LED="${STATE:0:1}"; # if set to 'x', ignore
test "${STATE:1:1}" != "x" && Rx[1]="${STATE:1:1}"; # if set to 'x', ignore
test "${STATE:2:1}" != "x" && Rx[2]="${STATE:2:1}"; # if set to 'x', ignore
test "${STATE:3:1}" != "x" && Rx[3]="${STATE:3:1}"; # if set to 'x', ignore
2018-01-28 16:03:12 +00:00
2018-01-28 16:16:54 +00:00
fi;
2018-01-28 16:03:12 +00:00
2018-01-28 16:16:54 +00:00
# (5) Display led #
2018-01-28 16:03:12 +00:00
echo -n "LED: "; $ROOT/src/disp-led $LED;
2018-01-28 16:16:54 +00:00
# (6) Display relays #
2018-01-28 16:03:12 +00:00
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;