Difference between revisions of "Application note - Example code for capturing power button event on fitlet2 running Linux"
From fit-PC wiki
(→Configure power button event handling) (change visibility) |
(→Configure power button event handling) (change visibility) |
||
Line 23: | Line 23: | ||
* Ignore power button events handling by systemd, then reboot: | * Ignore power button events handling by systemd, then reboot: | ||
<pre> | <pre> | ||
− | sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.conf | + | $ sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.conf |
− | reboot | + | $ reboot |
</pre> | </pre> | ||
− | * Install ACPI related software | + | * Install ACPI related software: |
<pre> | <pre> | ||
$ apt install acpi-support-base acpid | $ apt install acpi-support-base acpid | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</pre> | </pre> | ||
Line 54: | Line 40: | ||
button/power LNXPWRBN:00 00000080 00000008 | button/power LNXPWRBN:00 00000080 00000008 | ||
</pre> | </pre> | ||
− | NOTE: current power button handler is /etc/acpi/powerbtn-acpi-support.sh, but it does not work for some reason | + | NOTE #1: current power button handler is /etc/acpi/powerbtn-acpi-support.sh, but it does not work for some reason |
+ | NOTE #2: there are 2 events PBTN and LNXPWRBN, we need to handle only one of them, for example PBTN | ||
* Create custom power button event rule: | * Create custom power button event rule: | ||
<pre> | <pre> | ||
$ cat > /etc/acpi/events/powerbtn-custom-rule << EOF | $ cat > /etc/acpi/events/powerbtn-custom-rule << EOF | ||
− | event=power (PBTN) | + | event=power (PBTN) |
action=/etc/acpi/powerbtn-custom-handler.sh | action=/etc/acpi/powerbtn-custom-handler.sh | ||
EOF | EOF |
Latest revision as of 08:34, 17 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 (testing) Kernel: 4.16.0-2-amd64 ISO: debian-buster-DI-alpha3-amd64-netinst.iso
fitlet2: required BIOS settings
- Press [Delete] button after power-on to enter BIOS settings
- Set BIOS -> Main -> OS selection to [Linux]
Configure power button event handling
- Login as root user (root password required):
$ su - Password:
- Ignore power button events handling by systemd, then reboot:
$ sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.conf $ reboot
- Install ACPI related software:
$ apt install acpi-support-base acpid
- Verify acpi events are visible in the system, run acpi_listen command 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
NOTE #1: current power button handler is /etc/acpi/powerbtn-acpi-support.sh, but it does not work for some reason
NOTE #2: there are 2 events PBTN and LNXPWRBN, we need to handle only one of them, for example PBTN
- Create custom power button event rule:
$ cat > /etc/acpi/events/powerbtn-custom-rule << EOF event=power (PBTN) action=/etc/acpi/powerbtn-custom-handler.sh EOF
- Create custom power button event handler and make it executable:
$ cat > /etc/acpi/powerbtn-custom-handler.sh << EOF #!/bin/sh echo "Hello from PBTN!" > /dev/tty1 EOF $ chmod +x /etc/acpi/powerbtn-custom-handler.sh
- Restart acpid service to activate the new functionality:
$ service acpid restart
- Press power button shortly, you should see "Hello from PBTN!" on the main console