Improved script:
Code:
--------------------
#!/bin/bash
#use command - xinput - to find id of mouse who's scroll wheel you want to use
mouseID=" USB OPTICAL MOUSE"
player="Dining Room"
IP="127.0.0.1 9090"
#Button inactive after press registered - tenths of sec
locktime=10
#Ratio of mouse scroll value to volume change - sensitivity
gear=2
#Press Commands
Long="playlist play Radio2"
Short="playlist play Radio4"
Double="playlist play RadioCornwall"
#Need to convert player name to mac address
#find number of players
nplayers=$(echo "player count ?" | nc -q1 $IP | tail -c 2 )
n=0
#loop through players to determine mac address of player
while [ $n -lt $nplayers ]
do
pmac=$(printf "player id $n ?\nexit\n" | nc $IP | tail -c 28 |
sed -r 's/%3A/:/g' )
pname=$(printf "player name $n ?\nexit\n" | nc $IP | cut -c 15-
| sed -r 's/%20/ /g')
pmode=$(printf "$pmac mode ?\nexit\n" | nc $IP | cut -c 34-37)
if [ "$pname" = "$player" ]; then
playerID=$pmac
echo
echo "$pname" "$pmac" "$pmode"
fi
n=$(($n + 1))
done
echo
MouseState=$(xinput --query-state "$mouseID")
OldScroll="${MouseState#*valuator\[2\]\=}"
scroll=$OldScroll
echo "Initial scroll wheel position: $OldScroll"
playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 3 |
tr -dc '0-9')
echo "Initial Volume: $playerVOL"
echo
pressed=0
loop=0
lockout=0
# Infinite loop checks to see if mouse scroll wheel has turned and in which
direction - Ctrl C to quit
while :
do
loop=$((loop + 1))
lockout=$((lockout - 1))
if [ $lockout -eq 0 ]; then
echo Unlocked
fi
MouseState=$(xinput --query-state "$mouseID")
scroll="${MouseState#*valuator\[2\]\=}"
playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 4 |
tr -dc '0-9')
#Long press Playlist
#Short pressPause
#echo $loop
#echo press: $pressed
#echo lockout: $lockout
if [ $lockout -lt 0 ]; then
if [[ $MouseState == *"down"* ]]; then
pressed=$((pressed + 1))
if [[ $pressed -eq 1 ]]; then
loop=1
fi
if [[ $pressed -gt 1 ]] && [[ $pressed -ne $loop ]]; then
pressed=0
loop=0
lockout=$locktime
if [ $loop -lt 5 ]; then
printf "$playerID $Double\nexit\n" | nc
$IP
echo Double Press
fi
fi
if [[ $pressed -gt 4 ]] && [[ $pressed -eq $loop ]];then
printf "$playerID $Long\nexit\n" | nc $IP
echo Long Press
pressed=0
loop=0
lockout=$locktime
fi
fi
if [[ $loop -gt 6 ]] && [[ $pressed -lt 5 ]] && [[ $pressed -gt 0 ]];
then
printf "$playerID $Short\nexit\n" | nc $IP
echo Short Press
pressed=0
loop=0
lockout=$locktime
fi
fi
#Volume
delta=$((scroll - OldScroll))
if [ $delta -ne 0 ]; then
echo Read Vol: $playerVOL Scroll: $scroll
if [ $delta -lt "-25" -o $delta -gt 25 ]; then
echo "Scroll value implausible!"
else
if [ $delta -gt 0 ]; then
pmode=$(printf "$playerID mode ?\nexit\n" | nc $IP |
cut -c 34-37)
if [[ $pmode == *"stop"* ]]; then
printf "$playerID play\nexit\n" | nc
$IP
printf "$playerID mixer volume
10\nexit\n" | nc $IP
playerVOL=10
sleep 2
fi
if [ $playerVOL -lt 96 ]; then
setVOL=$((playerVOL + delta*gear))
printf "$playerID mixer volume
$setVOL\nexit\n" | nc $IP
fi
fi
if [ $delta -lt 0 ]; then
if [ $playerVOL -gt 0 ]; then
setVOL=$((playerVOL + delta*gear))
if [ $setVOL -lt 0 ]; then
setVOL=0
fi
printf "$playerID mixer volume $setVOL\nexit\n" | nc
$IP
#Power off player when volume gets to zero
if [ $setVOL -eq 0 ]; then
printf "$playerID power 0\nexit\n" | nc $IP
echo Volume Zero Off
sleep 10
echo unlocked
fi
fi
fi
fi
fi
OldScroll=$scroll
sleep 0.1
done
--------------------
------------------------------------------------------------------------
Wiredcharlie's Profile: http://forums.slimdevices.com/member.php?userid=35115
View this thread: http://forums.slimdevices.com/showthread.php?t=111225
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix