Difference between revisions of "Application note - Example code for capturing power button event on fitlet2 running Linux"
From fit-PC wiki
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | * This application note provides an example of how to capture a power button click event on Linux. | |
+ | * It has been tested with the below setup: | ||
+ | Device: fitlet2 | ||
+ | CPU: Intel(R) Atom(TM) Processor E3950 | ||
+ | BIOS: 09/17/2018 American Megatrends Inc. FLT2.0.46.01.00 | ||
+ | OS: Debian Buster (development) | ||
+ | Kernel: 4.13.0-1-amd64 | ||
+ | 1. Set BIOS -> Main -> OS selection to [Linux] | ||
+ | |||
+ | 2. Ignore power button handling provided by systemd, don't forget to reboot: | ||
+ | $ sudo sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.conf | ||
+ | $ sudo reboot | ||
+ | |||
+ | 3. Install ACPI related software if not installed yet: | ||
+ | $ sudo apt install acpi-support-base acpid | ||
+ | |||
+ | $ service acpid status | ||
+ | ● acpid.service - ACPI event daemon | ||
+ | Loaded: loaded (/lib/systemd/system/acpid.service; disabled; vendor preset: enabled) | ||
+ | Active: active (running) since Tue 2018-10-16 05:56:43 EDT; 1s ago | ||
+ | Main PID: 1754 (acpid) | ||
+ | Tasks: 1 (limit: 4915) | ||
+ | CGroup: /system.slice/acpid.service | ||
+ | └─1754 /usr/sbin/acpid | ||
+ | |||
+ | Oct 16 05:56:43 x86-atp-master systemd[1]: Started ACPI event daemon. | ||
+ | Oct 16 05:56:43 x86-atp-master acpid[1754]: starting up with netlink and the input layer | ||
+ | Oct 16 05:56:43 x86-atp-master acpid[1754]: 1 rule loaded | ||
+ | Oct 16 05:56:43 x86-atp-master acpid[1754]: waiting for events: event logging is off | ||
+ | |||
+ | 4. Verify acpi events are visible in the system, run acpi_listen tool and press power button 2-3 times: | ||
+ | $ acpi_listen | ||
+ | button/power PBTN 00000080 00000000 | ||
+ | button/power LNXPWRBN:00 00000080 00000007 | ||
+ | button/power PBTN 00000080 00000000 | ||
+ | button/power LNXPWRBN:00 00000080 00000008 | ||
+ | |||
+ | 5. Edit /etc/acpi/events/powerbtn-acpi-support: | ||
+ | event=power (PBTN) 00000080 | ||
+ | action=/etc/acpi/powerbtn-acpi-support-new.sh | ||
+ | |||
+ | 6. Create your custom script named /etc/acpi/powerbtn-acpi-support-new.sh: | ||
+ | #!/bin/sh | ||
+ | echo "Hello from PBTN!" > /dev/tty1 | ||
+ | |||
+ | 7. Make it executable | ||
+ | $ chmod +x /etc/acpi/powerbtn-acpi-support-new.sh | ||
+ | |||
+ | 8. Restart acpid service to activate the new functionality | ||
+ | $ service acpid restart | ||
+ | |||
+ | 9. Press power button shortly, you should see: | ||
+ | "Hello from PBTN!" on tty1 |
Revision as of 13:25, 16 October 2018
- This application note provides an example of how to capture a power button click event on Linux.
- It has been tested with the below setup:
Device: fitlet2 CPU: Intel(R) Atom(TM) Processor E3950 BIOS: 09/17/2018 American Megatrends Inc. FLT2.0.46.01.00 OS: Debian Buster (development) Kernel: 4.13.0-1-amd64
1. Set BIOS -> Main -> OS selection to [Linux]
2. Ignore power button handling provided by systemd, don't forget to reboot:
$ sudo sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.conf $ sudo reboot
3. Install ACPI related software if not installed yet:
$ sudo apt install acpi-support-base acpid
$ service acpid status ● acpid.service - ACPI event daemon Loaded: loaded (/lib/systemd/system/acpid.service; disabled; vendor preset: enabled) Active: active (running) since Tue 2018-10-16 05:56:43 EDT; 1s ago Main PID: 1754 (acpid) Tasks: 1 (limit: 4915) CGroup: /system.slice/acpid.service └─1754 /usr/sbin/acpid
Oct 16 05:56:43 x86-atp-master systemd[1]: Started ACPI event daemon. Oct 16 05:56:43 x86-atp-master acpid[1754]: starting up with netlink and the input layer Oct 16 05:56:43 x86-atp-master acpid[1754]: 1 rule loaded Oct 16 05:56:43 x86-atp-master acpid[1754]: waiting for events: event logging is off
4. Verify acpi events are visible in the system, run acpi_listen tool and press power button 2-3 times:
$ acpi_listen button/power PBTN 00000080 00000000 button/power LNXPWRBN:00 00000080 00000007 button/power PBTN 00000080 00000000 button/power LNXPWRBN:00 00000080 00000008
5. Edit /etc/acpi/events/powerbtn-acpi-support:
event=power (PBTN) 00000080 action=/etc/acpi/powerbtn-acpi-support-new.sh
6. Create your custom script named /etc/acpi/powerbtn-acpi-support-new.sh:
#!/bin/sh echo "Hello from PBTN!" > /dev/tty1
7. Make it executable
$ chmod +x /etc/acpi/powerbtn-acpi-support-new.sh
8. Restart acpid service to activate the new functionality
$ service acpid restart
9. Press power button shortly, you should see:
"Hello from PBTN!" on tty1