festival-daemon/festivald.sh

97 lines
1.6 KiB
Bash
Raw Normal View History

2021-04-04 22:30:03 +00:00
#!/bin/bash
SERIAL=/dev/ttyUSB0
VOLUME_CONTROL="Line Out"
RADIO1_URL="http://us2.internet-radio.com:8443/stream"
RADIO2_URL="https://rozhlas.stream/ddur_mp3_128.mp3"
RADIO3_URL="https://rozhlas.stream/brno_mp3_128.mp3"
#https://rozhlas.stream/radiozurnal_aac_128.aac
RADIO4_URL="https://ice3.abradio.cz/croretro128.mp3"
killStream() {
kill `ps aux | grep "$1" | awk '{print $2}'` 2>/dev/null
}
playStream() {
mplayer "$1" </dev/null >/dev/null 2>&1 &
}
handleStream() {
STREAM=$1
STATE=$2
#killStream "$STREAM"
if [ $STATE = 1 ]; then
playStream "$STREAM"
echo "Started radio: $STREAM"
else
echo "Stopped radio: $STREAM"
fi
}
execVolume() {
VOLUME_RAW=`echo "scale=4; $1/255*100" | bc`
VOLUME=`printf "%.0f%%" "$VOLUME_RAW"`
amixer sset "$VOLUME_CONTROL" "$VOLUME" >/dev/null &
echo Volume set to $VOLUME
#echo Volume set to $1
}
execButton() {
case $1 in
1)
handleStream "$RADIO1_URL" "$2"
;;
2)
handleStream "$RADIO2_URL" "$2"
;;
3)
handleStream "$RADIO3_URL" "$2"
;;
4)
handleStream "$RADIO4_URL" "$2"
;;
*)
echo "Unknown button '$1'." >&2
;;
esac
}
process_event() {
case $1 in
volume)
execVolume "$2"
;;
button*)
NUM=`echo $1 | tr -dc [:digit:]`
execButton "$NUM" "$2"
;;
"")
;;
*)
echo "Unknown event '$1'." >&2
;;
esac
}
consume_events() {
while true; do
IFS=$'\r'= read EVENT VALUE
if [ $? == 0 ]; then
#echo EVENT: $EVENT = $VALUE
process_event "$EVENT" "$VALUE"
else
echo Invalid input. >&2
fi
done
}
2021-04-04 22:47:36 +00:00
stty -F $SERIAL 9600 cs8 -cstopb -parenb
2021-04-04 22:30:03 +00:00
cat $SERIAL | consume_events