poll_button.sh uses vars-file

This commit is contained in:
mmaster 2021-09-23 21:59:31 +02:00
parent 7dc083541e
commit ac917260c8
2 changed files with 25 additions and 11 deletions

View File

@ -1,12 +1,14 @@
#!/bin/sh #!/bin/sh
vars="/home/pi/birdcam/vars"
gpiocmd="$(command -v gpio)" gpiocmd="$(command -v gpio)"
if [ -z "$gpiocmd" ]; then if [ -z "$gpiocmd" ]; then
echo "Command gpio missing, try to install ..." echo "Command gpio missing, try to install ..."
echo "Check internet connection ..." echo "Check internet connection ..."
pingserver="raspbian.raspberrypi.org" ### var: pingcheck destination pingserver="$(cat $vars | grep pingserver | cut -d'=' -f2)"
if ! ping -q -c1 $pingserver>/dev/null; then if ! ping -q -c1 $pingserver>/dev/null; then
echo "No internet connection ..." echo "No internet connection ..."
exit 0 exit 0
@ -25,16 +27,16 @@ if [ -z "$gpiocmd" ]; then
fi fi
fi fi
gpiopin_sw="0" ### var: gpio switch gpiopin_sw="$(cat $vars | grep gpio_sw | cut -d'=' -f2)"
gpiopin_led_r="2" ### var: gpio led red gpiopin_led_r="$(cat $vars | grep gpio_led_r | cut -d'=' -f2)"
gpiopin_led_g="29" ### var: gpio led green gpiopin_led_g="$(cat $vars | grep gpio_led_g | cut -d'=' -f2)"
cameracmd="/home/pi/birdcam/view_birdcam.sh" ### var: path to player script cameracmd="$(cat $vars | grep camerash | cut -d'=' -f2)"
buttonpolling="0.05" ### var: button polling in seconds buttonpolling="$(cat $vars | grep buttonpolling | cut -d'=' -f2)"
buttontimeout="1" ### var: button timeout in seconds buttontimeout="$(cat $vars | grep buttontimeout | cut -d'=' -f2)"
countermax="1200" ### var: counter max for automatic switching (countermax=time/buttonpolling) countermax="$(cat $vars | grep countermax | cut -d'=' -f2)"
$gpiocmd mode $gpiopin_led_g out $gpiocmd mode $gpiopin_led_g out
$gpiocmd write $gpiopin_led_g 0 $gpiocmd write $gpiopin_led_g 0
@ -52,7 +54,7 @@ while true; do
$gpiocmd write $gpiopin_led_g 0 $gpiocmd write $gpiopin_led_g 0
$gpiocmd mode $gpiopin_led_r in $gpiocmd mode $gpiopin_led_r in
camname="random" ### var: parameter for random video camname="$(cat $vars | grep camparamr | cut -d'=' -f2)"
$cameracmd $camname & $cameracmd $camname &
echo "$camname started!" echo "$camname started!"
sleep $buttontimeout sleep $buttontimeout
@ -68,7 +70,7 @@ while true; do
$gpiocmd write $gpiopin_led_g 0 $gpiocmd write $gpiopin_led_g 0
$gpiocmd mode $gpiopin_led_r in $gpiocmd mode $gpiopin_led_r in
camname="birdcam1" ### var: parameter for camera 1 camname="$(cat $vars | grep camparam1 | cut -d'=' -f2)"
$cameracmd $camname & $cameracmd $camname &
echo "$camname started!" echo "$camname started!"
sleep $buttontimeout sleep $buttontimeout
@ -84,7 +86,7 @@ while true; do
$gpiocmd write $gpiopin_led_g 0 $gpiocmd write $gpiopin_led_g 0
$gpiocmd mode $gpiopin_led_r in $gpiocmd mode $gpiopin_led_r in
camname="birdcam2" ### var: parameter for camera 2 camname="$(cat $vars | grep camparam2 | cut -d'=' -f2)"
$cameracmd $camname & $cameracmd $camname &
echo "$camname started!" echo "$camname started!"
sleep $buttontimeout sleep $buttontimeout

12
vars
View File

@ -12,3 +12,15 @@ usbdevice=sda1
# check_playerproc.sh # check_playerproc.sh
gpio_led_b=28 gpio_led_b=28
# poll_button.sh
gpio_sw=0
gpio_led_r=2
gpio_led_g=29
camerash=/home/pi/birdcam/view_birdcam.sh
buttonpolling=0.05
buttontimeout=1
countermax=1200
camparamr=random
camparam1=birdcam1
camparam2=birdcam2