#!/bin/bash
#IO INTIIALIZATION
tshwctl --setdio=65 #System Power ON
tshwctl --clrdio=57 #red OFF
tshwctl --clrdio=59 #yellow OFF
tshwctl --clrdio=61 #Green OFF
#CTRL+C Trap_EXIT_EXEC
trap ctrl_c INT
#trap 'tshwctl --clrdio=65' EXIT
function ctrl_c() {
#TURN OFF ALL IO
tshwctl --clrdio=57
tshwctl --clrdio=59
tshwctl --clrdio=61
tshwctl --clrdio=65
echo "** PROGRAM TERMINATED **"
exit
}
#MAIN Loop
for i in $(seq 0 1000)
do
reading=$(./adc1)
#echo $reading
if [ $reading -lt 300 ]
then
clear
echo "System Nominal"
tshwctl --clrdio=59
tshwctl --clrdio=57
tshwctl --setdio=61 #green ON
#Compund logical expansion in BASH
elif [[ $reading -gt 301 && $reading -lt 1000 ]];
then
tshwctl --clrdio=57 #red OFF
clear
echo "Intermediate Voltage Detected"
tshwctl --setdio=59 #yellow ON
tshwctl --setdio=61 #green ON
elif [[ $reading -gt 1001 && $reading -lt 2000 ]];
then
clear
echo "Median Voltage Detected"
tshwctl --clrdio=57 #red OFF
tshwctl --clrdio=61 #green OFF
tshwctl --setdio=59 #yellow ON
elif [ $reading -gt 2000 ]
then
clear
echo "Alert! HIGH VOLTAGE DETECTED!"
tshwctl --clrdio=61 #green OFF
tshwctl --clrdio=59 #yellow OFF
tshwctl --setdio=57 #Red ON
else
tshwctl --clrdio=61
tshwctl --clrdio=59
tshwctl --clrdio=57
fi
#sleep 1
done
#END LOOP ALL IO IS OFF
tshwctl --clrdio=57
tshwctl --clrdio=59
tshwctl --clrdio=61
tshwctl --clrdio=65