Resurrecting The Griffin PowerMate on Linux: Part 2, as a Service

See also: Resurrecting The Griffin PowerMate on Linux, about starting work with this device.

I'm going to outline how I currently have this set up on Debian 12 Linux. With the following files in place, the Powermate works to control MPD on a remote machine using the mpc client software. And all that's required is you plug it in. I'll outline the setup in its entirety, and explain after. This all needs to be done as root, and requires the evtest utility.

Add /root/bin/powermate-mpc:

#!/bin/bash
# https://m0aws.co.uk/?p=2201 (GO: 2023-11-08)
devName="/dev/input/by-id/usb-Griffin_Technology__Inc._Griffin_PowerMate-event-if00"
/usr/bin/evtest ${devName} | while read LINE
do
    case $LINE in
        *"(REL_DIAL), value 1") echo "clock" ;;
        *"(REL_DIAL), value -1") echo "counter" ;;
        *"(BTN_0), value 1") echo "click" ;;
    esac
done

Add /etc/systemd/system/powermate.service:

[Service]
Type=simple
Restart=no
ExecStart=/root/bin/powermate-mpc

[Install]
WantedBy=default.target
WantedBy=sys-devices-pci0000:00-0000:00:14.0-usb1-1\x2d1-1\x2d1.4:1.0.device

Then nail them together with a udev rule, /etc/udev/rules.d/10-local-powermate.rules:

SUBSYSTEMS=="input" \
, ACTION=="add" \
, ATTR{id/vendor}=="077d" \
, ATTR{id/product}=="0410" \
, TAG+="systemd" \
, ENV{SYSTEMD_WANTS}+="powermate.service"

Run udevadm control --reload. You should also run systemctl daemon-reload.

At this point, your Powermate should "just work" once plugged in.

Explanation

See Resurrecting The Griffin PowerMate on Linux for an explanation of the Bash script at the core of this. You can rename it or move it as you see fit, but you'll need to correct the reference to the script in the service file.

The SystemD service file is fairly straight-forward. You can call it what you want, but you'd have to update the udev rule to reference the new name. What wasn't straight-forward was figuring out the WantedBy line. The AskUbuntu link in the Bibliography showed an example of this, but no explanation of how it got that line. I extrapolated ... a lot. udevadm monitor gave the device name as /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.4/1-1.4:1.0 - which will probably be the same for you? I hope so, because otherwise you'll have to dig out that device name, then: turn every "-" into a "x2d", then (order is important because we have overlapping character sets) turn every "/" into a "-", except for the very first one, which you drop, and then finally add ".device" on the end. I don't understand this ... but I did make it work. (Some further testing shows the service doesn't work without the "devices" WantedBy, but I've changed it from ending in ".device" to ending in "-device" and it works either way ...)

The final piece is the udev rule. This is similar to what I did previously to identify the device, but now I've added , TAG+="systemd" \ (not sure that's needed, haven't tested without it) and , ENV{SYSTEMD_WANTS}+="powermate.service" which triggers the start of the service file.

Please read the caveats in the previous blog entry about the Griffin Powermate: using evtest to do this is hacky. Incredibly useful, but somewhat dubious.