95 lines
2.4 KiB
Bash
Executable File
95 lines
2.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
vars="/home/pi/birdcam/vars"
|
|
|
|
gpiocmd="$(command -v gpio)"
|
|
|
|
if [ -z "$gpiocmd" ]; then
|
|
echo "Command gpio missing, try to install ..."
|
|
|
|
echo "Check internet connection ..."
|
|
pingserver="$(cat $vars | grep pingserver | cut -d'=' -f2)"
|
|
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="$(cat $vars | grep gpio_sw | cut -d'=' -f2)"
|
|
gpiopin_led_r="$(cat $vars | grep gpio_led_r | cut -d'=' -f2)"
|
|
gpiopin_led_g="$(cat $vars | grep gpio_led_g | cut -d'=' -f2)"
|
|
|
|
|
|
cameracmd="$(cat $vars | grep camerash | cut -d'=' -f2)"
|
|
|
|
buttonpolling="$(cat $vars | grep buttonpolling | cut -d'=' -f2)"
|
|
buttontimeout="$(cat $vars | grep buttontimeout | cut -d'=' -f2)"
|
|
countermax="$(cat $vars | grep countermax | cut -d'=' -f2)"
|
|
|
|
$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="$(cat $vars | grep camparamr | cut -d'=' -f2)"
|
|
$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="$(cat $vars | grep camparam1 | cut -d'=' -f2)"
|
|
$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="$(cat $vars | grep camparam2 | cut -d'=' -f2)"
|
|
$cameracmd $camname &
|
|
echo "$camname started!"
|
|
sleep $buttontimeout
|
|
|
|
done
|