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
Results 1 to 4 of 4
-
2019-11-16, 12:32 #1
- Join Date
- Dec 2009
- Posts
- 71
Knob - Volume - mouse scroll hack
-
2019-11-16, 14:48 #2
- Join Date
- Aug 2012
- Location
- Austria
- Posts
- 937
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 | ...
-
2019-11-17, 02:05 #3
- Join Date
- Dec 2009
- Posts
- 71
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!
TonyLast edited by Wiredcharlie; 2019-11-17 at 02:11.
-
2019-11-17, 12:18 #4
- Join Date
- Aug 2012
- Location
- Austria
- Posts
- 937
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
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 | ...