HID buttons

From postmarketOS Wiki
(Redirected from Troubleshooting:HID buttons)

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