From ebced6fe183db5051c9e8484998fe477ec5a3805 Mon Sep 17 00:00:00 2001 From: Dejvino Date: Sun, 4 Apr 2021 22:30:03 +0000 Subject: [PATCH] Initial commit --- festivald.sh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 festivald.sh diff --git a/festivald.sh b/festivald.sh new file mode 100755 index 0000000..320f98f --- /dev/null +++ b/festivald.sh @@ -0,0 +1,95 @@ +#!/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 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 +} + +cat $SERIAL | consume_events +