93 lines
2.4 KiB
Bash
Executable File
93 lines
2.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
gpiocmd="$(command -v gpio)"
|
|
|
|
if [ -z "$gpiocmd" ]; then
|
|
echo "Command gpio missing, try to install ..."
|
|
|
|
echo "Check internet connection ..."
|
|
pingserver="raspbian.raspberrypi.org" ### var: pingcheck destination
|
|
if ! ping -q -c1 $pingserver>/dev/null; then
|
|
echo "No internet connection ..."
|
|
exit 0
|
|
fi
|
|
|
|
wget https://project-downloads.drogon.net/wiringpi-latest.deb
|
|
sudo dpkg -i wiringpi-latest.deb
|
|
rm wiringpi-latest.deb
|
|
|
|
# sudo apt update; sudo apt -y install wiringpi
|
|
|
|
gpiocmd="$(command -v gpio)"
|
|
if [ -z "$gpiocmd" ]; then
|
|
echo "cannot install wiringpi, exiting ..."
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
gpiopin_sw="0" ### var: gpio switch
|
|
gpiopin_led_r="2" ### var: gpio led red
|
|
gpiopin_led_g="29" ### var: gpio led green
|
|
|
|
|
|
cameracmd="/home/pi/birdcam/view_birdcam.sh" ### var: path to player script
|
|
|
|
buttonpolling="0.05" ### var: button polling in seconds
|
|
buttontimeout="1" ### var: button timeout in seconds
|
|
countermax="1200" ### var: counter max for automatic switching (countermax=time/buttonpolling)
|
|
|
|
$gpiocmd mode $gpiopin_led_g out
|
|
$gpiocmd write $gpiopin_led_g 0
|
|
|
|
while true; do
|
|
|
|
counter="0"
|
|
$gpiocmd mode $gpiopin_led_r out
|
|
$gpiocmd write $gpiopin_led_g 1
|
|
while [ "$($gpiocmd read $gpiopin_sw)" -eq "1" ] && [ "$counter" -lt "$countermax" ]; do
|
|
counter="$(($counter + 1))"
|
|
#echo "$counter"
|
|
sleep $buttonpolling
|
|
done
|
|
|
|
$gpiocmd write $gpiopin_led_g 0
|
|
$gpiocmd mode $gpiopin_led_r in
|
|
camname="random" ### var: parameter for random video
|
|
$cameracmd $camname &
|
|
echo "$camname started!"
|
|
sleep $buttontimeout
|
|
|
|
counter="0"
|
|
$gpiocmd mode $gpiopin_led_r out
|
|
$gpiocmd write $gpiopin_led_g 1
|
|
while [ "$($gpiocmd read $gpiopin_sw)" -eq "1" ] && [ "$counter" -lt "$countermax" ]; do
|
|
counter="$(($counter + 1))"
|
|
#echo "$counter"
|
|
sleep $buttonpolling
|
|
done
|
|
|
|
$gpiocmd write $gpiopin_led_g 0
|
|
$gpiocmd mode $gpiopin_led_r in
|
|
camname="birdcam1" ### var: parameter for camera 1
|
|
$cameracmd $camname &
|
|
echo "$camname started!"
|
|
sleep $buttontimeout
|
|
|
|
counter="0"
|
|
$gpiocmd mode $gpiopin_led_r out
|
|
$gpiocmd write $gpiopin_led_g 1
|
|
while [ "$($gpiocmd read $gpiopin_sw)" -eq "1" ] && [ "$counter" -lt "$countermax" ]; do
|
|
counter="$(($counter + 1))"
|
|
#echo "$counter"
|
|
sleep $buttonpolling
|
|
done
|
|
|
|
$gpiocmd write $gpiopin_led_g 0
|
|
$gpiocmd mode $gpiopin_led_r in
|
|
camname="birdcam2" ### var: parameter for camera 2
|
|
$cameracmd $camname &
|
|
echo "$camname started!"
|
|
sleep $buttontimeout
|
|
|
|
done
|