piradiobtn/btn_track_pi3.sh

47 lines
667 B
Bash
Raw Normal View History

2016-08-15 22:32:44 +02:00
#!/bin/bash
#Set GPIO ID with push button
GPIO_ID="24"
#Initialize GPIO
echo $GPIO_ID > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio$GPIO_ID/direction
#Start MPC
mpc clear
mpc load radios
mpc repeat on
mpc play
printf "MPC started"
2017-01-22 12:36:23 +01:00
2016-08-15 22:32:44 +02:00
i=0
echo "Loop check push"
while :
2016-08-15 22:32:44 +02:00
do
until /bin/grep 1 /sys/class/gpio/gpio$GPIO_ID/value >> /dev/null
do
/bin/sleep .1
2017-01-22 12:36:23 +01:00
i=0
done
2016-08-15 22:32:44 +02:00
2017-01-22 12:36:23 +01:00
echo i=$i
let i++
2017-01-22 12:36:23 +01:00
if [ $i -ge 3 ]
then
printf "Shutdown by button"
sudo systemctl poweroff
break
fi
2016-08-15 22:32:44 +02:00
2017-01-22 12:36:23 +01:00
if [ $i -ge 1 ]
then
echo "Next Track"
mpc next
/bin/sleep .5
fi
2016-08-15 22:32:44 +02:00
done
2017-01-22 12:36:23 +01:00