Commit 5978c7a5 authored by David Boddie's avatar David Boddie

Merge branch 'devkit-touchscreen' into 'master'

Add a low-level guide to reading touchscreen events

See merge request !202
parents fdbc95f8 181ed70d
Pipeline #4234 passed with stages
in 9 minutes and 48 seconds
......@@ -14,5 +14,6 @@ how to perform routine tasks.
.. _devkit_howto_touchscreen:
The Librem 5 development board is supplied with an LCD screen with an overlaid
touchscreen. User input from the screen is delivered to user-space via touch
events. This guide describes how to receive and interpret these events.
**Note:** This guide assumes that you are using a device tree binary file that
is configured for LCD display and touchscreen input. Follow the procedure in
:ref:`imx8_devkit_lcd_display` to copy the correct file into place on the
development board.
The commands and script given in the next section will need to be executed
using ``sudo`` unless the user is in the ``input`` group. We assume that the
user has been added to this group from this point onwards.
Receiving Touch Events
Events from the touchscreen are typically delivered to the ``/dev/input/event1``
file. This can be verified by using the ``lsinput`` tool from the ``input-utils``
Debian package. Install and run the tool like this::
sudo apt install input-utils
This should produce output like the following::
bustype : BUS_HOST
vendor : 0x1
product : 0x1
version : 256
name : "gpio-keys"
phys : "gpio-keys/input0"
bits ev : (null) (null)
bustype : BUS_I2C
vendor : 0x416
product : 0x1638
version : 256
name : "Goodix Capacitive TouchScreen"
phys : "input/ts"
bits ev : (null) (null) (null)
One way to examine these events is to run the ``evtest`` command::
evtest /dev/input/event1
This will listen for events from the touchscreen and write them in
human-readable form to the console.
Events can also be read using the `python-evdev`_ package. The following
program reads events from the device and prints their screen coordinates:
.. literalinclude:: _files/
:language: python3
The `python-evdev tutorial`_ shows several ways of handling events that can be
applied to various situations, using different techniques to read the event
.. include:: /links.txt
#/usr/bin/env python3
import evdev
from evdev.ecodes import ABS_MT_TRACKING_ID, ABS_MT_POSITION_X, \
import select
# Obtain an object for the input device.
device = evdev.InputDevice('/dev/input/event1')
while True:
# Wait for an event.
r, w, x =[device.fd], [], [])
id_ = -1
x = y = 0
# Read the events for the device.
for event in
if event.code == event.value == 0:
if id_ != -1:
print(x, y)
elif event.code == ABS_MT_TRACKING_ID:
id_ = event.value
elif event.code == ABS_MT_POSITION_X:
x = event.value
elif event.code == ABS_MT_POSITION_Y:
y = event.value
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment