Skip to content

Commit

Permalink
new file: traits/audio/radio/files/usr/bin/sleeptimer
Browse files Browse the repository at this point in the history
modified:   traits/audio/radio/files/www/cgi-bin/radio
  • Loading branch information
probono committed Dec 26, 2013
1 parent c9eb69e commit 211f9e6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
36 changes: 36 additions & 0 deletions traits/audio/radio/files/usr/bin/sleeptimer
@@ -0,0 +1,36 @@
#!/bin/sh

# Find all PIDs of processes with the same name as myself
PIDS=$(echo $(pidof $(basename $0)))
echo $PIDS

# Find my PID
MYPID=$(echo $PIDS | cut -d " " -f 2)
echo $MYPID

# Kill all PIDs of processes with the name name that are not myself
for PID in $PIDS ; do
if [ "$PID" != "$MYPID" ] ; then
echo kill $PID
kill -9 $PID >/dev/null 2>&1
fi
done

# Not clean
killall sleep

# Calculate seconds
MINS=$(uci get radio.sleeptimer || echo 0)
if [ $MINS -gt 100 ] ; then
MINS=0
fi
NEWMINS=$(($MINS+15))
uci set radio.sleeptimer=$NEWMINS
NEWSECS=$(($NEWMINS*60))
speak "Schaltee ab in $NEWMINS Minuten"

# Sleep for certain time, then switch USB power off
# (if we have set up everything correctly, this stops playback
# and sends shutdown IR signal to external devices)
sleep $NEWSECS ; echo 0 > /sys/class/gpio/gpio8/value

43 changes: 29 additions & 14 deletions traits/audio/radio/files/www/cgi-bin/radio
Expand Up @@ -51,8 +51,6 @@ echo '

echo "<center><h1>$(uci get system.@system[0].hostname) &infin;</h1></center>"

echo '<div style="line-height: 350%; text-align: justify">'

# A search field
echo '
<div class="container">
Expand All @@ -72,30 +70,33 @@ echo '
'

# Some buttons
echo "
echo '
<center>
<div class=\"btn-group\">
<a href=\"?next\" class=\"btn btn-default btn-sm\" role=\"button\"><i class=\"fa fa-step-forward\"></i> Next</a>
<a href=\"?pause\" class=\"btn btn-default btn-sm\" role=\"button\"><i class=\"fa fa-pause\"></i> Pause</a>
<a href=\"?continue\" class=\"btn btn-default btn-sm\" role=\"button\"><i class=\"fa fa-play\"></i> Continue</a>
<a href=\"?mute\" class=\"btn btn-default btn-sm\" role=\"button\"><i class=\"fa fa-times-circle-o\"></i> Mute</a>
<a href=\"?unmute\" class=\"btn btn-default btn-sm\" role=\"button\"><i class=\"fa fa-times-circle-o\"></i> Unmute</a>
<div class="btn-group">
<a href="?next" class="btn btn-default btn-sm" role="button"><i class="fa fa-step-forward"></i> Next</a>
<a href="?pause" class="btn btn-default btn-sm" role="button"><i class="fa fa-pause"></i> Pause</a>
<a href="?continue" class="btn btn-default btn-sm" role="button"><i class="fa fa-play"></i> Continue</a>
<a href="?mute" class="btn btn-default btn-sm" role="button"><i class="fa fa-volume-off"></i> Mute</a>
<a href="?unmute" class="btn btn-default btn-sm" role="button"><i class="fa fa-bullhorn"></i> Unmute</a>
<a href="?voldown" class="btn btn-default btn-sm" role="button">&nbsp;<i class="fa fa-volume-down"></i>&nbsp;</a>
<a href="?volup" class="btn btn-default btn-sm" role="button">&nbsp;<i class="fa fa-volume-up"></i>&nbsp;</a>
</div>
</center>
<p></p>
"
'

echo '</div>'

# One button per station
echo '<center>'
STATIONS=$(uci show radio | grep "=station" | cut -d "=" -f 1 | cut -d "." -f 2)
COUNTER=0
for STATION in $STATIONS
do
let COUNTER=COUNTER+1
echo " <a href=\"?station="$COUNTER"\" class=\"btn\" role=\"button\">"$STATION"</a>"
echo " <a href=\"?station="$COUNTER"\">"$STATION"</a> |"
done

echo '</div>'

echo '</center>'

# Some debug output
# echo "<pre>"
Expand All @@ -111,6 +112,10 @@ for SONG in "sunchyme" "orinoco flow" "toto africa" "sunchyme" "wedding rain liz
"bolero ravel" "Tamee Harrison" ; do
echo '<a href="?song='$SONG'">'$SONG'</a> | '
done

echo '<p></p>'
echo '<p><a class="btn btn-default btn-sm" role="button" href="/cgi-bin/luci/">Settings</a></p>'
echo '<p><a href="https://github.com/probonopd/" target="_blank"><i class="fa fa-github"></i> Fork me on Github</a></p>'
echo "</center>"


Expand Down Expand Up @@ -177,6 +182,16 @@ if [ "$STRING" == "volume" ] ; then
amixer sset $SPEAKER $VOLUME% # This is DANGEROUS, what if some random rubbish is passed in?
fi

if [ "$STRING" == "voldown" ] ; then
SPEAKER=$(amixer scontrols | head -n 1 | cut -d "'" -f 2)
amixer set $SPEAKER 7dB-
fi

if [ "$STRING" == "volup" ] ; then
SPEAKER=$(amixer scontrols | head -n 1 | cut -d "'" -f 2)
amixer set $SPEAKER 7dB+
fi

if [ "$QUERY_STRING" == "mute" ] ; then
SPEAKER=$(amixer scontrols | head -n 1 | cut -d "'" -f 2)
amixer sset $SPEAKER '3%'
Expand Down

0 comments on commit 211f9e6

Please sign in to comment.