Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 4 of 4
  1. #1

    Knob - Volume - mouse scroll hack

    Here is a shell script that takes input from the mouse scroll wheel to change the volume of the named local player. I wrote it with a view to hacking a Poundland mouse plus rotary encoder to put a real volume knob on my LMS / Squeezebox computer. I would welcome any comments or suggestions.
    Code:
    #!/bin/bash
    
    #use command - xinput - to find id of mouse who's scroll wheel you want to use
    mouseID=10 
    player='Dining Room'
    IP="127.0.0.1 9090"
    
    
    
    
      #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=$(echo "player id $n ?" | nc -q1 $IP | tail -c 28 | sed -r 's/%3A/:/g' )
    		pname=$(echo "player name $n ?" | nc -q1 $IP | cut -c 15- | sed -r 's/%20/ /g')
    			if [ "$pname" = "$player" ]; then
    				playerID=$pmac
    				echo
    				echo "$pname"   "$pmac"
    			fi
    		n=$(($n + 1))
    	done
    
    echo
    OldScroll=$(xinput --query-state $mouseID | grep 'valuator\[2\]\=' | cut -c 14-)
    echo "Initial wheel position: $OldScroll"
    playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 3 | tr -dc '0-9')
    echo "Initial Volume: $playerVOL"
    echo
    
    # Infinite loop checks to see if mouse scroll wheel has turned and in which direction - Ctrl C to quit
    
    while :
    do
    
    scroll=$(xinput --query-state $mouseID | grep 'valuator\[2\]\=' | cut -c 14-)
    
    if [ $OldScroll -gt $scroll ]; then
    	playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 3 | tr -dc '0-9')
    	setVOL=`expr $playerVOL + 5`
    	printf "$playerID mixer volume $setVOL\nexit\n" | nc $IP
    fi
    
    if [ $scroll -gt $OldScroll ]; then
    	playerVOL=$(printf "$playerID mixer volume ?\nexit\n" | nc $IP | tail -c 3 | tr -dc '0-9')
    	setVOL=`expr $playerVOL - 5`
    	printf  "$playerID mixer volume $setVOL\nexit\n" | nc $IP
    fi
      
    OldScroll=$scroll  
    sleep 0.2
    
    done

  2. #2
    Senior Member
    Join Date
    Aug 2012
    Location
    Austria
    Posts
    927
    Quote Originally Posted by Wiredcharlie View Post
    Here is a shell script that takes input from the mouse scroll wheel to change the volume of the named local player. I wrote it with a view to hacking a Poundland mouse plus rotary encoder to put a real volume knob on my LMS / Squeezebox computer. I would welcome any comments or suggestions.
    This might be of interest.
    Various SW: Web Interface | Playlist Editor / Generator | Music Classification | Similar Music | Announce | EventTrigger | LMSlib2go | ...
    Various HowTos: build a self-contained LMS | Bluetooth/ALSA | Control LMS with any device | ...

  3. #3
    Quote Originally Posted by Roland0 View Post
    This might be of interest.
    From what I can see that is button/keypress only. The point (for me) is to have the rotation of a traditional volume knob that properly interfaces with the LMS volume setting. Most of the Human Interface Device implementations I could find used a programmed microcontroller to provide a USB interface. I figured that looked like hard work when a mouse scroll wheel already does that! Then I stumbled across this https://19max63.wordpress.com/2016/0...-knob-for-sdr/
    where someone had connected a standard rotary encoder to a mouse PCB.

    My server is a headless MiniATX box which also provides a local player output, so I figured if I added a volume knob on the front it would look like a piece of HiFi!

    Tony
    Last edited by Wiredcharlie; Yesterday at 02:11.

  4. #4
    Senior Member
    Join Date
    Aug 2012
    Location
    Austria
    Posts
    927
    Quote Originally Posted by Wiredcharlie View Post
    From what I can see that is button/keypress only.
    It uses python-evdev, which is a interface to evdev and reports all device events (X uses evdev as well btw). Haven't tested it with inputexec, but this works:

    Code:
    #!/usr/bin/env python3
    import evdev
    device = evdev.InputDevice('/dev/input/event10')
    print(device)
    for event in device.read_loop():
    	if event.code == evdev.ecodes.REL_WHEEL:
    		print("Event: {} value: {}".format( evdev.categorize(event), event.value))
    Code:
    device /dev/input/event10, name "Logitech USB Laser Mouse", phys "usb-0000:00:1d.0-1.6/input0"
    Event: relative axis event at 1574017671.107975, REL_WHEEL  value: -1
    Event: relative axis event at 1574017672.227968, REL_WHEEL  value: 1
    so you could just add a line to send something (e.g. with requests) to LMS in that if clause

    Anyway, I've switched to triggerhappy in the meantime, which will also work with the wheel:
    Code:
    $  cat ../THD.conf
    REL_WHEEL	1	echo "wheel up" >> /tmp/thd.log
    REL_WHEEL	-1	echo "wheel down" >> /tmp/thd.log
    Code:
    ./thd --triggers ../THD.conf /dev/input/event10
    Executing trigger action: echo "wheel down" >> /tmp/thd.log
    Executing trigger action: echo "wheel up" >> /tmp/thd.log
    Various SW: Web Interface | Playlist Editor / Generator | Music Classification | Similar Music | Announce | EventTrigger | LMSlib2go | ...
    Various HowTos: build a self-contained LMS | Bluetooth/ALSA | Control LMS with any device | ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •