add licence

add volume control
This commit is contained in:
Martin Selbmann 2020-09-23 15:18:30 +02:00
parent 3d89f570c3
commit 5da67bc518
2 changed files with 54 additions and 21 deletions

View File

@ -1,4 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: Unlicense
folder="/mnt/video"
player="cvlc"
@ -6,8 +7,8 @@ playerparam="--play-and-exit --quiet --no-osd -A alsa --alsa-audio-device=front:
pgrepplayer="vlc"
swupgpio=23
swdowngpio=25
playerfull="$(command -v $player) $playerparam"
swupstat=$($(command -v gpio) read $swupgpio)
if [ $# -eq 0 ]; then
@ -20,7 +21,7 @@ if [ $# -gt 1 ]; then
exit 1
fi
if [ $swupstat -eq 1 ]; then
if [ "$swupstat" -eq 1 ]; then
exit 1
fi
@ -29,9 +30,9 @@ if [ "buzzer" != "$1" ] && [ "cron" != "$1" ]; then
exit 1
fi
if $(command -v pgrep) "$pgrepplayer" > /dev/null; then
if pgrep "$pgrepplayer" > /dev/null; then
if [ "$1" = "buzzer" ]; then
$(command -v pkill) "$pgrepplayer"
pkill "$pgrepplayer"
elif [ "$1" = "cron" ]; then
exit 1
@ -39,6 +40,6 @@ if $(command -v pgrep) "$pgrepplayer" > /dev/null; then
fi
else
$(command -v "$player") $playerparam "$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)" &
$playerfull "$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)" &
fi

View File

@ -1,52 +1,84 @@
#!/bin/sh
# SPDX-License-Identifier: Unlicense
buzzgpio=0
strobogpio=2
buzzergpio=0
strobegpio=2
swupgpio=23
swdowngpio=25
player="cvlc"
playerparam="--play-and-exit --quiet --no-osd -A alsa --alsa-audio-device=front:CARD=Device,DEV=0"
playerloop="--loop"
pgrepplayer="vlc"
pollingtime=0.05
buzzertimeout=2
strobeduration=1
volumetimeout=0.1
playerfull="$(command -v $player) $playerparam"
cmdgpio="$(command -v gpio)"
cmdamixer="$(command -v amixer)"
$cmdgpio mode $buzzgpio in
$cmdgpio mode $buzzergpio in
$cmdgpio mode $strobogpio out
$cmdgpio write $strobogpio 1
$cmdgpio mode $strobegpio out
$cmdgpio write $strobegpio 1
$cmdgpio mode $swdowngpio in
$cmdgpio mode $swupgpio in
volumevalue=0
$cmdamixer -q -c 2 sset 'Speaker' $volumevalue%
while true; do
buzzerstat="$($cmdgpio read $buzzgpio)"
buzzerstat="$($cmdgpio read $buzzergpio)"
swupstat="$($cmdgpio read $swupgpio)"
swdownstat="$($cmdgpio read $swdowngpio)"
if [ "$buzzerstat" -eq 0 ] && [ "$swupstat" -eq 0 ]; then
/home/pi/RandomVideo/RandomVideo.sh buzzer
$cmdgpio write $strobogpio 0; sleep 1; $cmdgpio write $strobogpio 1 &
sleep 1
~/RandomVideo/RandomVideo.sh buzzer
$cmdgpio write $strobegpio 0; sleep $strobeduration; $cmdgpio write $strobegpio 1 &
sleep $buzzertimeout
elif [ "$swupstat" -eq 1 ]; then
if $(command -v pgrep) "$pgrepplayer" > /dev/null; then
$(command -v pkill) "$pgrepplayer"
if pgrep "$pgrepplayer" > /dev/null; then
pkill "$pgrepplayer"
fi
$(command -v $player) $playerparam --loop ~/RandomVideo/onair.mp4 &
$playerfull $playerloop ~/RandomVideo/onair.mp4 &
while [ "$swupstat" -eq 1 ]; do
swupstat="$($cmdgpio read $swupgpio)"
sleep 0.1
sleep $pollingtime
done
$(command -v pkill) "$pgrepplayer"
pkill "$pgrepplayer"
elif [ "$volumevalue" -eq 0 ] && [ "$swdownstat" -eq 1 ]; then
while [ "$volumevalue" -lt "$volumemax" ] || [ "$buzzerstat" -eq 0 ]; do
volumevalue=$((volumevalue + 1))
$cmdamixer -q -c 2 sset 'Speaker' $volumevalue%
buzzerstat="$($cmdgpio read $buzzergpio)"
sleep $volumetimeout
done
elif [ "$volumevalue" -gt 0 ] && [ "$swdownstat" -eq 0 ]; then
while [ "$volumevalue" -gt 0 ] || [ "$swdownstat" -eq 1 ]; do
volumevalue=$((volumevalue -1))
$cmdamixer -q -c 2 sset 'Speaker' $volumevalue%
swdownstat="$($cmdgpio read $swdowngpio)"
sleep $volumetimeout
done
elif [ "$buzzerstat" -eq 1 ] && [ "$swupstat" -eq 0 ]; then
sleep 0.1
sleep $pollingtime
fi