I am running Raspbian Lite on a Raspberry Pi Zero. It has a touch sensitive LCD display. I have a (perl) program that reads touch events from /dev/input/event* and responds appropriately.
The problem I have is that the event file name sometimes flips between /dev/input/event0 and event1 after a reboot. Both files always exist.
Why does it do that? What sets the filename that is used?
Is there any way that I can detect which file is "active"? (There are no events on the other filename as far as I can tell.)
2
Answers
Look for the presence of a directory named /dev/input/by-path or /dev/input/by-id. Inside these directories there will be links to your hardware that will persist across boot cycles.
The
N
ineventN
is assigned chronologically by the kernel and is therefore non-deterministic. It’s not a reliable way to read from a specific device, even if it appears to always be the same, if for example a newer kernel changes the loading order. Always use/dev/input/by-path
or/dev/input/by-id
when available.However you may notice that not all
eventN
files have a corresponding entry in/dev/input/by-path
or/dev/input/by-id
. For example, you might not be able to find a symlink for your power button. In such cases, there is also the file/proc/bus/input/devices
, in which you can find an entry for every input device. And in theHandlers=
line you should be able to findeventN
, corresponding to/dev/input/eventN
. It seems like there an entry for every/dev/input/eventN
, at least in my testing.