I have an input class device (accelerometer) bound to a driver which exposes sysfs attributes that I need to access from userland. Using a udev rule, I have provided an alias that unambiguously identifies my device, i.e.
ll /dev/input yields:
lrwxrwxrwx 1 root root 6 May 18 13:47 accelerometer0 -> event0 drwxr-xr-x 2 root root 60 May 18 13:47 by-path crw-rw---- 1 root input 13, 64 May 18 13:47 event0 crw-rw---- 1 root input 13, 65 May 18 13:47 event1 crw-rw---- 1 root input 13, 66 May 18 13:47 event2
So far, so good: I can
open("/dev/input/accelerometer0") in my userland code and start streaming the data. But to, for example, change the data rate, I need to write to the
pollrate_ms attribute in the related sysfs directory. An
ls /sys/class/input/ yields:
event0 event1 event2 input0 input1 input2
I happen to know that
pollrate_ms resides in
input0/device, but I need to figure this out programatically, especially since future updates might cause that numbering to change.
I know that I can use
libudev to enumerate
/sys/class/input and then use a for loop to explore each of those directories until I find the one containing
pollrate_ms. It just seems like that's a lot of work compared to how easy it was to unambiguously identify the device via a udev rule.
Am I missing out on an easy way or should I just suck it up?