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