Compare commits

..

No commits in common. "main" and "main" have entirely different histories.
main ... main

10 changed files with 22 additions and 256 deletions

View File

@ -1,47 +0,0 @@
# RandomVideo
* shell scripts to play a random video
* polls big button (buzzer) in left of lounge door
* polls 2-way-switch left from big button (buzzer)
## Usage instructions
### Buzzer commands
* button press (2s delay between presses) start or stop video
* switch up turns on "On Air"-mode (stops video and doesn't open new videos, button locked)
* switch down turns sound on, volume rises slowly and can be stopped with button press
* turn switch back from down to center position slowly decreases volume, it can be stopped when switch turned down again
## Install instructions
### crontab entries
* */15 * * * * cd ~/RandomVideo; ~/RandomVideo/RandomVideo.sh cron
* @reboot cd ~/RandomVideo; ~/RandomVideo/buzzer.sh & pid=$!; while ! ping -c1 git.chch.it>/dev/null; do sleep 1; done; git -C ~/RandomVideo/ pull; kill -9 $pid; ~/RandomVideo/buzzer.sh
### fstab entries
* UUID=DAE9-9682 /mnt/video vfat defaults,users,ro 0 1
## Filelist
### RandomVideo.sh
* Plays a random video file
### buzzer.sh
* polls buzzer and 2-way-switch
* volume control
* controls video playback
* controls "On Air"-mode
### onair.mp4
* placeholder videofile for "On Air"-Message
### config.json
* configfile with all config parameters
### volumetest.sh
* testscript for ramping soundcard output volume
* reads volume value from amixer
* not a necessary file
### Bild
![Chaostreff Gang Buzzer](chch_gang_buzzer.JPG)
## Licence
* All stuff in this repo is licenced under Unlicence.
* current onair.mp4 is excluded and a placeholder!

View File

@ -1,56 +1,26 @@
#!/bin/sh
# SPDX-License-Identifier: Unlicense
configfile="config.json"
if [ -z "$(command -v jq)" ]; then
echo "Missing \"jq\"!"
exit 1
fi
if [ -z "$(command -v gpio)" ]; then
echo "Missing \"gpio\"!"
echo "This is a part of WiringPi-Package."
exit 1
fi
player="$(jq -r ".player" < $configfile)"
if [ -z "$(command -v $player)" ]; then
echo "Missing \"$player\"!"
exit 1
fi
folder=/mnt/video
player=omxplayer
if [ $# -eq 0 ]; then
echo "Missing parameter!"
echo "Parameter fehlt"
exit 1
fi
if [ $# -gt 1 ]; then
echo "To much parameters!"
echo "Zu viele Parameter"
exit 1
fi
if [ "buzzer" != "$1" ] && [ "cron" != "$1" ]; then
echo "parameters must be \"buzzer\" or \"cron\"!"
echo "Parameter muss \"buzzer\" oder \"cron\" sein"
exit 1
fi
swupstat="$(gpio read $swupgpio)"
if [ "$swupstat" -eq 1 ]; then
exit 1
fi
folder="$(jq -r ".RandomVideo | .folder" < $configfile)"
playerparam="$(jq -r ".playerparam" < $configfile)"
pgrepplayer="$(jq -r ".pgrepplayer" < $configfile)"
swupgpio="$(jq -r ".swupgpio" < $configfile)"
playerfull="$(command -v $player) $playerparam"
if pgrep "$pgrepplayer" > /dev/null; then
if $(command -v pgrep) "$player" > /dev/null; then
if [ "$1" = "buzzer" ]; then
pkill "$pgrepplayer"
$(command -v pkill) "$player"
elif [ "$1" = "cron" ]; then
exit 1
@ -58,6 +28,6 @@ if pgrep "$pgrepplayer" > /dev/null; then
fi
else
$playerfull "$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)" &
$(command -v "$player") "$(find "$folder" -maxdepth 1 -type f |sort -R |head -n1)" &
fi

View File

@ -1,24 +0,0 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

104
buzzer.sh
View File

@ -1,106 +1,20 @@
#!/bin/sh
# SPDX-License-Identifier: Unlicense
configfile="config.json"
# set gpio number
gpio=0
if [ -z "$(command -v jq)" ]; then
echo "Missing \"jq\"!"
exit 1
fi
if [ -z "$(command -v gpio)" ]; then
echo "Missing \"gpio\"!"
echo "This is a part of WiringPi-Package."
exit 1
fi
player="$(jq -r ".player" < $configfile)"
if [ -z "$(command -v $player)" ]; then
echo "Missing \"$player\"!"
exit 1
fi
buzzergpio="$(jq -r ".buzzer | .buzzergpio" < $configfile)"
strobegpio="$(jq -r ".buzzer | .strobegpio" < $configfile)"
swupgpio="$(jq -r ".swupgpio" < $configfile)"
swdowngpio="$(jq -r ".buzzer | .swdowngpio" < $configfile)"
playerparam="$(jq -r ".playerparam" < $configfile)"
playerloop="$(jq -r ".buzzer | .playerloop" < $configfile)"
pgrepplayer="$(jq -r ".pgrepplayer" < $configfile)"
pollingtime="$(jq -r ".buzzer | .pollingtime" < $configfile)"
buzzertimeout="$(jq -r ".buzzer | .buzzertimeout" < $configfile)"
strobeduration="$(jq -r ".buzzer | .strobeduration" < $configfile)"
volumetimeout="$(jq -r ".buzzer | .volumetimeout" < $configfile)"
volumedelay="$(jq -r ".buzzer | .volumedelay" < $configfile)"
volumemax="$(jq -r ".buzzer | .volumemax" < $configfile)"
playerfull="$(command -v $player) $playerparam"
gpio mode $buzzergpio in
gpio mode $strobegpio out
gpio write $strobegpio 1
gpio mode $swdowngpio in
gpio mode $swupgpio in
volumevalue=0
amixer -q -c 2 sset 'Speaker' $volumevalue%
$(command -v gpio) mode IN $gpio
while true; do
buzzerstat="$(gpio read $buzzergpio)"
swupstat="$(gpio read $swupgpio)"
swdownstat="$(gpio read $swdowngpio)"
buzzerstat="$($(command -v gpio) read $gpio)"
if [ "$buzzerstat" -eq 0 ] && [ "$swupstat" -eq 0 ]; then
~/RandomVideo/RandomVideo.sh buzzer
gpio write $strobegpio 0; sleep $strobeduration; gpio write $strobegpio 1 &
sleep $buzzertimeout
if [ "$buzzerstat" -eq 0 ]; then
/home/pi/RandomVideo/RandomVideo.sh buzzer
sleep 5
elif [ "$swupstat" -eq 1 ]; then
if pgrep "$pgrepplayer" > /dev/null; then
pkill "$pgrepplayer"
fi
$playerfull $playerloop ~/RandomVideo/onair.mp4 &
while [ "$swupstat" -eq 1 ]; do
swupstat="$(gpio read $swupgpio)"
sleep $pollingtime
done
pkill "$pgrepplayer"
elif [ "$volumevalue" -eq 0 ] && [ "$swdownstat" -eq 1 ]; then
while [ "$volumevalue" -lt "$volumemax" ] && [ "$buzzerstat" -eq 1 ]; do
volumevalue=$((volumevalue + 1))
amixer -q -c 2 sset 'Speaker' $volumevalue%
buzzerstat="$(gpio read $buzzergpio)"
sleep $volumetimeout
done
sleep $volumedelay
elif [ "$volumevalue" -gt 0 ] && [ "$swdownstat" -eq 0 ]; then
while [ "$volumevalue" -gt 0 ] && [ "$swdownstat" -eq 0 ]; do
volumevalue=$((volumevalue -1))
amixer -q -c 2 sset 'Speaker' $volumevalue%
swdownstat="$(gpio read $swdowngpio)"
sleep $volumetimeout
done
sleep $volumedelay
elif [ "$buzzerstat" -eq 1 ] && [ "$swupstat" -eq 0 ]; then
sleep $pollingtime
elif [ "$buzzerstat" -eq 1 ]; then
sleep 0.1
fi

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

View File

@ -1,21 +0,0 @@
{
"swupgpio": "23",
"player": "cvlc",
"playerparam": "--play-and-exit --quiet --no-osd -A alsa --alsa-audio-device=front:CARD=Device,DEV=0",
"pgrepplayer": "vlc",
"buzzer": {
"buzzergpio": "0",
"buzzertimeout": "2",
"pollingtime": "0.05",
"strobegpio": "2",
"strobeduration": "1",
"swdowngpio": "25",
"playerloop": "--loop",
"volumetimeout": "0.1",
"volumedelay": "0.1",
"volumemax": "60"
},
"RandomVideo": {
"folder": "/mnt/video"
}
}

4
crontab Normal file
View File

@ -0,0 +1,4 @@
# user: pi
*/15 * * * * /home/pi/RandomVideo/RandomVideo.sh cron
@reboot /home/pi/RandomVideo/buzzer.sh &

1
fstab Normal file
View File

@ -0,0 +1 @@
/dev/sda1 /mnt/video vfat defaults,users,ro 0 1

BIN
onair.mp4

Binary file not shown.

View File

@ -1,31 +0,0 @@
#!/bin/sh
# SPDX-License-Identifier: Unlicense
volumevalue=$(amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }' | tr -d '%')
timeout=$1
if [ -z "$timeout" ]; then
echo "Timeout missing!"
exit 1
fi
if [ "$volumevalue" -eq 0 ]; then
while [ "$volumevalue" -lt 100 ]; do
volumevalue=$((volumevalue + 1))
amixer -q sset 'Master' $volumevalue%
echo $volumevalue
sleep $timeout
done
elif [ "$volumevalue" -gt 0 ]; then
while [ "$volumevalue" -gt 0 ]; do
volumevalue=$((volumevalue - 1 ))
amixer -q sset 'Master' $volumevalue%
echo $volumevalue
sleep $timeout
done
fi