Greg Erskine wrote:
> Hi John,
>
> In this Pink Fish Media thread, Bemused wanted a automatic script that
> turned his amp on and off (after a delay) depending on whether
> Squeezelite was playing or not.
>
> http://www.pinkfishmedia.net/forum/showthread.php?t=165465
>
> Challenge: I think this could be modified to unmute/mute the IQaudIO
> amp.
>
> regards
> Greg
Greg,
I modified your script to allow unmuting/muting of the Pi-AMP and
extended it with one extra variable : FOLLOW_PLAYBACK_STATE.
If FOLLOW_PLAYBACK_STATE<>0 then the script will mute/unmute the amp
according to the playback state. If FOLLOW_PLAYBACK_STATE=0 then the
script will just unmute the amp and exit.
I tested this without any speakers attached but the mute status light on
the amp does reflect the playback state.
Code:
--------------------
#!/bin/sh
# Version: 0.01 2014-11-28 GE
# 2015-02-18 Adapted for Pi-AMP
#
#===========================================================================
# This script polls LMS at a regular interval to determine the current
# status of the Squeezelite process on piCorePlayer. i.e. play or stop.
#
# GPIO 22 is then set/reset depending on the result of this status check.
# This will unmute/mute the Pi-AMP accordingly.
#
# There is an adjustable mute delay that can be used as an inactivity
# timing.
#---------------------------------------------------------------------------
#===========================================================================
# Possible issues
#---------------------------------------------------------------------------
# 1. If setting MAC address manually, pay close attention to the physical,
# wireless and fake MAC addresses.
# 2. This script hasn't been tested on synced players.
#---------------------------------------------------------------------------
#===========================================================================
# Save script to /home/tc/piamp.sh
# Make script executable
#
## chmod +x /home/tc/piamp.sh
#
# Edit /opt/bootlocal.sh and add this script
#
## #!/bin/sh
## #put other system startup commands here
## #amixer cset numid=3 2
##
## #run Pi-AMP script
## sleep 5
## sudo /home/tc/piamp.sh > /dev/null &
##
## #mnt/mmcblk0p2/tce/OliWeb-master/ivySox/myweb/do_rebootstuff.sh
## /home/tc/www/cgi-bin/do_rebootstuff.sh
#
# Save changes to piCorePlayer
#
## sudo filetool.sh -b
#---------------------------------------------------------------------------
#===========================================================================
# Set the following according to your setup
#---------------------------------------------------------------------------
GPIO=22 # Set GPIO 22 for Pi-AMP
PI_MAC_ADDRESS=b8:27:eb:1c:62:19 # Raspberry Pi MAC address
LMS_IP_ADDRESS=192.168.0.200 # LMS IP address
LMS_CLI_PORT_NUMBER=9090 # LMS CLI port number
COMMAND="status 0 0" # LMS player status command
INTERVAL=0.5 # Set Poll interval
DELAY_OFF=10 # Delay in no. of intervals
FOLLOW_PLAYBACK_STATE=1 # If set to 0 this script will
just unmute and exit
COUNT=0
DEBUG=0
#---------------------------------------------------------------------------
if [ $DEBUG = 1 ]; then
echo
echo "GPIO : "$GPIO
echo "PI_MAC_ADDRESS : "$PI_MAC_ADDRESS
echo "LMS_IP_ADDRESS : "$LMS_IP_ADDRESS
echo "LMS_CLI_PORT_NUMBER : "$LMS_CLI_PORT_NUMBER
echo "COMMAND : "$COMMAND
echo "INTERVAL : "$INTERVAL
echo "DELAY_OFF : "$DELAY_OFF
echo "FOLLOW_PLAYBACK_STATE : "$FOLLOW_PLAYBACK_STATE
echo
fi
get_mode() {
RESULT=`( echo "$PI_MAC_ADDRESS $COMMAND"; echo exit ) | nc
$LMS_IP_ADDRESS $LMS_CLI_PORT_NUMBER`
echo $RESULT | grep "mode%3Aplay" > /dev/null 2>&1
if [ $? == 0 ]; then
COUNT=0
# unmute Pi-AMP
echo "1" > /sys/class/gpio/gpio$GPIO/value
echo "Playing. Count: $COUNT"
else
if [ $COUNT -ge $DELAY_OFF ]; then
# mute Pi-AMP
echo "0" > /sys/class/gpio/gpio$GPIO/value
COUNT=0
else
COUNT=$(($COUNT + 1))
echo "Stopped. Count: $COUNT"
fi
fi
}
#===========================================================================
# Initial GPIO setup
#---------------------------------------------------------------------------
sudo sh -c 'echo '"$GPIO"' > /sys/class/gpio/export'
sudo sh -c 'echo "out" > /sys/class/gpio/gpio'"$GPIO"'/direction'
#---------------------------------------------------------------------------
#===========================================================================
# main()
#---------------------------------------------------------------------------
if [ $FOLLOW_PLAYBACK_STATE = 0 ]; then
# unmute Pi-AMP, cleanup and exit
echo "1" > /sys/class/gpio/gpio$GPIO/value
sudo sh -c 'echo '"$GPIO"' > /sys/class/gpio/unexport'
exit
else
# Loop forever. This uses less then 1% CPU, so it should be OK.
while true
do
get_mode
sleep $INTERVAL
done
fi
#---------------------------------------------------------------------------
--------------------
------------------------------------------------------------------------
kolossos4730's Profile: http://forums.slimdevices.com/member.php?userid=63988
View this thread: http://forums.slimdevices.com/showthread.php?t=97803
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix