summaryrefslogtreecommitdiff
path: root/bin
diff options
authorPMR <pmr@pmr-lander>2019-10-16 16:57:23 +0000
committerPMR <pmr@pmr-lander>2019-10-16 16:57:23 +0000
commit0fd759213f2f0e9ef20e7e4cd732d4d25b663d2f (patch)
treee60b3d20e2f4fcdfad264cec7580b246889db193 /bin
parent5a17231d343d45da82f3062e526bbd4c62723aa5 (diff)
parent2b21c124f452112a44cce4896455c1f027bfcb30 (diff)
Merge #374228 from ~sylvain-pineau/plainbox-provider-checkbox:touchscreen-evdev-tests
Diffstat (limited to 'bin')
-rwxr-xr-xbin/evdev_touch_test.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/bin/evdev_touch_test.py b/bin/evdev_touch_test.py
new file mode 100755
index 0000000..5649701
--- /dev/null
+++ b/bin/evdev_touch_test.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# This file is part of Checkbox.
+#
+# Copyright 2019 Canonical Ltd.
+#
+# Checkbox is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3,
+# as published by the Free Software Foundation.
+#
+# Checkbox is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
+
+import argparse
+import selectors
+import time
+
+import evdev
+
+parser = argparse.ArgumentParser()
+parser.add_argument("name", help='Touch device product name')
+parser.add_argument("--timeout", type=int, default=10, help='timeout')
+parser.add_argument(
+ "--xfingers", "-x", type=int, default=1, help="X-fingers tap event")
+args = parser.parse_args()
+start = time.time()
+
+
+def check_timeout():
+ if time.time() > start + args.timeout:
+ raise SystemExit("Event not detected")
+
+
+selector = selectors.DefaultSelector()
+for d in [evdev.InputDevice(path) for path in evdev.list_devices()]:
+ if d.name == args.name:
+ device = d
+ break
+else:
+ raise SystemExit("Touch device not found!")
+selector.register(device, selectors.EVENT_READ)
+
+
+while True:
+ time.sleep(0.25) # sleep for 250 milliseconds
+ check_timeout()
+ for key, mask in selector.select(1):
+ dev = key.fileobj
+ for e in dev.read():
+ tap = args.xfingers
+ if tap == 1:
+ if (e.type == 3 and e.code == 47 and e.value > 0):
+ raise SystemExit(
+ "Multitouch Event detected but Single was expected")
+ # type 1 is evdev.ecodes.EV_KEY
+ # code 330 is a BTN_TOUCH event
+ # value is a boolean, 1 means a PRESS, 0 a RELEASED event
+ if (e.type == 1 and e.code == 330 and e.value == 1):
+ print("SUCCESS:", e)
+ raise SystemExit
+ else:
+ # type 3 is evdev.ecodes.EV_ABS
+ # code 47 is a PRESS event
+ # value is the 0-indexed amount of simultaneous detected
+ # fingers
+ if (e.type == 3 and e.code == 47 and e.value == tap - 1):
+ print("SUCCESS:", e)
+ raise SystemExit
+ check_timeout()
+ else:
+ check_timeout()