Commit acba3e40 authored by David Boddie's avatar David Boddie

Add a low-level guide to reading touchscreen events

parent 2e35cf41
......@@ -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.
Receiving Touch Events
Events from the touchscreen are delivered to the ``/dev/input/event1`` file.
One way to examine these events is to run the ``evtest`` command -- this will
need to be executed using ``sudo`` unless the user is in the ``input`` group::
sudo 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
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment