tools: switch measure-fuzz to use python-libevdev

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-03-15 11:21:27 +10:00
parent 6d96d417a0
commit 795c08eb44

View file

@ -29,8 +29,7 @@ import sys
import argparse import argparse
import subprocess import subprocess
try: try:
import evdev import libevdev
import evdev.ecodes
import pyudev import pyudev
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
print('Error: {}'.format(str(e)), file=sys.stderr) print('Error: {}'.format(str(e)), file=sys.stderr)
@ -70,15 +69,15 @@ class InvalidDeviceError(Exception):
pass pass
class Device(object): class Device(libevdev.Device):
def __init__(self, path): def __init__(self, path):
if path is None: if path is None:
self.path = self.find_touch_device() self.path = self.find_touch_device()
else: else:
self.path = path self.path = path
self.device = evdev.InputDevice(self.path) fd = open(self.path, 'rb')
self.name = self.device.name super().__init__(fd)
context = pyudev.Context() context = pyudev.Context()
self.udev_device = pyudev.Devices.from_device_file(context, self.path) self.udev_device = pyudev.Devices.from_device_file(context, self.path)
@ -133,37 +132,18 @@ class Device(object):
Returns a tuple of (xfuzz, yfuzz) with the fuzz as set on the device Returns a tuple of (xfuzz, yfuzz) with the fuzz as set on the device
axis. Returns None if no fuzz is set. axis. Returns None if no fuzz is set.
''' '''
# capabilities returns a dict with the EV_* codes as key, if not self.has(libevdev.EV_ABS.ABS_X) or not self.has(libevdev.EV_ABS.ABS_Y):
# each of which is a list of tuples of (code, AbsInfo)
#
# Get the abs list first (or empty list if missing),
# then extract the touch major absinfo from that
caps = self.device.capabilities(absinfo=True).get(
evdev.ecodes.EV_ABS, []
)
codes = [cap[0] for cap in caps]
if evdev.ecodes.ABS_X not in codes or evdev.ecodes.ABS_Y not in codes:
raise InvalidDeviceError('device does not have x/y axes') raise InvalidDeviceError('device does not have x/y axes')
if (evdev.ecodes.ABS_MT_POSITION_X in codes) != (evdev.ecodes.ABS_MT_POSITION_Y in codes): if self.has(libevdev.EV_ABS.ABS_MT_POSITION_X) != self.has(libevdev.EV_ABS.ABS_MT_POSITION_Y):
raise InvalidDeviceError('device does not have both multitouch axes') raise InvalidDeviceError('device does not have both multitouch axes')
axes = { xfuzz = self.absinfo[libevdev.EV_ABS.ABS_X].fuzz or \
0x00: None, self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_X].fuzz
0x01: None, yfuzz = self.absinfo[libevdev.EV_ABS.ABS_Y].fuzz or \
0x35: None, self.absinfo[libevdev.EV_ABS.ABS_MT_POSITION_Y].fuzz
0x36: None,
}
for c in caps: if xfuzz is 0 and yfuzz is 0:
if c[0] in axes.keys():
axes[c[0]] = c[1].fuzz
xfuzz = axes[0x35] or axes[0x00]
yfuzz = axes[0x36] or axes[0x01]
if xfuzz is None and yfuzz is None:
return None return None
return (xfuzz, yfuzz) return (xfuzz, yfuzz)