Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6334

Advanced users • Re: Pi 5 PWR button as multi-function button?

$
0
0
https://github.com/librerpi/rpi-tools/b ... oxy/main.c

Code:

  int fd = open("/dev/input/event0", O_RDWR);    int ret = ioctl(fd, EVIOCGRAB, (void*)1);        struct input_event ev[64];      int rd = read(events[i].data.fd, ev, sizeof(ev));
if you open an event device with the GRAB flag set, then the events dont go to any other application, so you can get exclusive use of the button

Code:

root@raspberrypi:~# ls -l /dev/input/by-path/platform-pwr_button-event lrwxrwxrwx 1 root root 9 Apr 16 09:17 /dev/input/by-path/platform-pwr_button-event -> ../event0
then you just need to find the right path to the power button, likely this symlink

and now its up to your application to issue a shutdown on double-click

the only issue for the power button, is that the firmware will issue an improper shutdown if you hold the button for a few seconds, so beware of that

Statistics: Posted by cleverca22 — Wed Apr 30, 2025 12:12 am



Viewing all articles
Browse latest Browse all 6334

Trending Articles