zynq_7010/zynq_7010_code/countdown.sh

48 lines
1.1 KiB
Bash
Raw Normal View History

2023-07-17 03:29:37 +00:00
#!/bin/sh
# A countdown timer
# GNU GPLv3
value_num=$#
HOU=$2
MIN=$3
SEC=$4
start(){
# If there are 3 arguments given, they become H, M, and S. Otherwise, the user is asked
if [ $HOU -eq 0 ] && [ $MIN -eq 0 ] && [ $SEC -eq 0 ] ; then
HOU=0
MIN=30
SEC=0
fi
if [ $SEC -lt 60 ] ; then
SEC=60
fi
# Convert input to seconds
TIMER=$(( ($HOU*3600) + ($MIN*60) + $SEC ))
# Count down and output remaining time to temp file
while [ $TIMER -gt 0 ]
do
#printf "%02dh:%02dm:%02ds\n" $((TIMER/3600)) $((TIMER%3600/60)) $((TIMER%60))
printf "%02d:%02d:%02d\n" $((TIMER/3600)) $((TIMER%3600/60)) $((TIMER%60))
sleep 10
TIMER=$(( TIMER - 10 ))
done
if [ $SEC -gt 0 ] ; then
sh /mnt/flash-disk/low_power.sh 1
2023-07-17 03:29:37 +00:00
fi
}
stop(){
echo "timer need to be killed"
}
if [ "$1" != "" ]; then
case $1 in
start|stop) "$1" ;;
esac
fi