Add a hid-feature tool to query and set feature reports
The motivation here is being able to quickly debug some devices in the hope of narrowing it down where the bug comes from. Examples are:
- the case where the resolution multiplier gets reset after a device-internal suspend, running this tool would verify that resetting the RM changes the wheel speed back to normal
- easier debugging of vendor-specific protocols, "lets see what happens if we set field X to Y"
- that touchpad (forgot the bug number) where the HID report showed a single bit to toggle and it may have switched the touchpad into a more meaningful behaviour
I was hoping this would also let me play with my Kogan keyboard LEDs, but so far all I get from it is EPIPE. It does work for my MS Sculpt receiver though.
This is obv. a debugging tool, I'm not intending this to have some sort of stable CLI that users can hook up through scripts.
From the top commit message:
Example usage to change the second Resolution Multiplier here:
$ hid-feature list --fetch-values /dev/hidraw1
Feature | Report | Usage Page | Usage | Range | Count | Bits | Value(s)
--------|--------|---------------------------|--------------------------------------------|-----------|-------|------|---------
120000 | 18 | Generic Desktop | Resolution Multiplier | [ 0, 1] | 1 | 2 | 1
120001 | 18 | Generic Desktop | Resolution Multiplier | [ 0, 1] | 1 | 2 | 1
120002 | 18 | Generic Desktop | Undefined | [ 0, 1] | 1 | 4 | 0
170000 | 23 | Vendor Defined Page 1 | 0xff00ff06 | [ 0, 1] | 1 | 2 | 1
$ hid-feature set --feature 120000 1 --feature 120001 0 /dev/hidraw1
$ hid-feature list --fetch-values /dev/hidraw1
Feature | Report | Usage Page | Usage | Range | Count | Bits | Value(s)
--------|--------|---------------------------|--------------------------------------------|-----------|-------|------|---------
120000 | 18 | Generic Desktop | Resolution Multiplier | [ 0, 1] | 1 | 2 | 1
120001 | 18 | Generic Desktop | Resolution Multiplier | [ 0, 1] | 1 | 2 | 0
120002 | 18 | Generic Desktop | Undefined | [ 0, 1] | 1 | 4 | 0
170000 | 23 | Vendor Defined Page 1 | 0xff00ff06 | [ 0, 1] | 1 | 2 | 1
Where the --fetch-values
is omitted during list
, the device is never accessed.
The feature index is a simple value based on the report ID and the index of
the feature within that report, this gives it a unique-enough ID that we can
then pass into hid-feature set
.
Setting the actual feature takes a tuple of the id and the new value
(e.g. --feature 120001 0
). This won't work for items that have a count != 1
but we can deal with that when we need to.