Udev Power Supply Behavior

Hello! I was looking into writing some udev rules to trigger whenever my a311d Pocket Reform is unplugged or charging, something like the following:

SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_STATUS}=="Charging", RUN+="/usr/bin/bash -c 'printf xLRGB\\x00\\x30\\x30 > /dev/hidraw0'"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_STATUS}=="Disharging", RUN+="/usr/bin/bash -c 'printf xLRGB\\x00\\x00\\x00 > /dev/hidraw0'"

I realized this only triggers once, when the device is powered on. It does correctly trigger according to the power supply status at boot, but never triggers again.

I noticed that sudo udevadm monitor doesn’t show Charging/Discharging changes. I tried this on another computer (a laptop with acpi) and there is a Change event every time it unplugs. There is also an “AC” device (/sys/class/power_supply/AC) created or destroyed respectively every time the device is plugged in or unplugged.

This is a bug in reform2-lpc, right? My suspicion is that it is because power_supply_changed never gets called in that driver but I’m not sure. Does anyone know of a simple power supply driver to crib from? (The acpi driver is quite complicated.)

1 Like