Changes

Jump to: navigation, search
* 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:
<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 (developmenttesting) Kernel: 4.1316.0-12-amd641. Set BIOS ISO: debian-> Main buster-DI-alpha3-amd64-netinst.iso</pre> OS selection to [Linux]
2. Ignore power button handling provided by systemd, don't forget to reboot== fitlet2:required BIOS settings == $ sudo sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.confPress [Delete] button after power-on to enter BIOS settings $ sudo reboot* Set BIOS -> Main -> OS selection to [Linux]
3. Install ACPI related software if not installed yet== Configure power button event handling ==* Login as root user (root password required): <pre>$ sudo apt install acpisu -support-base acpidPassword:</pre>
* Ignore power button events handling by systemd, then reboot:<pre>sed -i s/".*HandlePowerKey.*"/"HandlePowerKey=ignore"/ /etc/systemd/logind.confreboot<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 Tue Wed 2018-10-16 0517 03:5653:43 36 EDT; 1s 29s ago Main PID: 1754 919 (acpid) Tasks: 1 (limit: 49154389) Memory: 280.0K
CGroup: /system.slice/acpid.service
└─1754 └─919 /usr/sbin/acpid
Oct 16 0517 03:5653:43 36 x86-atp-master systemd[1]: Started ACPI event daemon. Oct 16 0517 03:5653:43 36 x86-atp-master acpid[1754919]: starting up with netlink and the input layer Oct 16 0517 03:5653:43 36 x86-atp-master acpid[1754919]: 1 rule loaded Oct 16 0517 03:5653:43 36 x86-atp-master acpid[1754919]: waiting for events: event logging is off</pre>
4. * Verify acpi events are visible in the system, run acpi_listen tool 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
5. Edit * Create custom power button event rule:<pre>$ cat > /etc/acpi/events/powerbtn-acpicustom-support:rule << EOF event=power (PBTN) 00000080 action=/etc/acpi/powerbtn-acpicustom-support-newhandler.shEOF</pre>
6. * Create your custom script named power button event handler and make it executable:<pre>$ cat > /etc/acpi/powerbtn-acpi-supportcustom-newhandler.sh:<< EOF #!/bin/sh echo "Hello from PBTN!" > /dev/tty1EOF
7. Make it executable $ chmod +x /etc/acpi/powerbtn-acpicustom-support-newhandler.sh</pre>
8. * Restart acpid service to activate the new functionality:<pre> $ service acpid restart</pre>
9. * Press power button shortly, you should see: "Hello from PBTN!" on tty1the main console
425
edits