Difference between revisions of "Application note - Example code for capturing power button event on fitlet2 running Linux"
From fit-PC wiki
Line 1: | Line 1: | ||
* This application note provides an example of how to capture a power button click event on Linux. | * 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: | * It has been tested with the below setup: | ||
− | + | <pre> | |
− | + | 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 | ||
+ | </pre> | ||
− | + | == 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): | |
+ | <pre> | ||
+ | $ su - | ||
+ | Password: | ||
+ | </pre> | ||
− | + | * Ignore power button events handling by systemd, then reboot: | |
− | + | <pre> | |
+ | sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.conf | ||
+ | reboot | ||
+ | <pre> | ||
+ | |||
+ | * Install ACPI related software if not installed yet: | ||
+ | <pre> | ||
+ | $ 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) | Loaded: loaded (/lib/systemd/system/acpid.service; disabled; vendor preset: enabled) | ||
− | Active: active (running) since | + | Active: active (running) since Wed 2018-10-17 03:53:36 EDT; 29s ago |
− | Main PID: | + | Main PID: 919 (acpid) |
− | Tasks: 1 (limit: | + | Tasks: 1 (limit: 4389) |
+ | Memory: 280.0K | ||
CGroup: /system.slice/acpid.service | CGroup: /system.slice/acpid.service | ||
− | + | └─919 /usr/sbin/acpid | |
− | + | Oct 17 03:53:36 x86-atp-master systemd[1]: Started ACPI event daemon. | |
− | + | Oct 17 03:53:36 x86-atp-master acpid[919]: starting up with netlink and the input layer | |
− | + | Oct 17 03:53:36 x86-atp-master acpid[919]: 1 rule loaded | |
− | + | Oct 17 03:53:36 x86-atp-master acpid[919]: waiting for events: event logging is off | |
+ | </pre> | ||
− | + | * Verify acpi events are visible in the system, run acpi_listen command and press power button 2-3 times: | |
− | + | <pre> | |
− | + | $ acpi_listen | |
− | + | button/power PBTN 00000080 00000000 | |
− | + | button/power LNXPWRBN:00 00000080 00000007 | |
− | + | button/power PBTN 00000080 00000000 | |
+ | button/power LNXPWRBN:00 00000080 00000008 | ||
+ | </pre> | ||
+ | NOTE: current power button handler is /etc/acpi/powerbtn-acpi-support.sh, but it does not work for some reason | ||
− | + | * Create custom power button event rule: | |
− | + | <pre> | |
− | + | $ cat > /etc/acpi/events/powerbtn-custom-rule << EOF | |
+ | event=power (PBTN) 00000080 | ||
+ | action=/etc/acpi/powerbtn-custom-handler.sh | ||
+ | EOF | ||
+ | </pre> | ||
− | + | * Create custom power button event handler and make it executable: | |
− | + | <pre> | |
− | + | $ 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 | |
− | + | </pre> | |
− | + | * Restart acpid service to activate the new functionality: | |
− | + | <pre> | |
+ | $ service acpid restart | ||
+ | </pre> | ||
− | + | * Press power button shortly, you should see "Hello from PBTN!" on the main console | |
− | + |
Revision as of 08:24, 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 <pre> * Install ACPI related software if not installed yet: <pre> $ 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 Wed 2018-10-17 03:53:36 EDT; 29s ago Main PID: 919 (acpid) Tasks: 1 (limit: 4389) Memory: 280.0K CGroup: /system.slice/acpid.service └─919 /usr/sbin/acpid Oct 17 03:53:36 x86-atp-master systemd[1]: Started ACPI event daemon. Oct 17 03:53:36 x86-atp-master acpid[919]: starting up with netlink and the input layer Oct 17 03:53:36 x86-atp-master acpid[919]: 1 rule loaded Oct 17 03:53:36 x86-atp-master acpid[919]: waiting for events: event logging is off
- 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: current power button handler is /etc/acpi/powerbtn-acpi-support.sh, but it does not work for some reason
- Create custom power button event rule:
$ cat > /etc/acpi/events/powerbtn-custom-rule << EOF event=power (PBTN) 00000080 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