Jump to content

HID buttons: Difference between revisions

From postmarketOS Wiki
HID_buttons: initial page creation
 
update to gitlab.postmarketos.org
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Introduction ==
Phones may have some buttons. Those buttons can be configured to execute specific command when pressed.
Phones may have some buttons. Those buttons can be configured to execute specific command when pressed.


== Getting input device information using udevadm ==
== Getting input device information using udevadm ==


Make sure that buttons are recognized as eventX inside /dev/input directory
Make sure that buttons are recognized as eventX inside <code>/dev/input</code> directory


To make sure that the input buttons are recognized, run the following command
To make sure that the input buttons are recognized, run the following command:


<code># udevadm info -a /dev/input/event0 </code>
<syntaxhighlight lang='shell-session'>$ udevadm info -a /dev/input/event0 </syntaxhighlight>


The command will print udev properties which can be used to assign udev rules, for example tagging specified device as touchscreen.
The command will print udev properties which can be used to assign udev rules, for example tagging specified device as touchscreen.
Line 29: Line 28:


== Using triggerhappy to handle HID input events ==
== Using triggerhappy to handle HID input events ==
{{note|Triggerhappy has been replaced with [https://gitlab.postmarketos.org/postmarketOS/hkdm HKDM]}}


Triggerhappy can be used to handle HID input device. To install triggerhappy, fetch the initial pull request for triggerhappy.
=== Installation ===
Triggerhappy can be used to handle HID input device. After postmarketOS is installed, add it with:


<code>$ cd $PMBOOTSTRAP # the directory where pmbootstrap git source code is laying around </code>
<syntaxhighlight lang="shell-session">
$ apk add triggerhappy
</syntaxhighlight>


<code>$ git fetch origin pull/1211/head:triggerhappy </code>
If you did not install it yet, you can also request it to be added to the installation in <code>pmbootstrap init</code> or by using the <code>--add</code> parameter for the install action:


<code>$ git checkout triggerhappy </code>
<syntaxhighlight lang="shell-session">
$ pmbootstrap install --add=triggerhappy
</syntaxhighlight>


<code>$ ./pmbootstrap.py build triggerhappy --arch=armhf </code>
=== Usage ===
Run thd on the device to find what is sent:


The built package is ~/.local/var/pmbootstrap/packages/armhf/triggerhappy-0.5.0-r0.apk (assuming default location during pmbootstrap.py init), which can be transferred to the device via scp / sftp.
<syntaxhighlight lang="shell-session">
$ sudo thd --dump /dev/input/event*
</syntaxhighlight>


<code>$ scp ~/.local/var/pmbootstrap/packages/armhf/triggerhappy-0.5.0-r0.apk user@172.16.42.1:~/ </code>
With <code>thd --dump</code> running, touch the touchscreen and press the available buttons. There will be information related to the input device printed on the ssh session.  
 
Install the package
 
<code>$ ssh user@172.16.42.1 </code>
 
<code>$ sudo apk add --allow-untrusted ./triggerhappy-0.5.0-r0.apk </code>
 
Run thd on the device to find what is sent
 
<code>$ sudo thd --dump /dev/input/event* </code>
 
With thd --dump running, touch the touchscreen and press the available buttons. There will be information related to the input device printed on the ssh session.


<pre>
<pre>
Line 83: Line 79:
</pre>
</pre>


The information can be used to create a triggerhappy configuration, for example assigning command when the home touch button is pressed.
The information can be used to create a triggerhappy configuration, for example assigning a command when the home touch button is pressed.
 
<code> /etc/triggerhappy/triggers.d/buttons.conf </code>


Example <code>/etc/triggerhappy/triggers.d/buttons.conf</code>:
<pre>
<pre>
KEY_POWER 1 poweroff
KEY_POWER 1 poweroff
Line 95: Line 90:
</pre>
</pre>


The triggerhappy service needs to be enabled to listen HID button keypresses.
The triggerhappy service needs to be enabled to listen HID button keypresses:


<code># rc-update add triggerhappy default </code>
<syntaxhighlight lang="shell-session">
# rc-update add triggerhappy default
</syntaxhighlight>


== Using busybox acpid ==
== Using busybox acpid ==
Line 103: Line 100:
Some device buttons can trigger acpi events. Busybox acpid can be used to handle these events, for example nokia n900.
Some device buttons can trigger acpi events. Busybox acpid can be used to handle these events, for example nokia n900.


For this to work, an acpi.map is needed. Look at [https://github.com/postmarketOS/pmbootstrap/blob/master/aports/device/device-nokia-n900 device-nokia-n900] for more information.
For this to work, an acpi.map is needed. Look at [https://gitlab.postmarketos.org/postmarketOS/pmaports/-/blob/master/device/community/device-nokia-n900 device-nokia-n900] for more information.


== See also ==
== See also ==
 
* [https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/1211#note_85244691 Difference between busybox acpid and triggerhappy]
* [https://cgit.freedesktop.org/evtest/tree/ evtest source code]
* [https://cgit.freedesktop.org/evtest/tree/ evtest source code]
* [https://github.com/wertarbyte/triggerhappy triggerhappy source code]
* [https://github.com/wertarbyte/triggerhappy triggerhappy source code]
* [https://git.busybox.net/busybox/tree/util-linux/acpid.c busybox acpid source code]


* [https://git.busybox.net/busybox/tree/util-linux/acpid.c busybox acpid source code]
[[Category:Technical Reference]]

Latest revision as of 06:54, 3 November 2024

Phones may have some buttons. Those buttons can be configured to execute specific command when pressed.

Getting input device information using udevadm

Make sure that buttons are recognized as eventX inside /dev/input directory

To make sure that the input buttons are recognized, run the following command:

$ udevadm info -a /dev/input/event0

The command will print udev properties which can be used to assign udev rules, for example tagging specified device as touchscreen.

Note that HID input device doesn't trigger udev event, so the following command can't be used to detect key-presses from HID input device.

# udevadm monitor

Getting input device events using evtest

evtest can be used to detect events sent by input devices. To use it, install evtest package.

# apk add evtest

Launch evtest to troubleshoot the input device

# evtest /dev/input/event0

The information obtained from evtest can be used as reference to configure triggerhappy or creating acpi.map for busybox acpid

Using triggerhappy to handle HID input events

Note Triggerhappy has been replaced with HKDM

Installation

Triggerhappy can be used to handle HID input device. After postmarketOS is installed, add it with:

$ apk add triggerhappy

If you did not install it yet, you can also request it to be added to the installation in pmbootstrap init or by using the --add parameter for the install action:

$ pmbootstrap install --add=triggerhappy

Usage

Run thd on the device to find what is sent:

$ sudo thd --dump /dev/input/event*

With thd --dump running, touch the touchscreen and press the available buttons. There will be information related to the input device printed on the ssh session.

EV_ABS	ABS_MT_TRACKING_ID	16	/dev/input/event0
# ABS_MT_TRACKING_ID	16	command
EV_ABS	ABS_MT_TRACKING_ID	0	/dev/input/event0
# ABS_MT_TRACKING_ID	0	command
EV_ABS	ABS_MT_POSITION_X	312	/dev/input/event0
# ABS_MT_POSITION_X	312	command
EV_ABS	ABS_MT_POSITION_Y	1013	/dev/input/event0
# ABS_MT_POSITION_Y	1013	command
EV_ABS	ABS_MT_TOUCH_MAJOR	123	/dev/input/event0
# ABS_MT_TOUCH_MAJOR	123	command
EV_ABS	ABS_MT_WIDTH_MAJOR	144	/dev/input/event0
# ABS_MT_WIDTH_MAJOR	144	command
EV_KEY  KEY_POWER       1       /dev/input/event1
# KEY_POWER     1       command
EV_KEY  KEY_POWER       0       /dev/input/event1
# KEY_POWER     0       command
EV_KEY  KEY_VOLUMEDOWN  1       /dev/input/event1
# KEY_VOLUMEDOWN        1       command
EV_KEY  KEY_VOLUMEDOWN  0       /dev/input/event1
# KEY_VOLUMEDOWN        0       command
EV_KEY  KEY_VOLUMEUP    1       /dev/input/event2
# KEY_VOLUMEUP  1       command
EV_KEY  KEY_VOLUMEUP    0       /dev/input/event2
# KEY_VOLUMEUP  0       command

The information can be used to create a triggerhappy configuration, for example assigning a command when the home touch button is pressed.

Example /etc/triggerhappy/triggers.d/buttons.conf:

KEY_POWER 1 poweroff
KEY_VOLUMEDOWN+KEY_POWER 1 reboot
#ABS_MT_POSITION_Y@ 1344 @home
#ABS_MT_POSITION_X@home 360 logger "Home button is pressed"
#ABS_MT_POSITION_Y@home 1344 @

The triggerhappy service needs to be enabled to listen HID button keypresses:

# rc-update add triggerhappy default

Using busybox acpid

Some device buttons can trigger acpi events. Busybox acpid can be used to handle these events, for example nokia n900.

For this to work, an acpi.map is needed. Look at device-nokia-n900 for more information.

See also