OpenWrt/MightyOhm Wifi Radio
< OpenWrt
OpenWrt
interface.sh
#! /bin/sh - # interface.sh - Wifi Radio User Interface Script # 01/29/09 Jeff Keyzer http://mightyohm.com # # This shell script sets up a playlist in mpd and changes playlist entries # based on the position of a tuner knob connected to an AVR on the router's # serial port. # # The script expects the AVR to send data at 9600 baud (8N1) to the router, # in the format "tuner: value", one line at a time. # # This script also launches display.sh, the LCD display script. # # For more information, visit # http://mightyohm.com/blog/tag/wifiradio/ # # This work is protected by the # Creative Commons Attribution-Share Alike 3.0 United States License. # http://creativecommons.org/licenses/by-sa/3.0/us/ # Some configuration settings VOLUME=60 STATIONS=10 MAXADC=1024 ADCBIN=$(expr "(" $MAXADC / $STATIONS ")" + 1) trap 'kill $! ; exit 1' SIGINT # exit on ctrl-c, useful for debugging # kills the display.sh process before exiting stty 9600 -echo < /dev/tts/0 # set serial port to 9600 baud # so we can talk to the AVR # turn off local echo to make TX/RX directions # completely separate from each other # mpd setup mpc volume $VOLUME # adjust this to suit your speakers/amplifier mpc clear # clear current playlist # build a playlist, substitute your favorite radio stations here # the first line becomes station #1, and so on. mpc add http://relay3.slayradio.org:8000/ # Slay Radio mpc add http://scfire-dtc-aa01.stream.aol.com:80/stream/1046 # KCRW Simulcast mpc add http://208.101.28.234:8004 # Bassdrive mpc add http://205.188.215.232:8016 # di.fm Soulful House mpc add http://scfire-ntc-aa03.stream.aol.com:80/stream/1009 # di.fm Lounge mpc add http://205.188.215.225:8002 # di.fm Breaks mpc add http://scfire-ntc-aa03.stream.aol.com:80/stream/1025 # di.fm Electro House mpc add http://di-fm-01.quintex.com:8888 # di.fm NYC Exposure mpc add http://208.122.59.30:7234 # di.fm Future Synthpop mpc add http://scfire-mtc-aa03.stream.aol.com:80/stream/1026 # di.fm Progressive mpc playlist # show the resulting playlist oldstation=0 # var to keep track of what station we're playing # Tell the AVR we're ready to start doing stuff echo "AVR Start!\n" > /dev/tts/0 # launch LCD display routines in the background /root/display2.sh & while true # loop forever do inputline="" # clear input # Loop until we get a valid tuner position from the AVR until inputline=$(echo $inputline | grep -e "^tuner: ") do inputline=$(head -n 1 < /dev/tts/0) done value=$(echo $inputline | sed 's/tuner: //') # strip out the tuner: part #echo "$value" # compute playlist positon based on tuner value # the tuner range is 0 to MAXADC # the ADC range is separated into equally sized bins, each bin # is one station # station ends up being an integer from 1 to STATIONS # that determines what station to play station=$(expr $value / $ADCBIN + 1) # if station has changed, we need to change position in the playlist if [ "$station" -ne "$oldstation" ] then echo "Tuner Position: " $value echo "New station..." mpc play $station fi oldstation=$station # remember what station we're on so we know # if we need to change stations next time around done