test_wacom_generic.py 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. #!/bin/env python3
  2. # SPDX-License-Identifier: GPL-2.0
  3. # -*- coding: utf-8 -*-
  4. #
  5. # Copyright (c) 2017 Benjamin Tissoires <benjamin.tissoires@gmail.com>
  6. # Copyright (c) 2017 Red Hat, Inc.
  7. # Copyright (c) 2020 Wacom Technology Corp.
  8. #
  9. # Authors:
  10. # Jason Gerecke <jason.gerecke@wacom.com>
  11. """
  12. Tests for the Wacom driver generic codepath.
  13. This module tests the function of the Wacom driver's generic codepath.
  14. The generic codepath is used by devices which are not explicitly listed
  15. in the driver's device table. It uses the device's HID descriptor to
  16. decode reports sent by the device.
  17. """
  18. from .descriptors_wacom import (
  19. wacom_pth660_v145,
  20. wacom_pth660_v150,
  21. wacom_pth860_v145,
  22. wacom_pth860_v150,
  23. wacom_pth460_v105,
  24. )
  25. import attr
  26. from collections import namedtuple
  27. from enum import Enum
  28. from hidtools.hut import HUT
  29. from hidtools.hid import HidUnit
  30. from . import base
  31. from . import test_multitouch
  32. import libevdev
  33. import pytest
  34. import logging
  35. logger = logging.getLogger("hidtools.test.wacom")
  36. KERNEL_MODULE = base.KernelModule("wacom", "wacom")
  37. class ProximityState(Enum):
  38. """
  39. Enumeration of allowed proximity states.
  40. """
  41. # Tool is not able to be sensed by the device
  42. OUT = 0
  43. # Tool is close enough to be sensed, but some data may be invalid
  44. # or inaccurate
  45. IN_PROXIMITY = 1
  46. # Tool is close enough to be sensed with high accuracy. All data
  47. # valid.
  48. IN_RANGE = 2
  49. def fill(self, reportdata):
  50. """Fill a report with approrpiate HID properties/values."""
  51. reportdata.inrange = self in [ProximityState.IN_RANGE]
  52. reportdata.wacomsense = self in [
  53. ProximityState.IN_PROXIMITY,
  54. ProximityState.IN_RANGE,
  55. ]
  56. class ReportData:
  57. """
  58. Placeholder for HID report values.
  59. """
  60. pass
  61. @attr.s
  62. class Buttons:
  63. """
  64. Stylus button state.
  65. Describes the state of each of the buttons / "side switches" that
  66. may be present on a stylus. Buttons set to 'None' indicate the
  67. state is "unchanged" since the previous event.
  68. """
  69. primary = attr.ib(default=None)
  70. secondary = attr.ib(default=None)
  71. tertiary = attr.ib(default=None)
  72. @staticmethod
  73. def clear():
  74. """Button object with all states cleared."""
  75. return Buttons(False, False, False)
  76. def fill(self, reportdata):
  77. """Fill a report with approrpiate HID properties/values."""
  78. reportdata.barrelswitch = int(self.primary or 0)
  79. reportdata.secondarybarrelswitch = int(self.secondary or 0)
  80. reportdata.b3 = int(self.tertiary or 0)
  81. @attr.s
  82. class ToolID:
  83. """
  84. Stylus tool identifiers.
  85. Contains values used to identify a specific stylus, e.g. its serial
  86. number and tool-type identifier. Values of ``0`` may sometimes be
  87. used for the out-of-range condition.
  88. """
  89. serial = attr.ib()
  90. tooltype = attr.ib()
  91. @staticmethod
  92. def clear():
  93. """ToolID object with all fields cleared."""
  94. return ToolID(0, 0)
  95. def fill(self, reportdata):
  96. """Fill a report with approrpiate HID properties/values."""
  97. reportdata.transducerserialnumber = self.serial & 0xFFFFFFFF
  98. reportdata.serialhi = (self.serial >> 32) & 0xFFFFFFFF
  99. reportdata.tooltype = self.tooltype
  100. @attr.s
  101. class PhysRange:
  102. """
  103. Range of HID physical values, with units.
  104. """
  105. unit = attr.ib()
  106. min_size = attr.ib()
  107. max_size = attr.ib()
  108. CENTIMETER = HidUnit.from_string("SILinear: cm")
  109. DEGREE = HidUnit.from_string("EnglishRotation: deg")
  110. def contains(self, field):
  111. """
  112. Check if the physical size of the provided field is in range.
  113. Compare the physical size described by the provided HID field
  114. against the range of sizes described by this object. This is
  115. an exclusive range comparison (e.g. 0 cm is not within the
  116. range 0 cm - 5 cm) and exact unit comparison (e.g. 1 inch is
  117. not within the range 0 cm - 5 cm).
  118. """
  119. phys_size = (field.physical_max - field.physical_min) * 10 ** (field.unit_exp)
  120. return (
  121. field.unit == self.unit.value
  122. and phys_size > self.min_size
  123. and phys_size < self.max_size
  124. )
  125. class BaseTablet(base.UHIDTestDevice):
  126. """
  127. Skeleton object for all kinds of tablet devices.
  128. """
  129. def __init__(self, rdesc, name=None, info=None):
  130. assert rdesc is not None
  131. super().__init__(name, "Pen", input_info=info, rdesc=rdesc)
  132. self.buttons = Buttons.clear()
  133. self.toolid = ToolID.clear()
  134. self.proximity = ProximityState.OUT
  135. self.offset = 0
  136. self.ring = -1
  137. self.ek0 = False
  138. def match_evdev_rule(self, application, evdev):
  139. """
  140. Filter out evdev nodes based on the requested application.
  141. The Wacom driver may create several device nodes for each USB
  142. interface device. It is crucial that we run tests with the
  143. expected device node or things will obviously go off the rails.
  144. Use the Wacom driver's usual naming conventions to apply a
  145. sensible default filter.
  146. """
  147. if application in ["Pen", "Pad"]:
  148. return evdev.name.endswith(application)
  149. else:
  150. return True
  151. def create_report(
  152. self, x, y, pressure, buttons=None, toolid=None, proximity=None, reportID=None
  153. ):
  154. """
  155. Return an input report for this device.
  156. :param x: absolute x
  157. :param y: absolute y
  158. :param pressure: pressure
  159. :param buttons: stylus button state. Use ``None`` for unchanged.
  160. :param toolid: tool identifiers. Use ``None`` for unchanged.
  161. :param proximity: a ProximityState indicating the sensor's ability
  162. to detect and report attributes of this tool. Use ``None``
  163. for unchanged.
  164. :param reportID: the numeric report ID for this report, if needed
  165. """
  166. if buttons is not None:
  167. self.buttons = buttons
  168. buttons = self.buttons
  169. if toolid is not None:
  170. self.toolid = toolid
  171. toolid = self.toolid
  172. if proximity is not None:
  173. self.proximity = proximity
  174. proximity = self.proximity
  175. reportID = reportID or self.default_reportID
  176. report = ReportData()
  177. report.x = x
  178. report.y = y
  179. report.tippressure = pressure
  180. report.tipswitch = pressure > 0
  181. buttons.fill(report)
  182. proximity.fill(report)
  183. toolid.fill(report)
  184. return super().create_report(report, reportID=reportID)
  185. def create_report_heartbeat(self, reportID):
  186. """
  187. Return a heartbeat input report for this device.
  188. Heartbeat reports generally contain battery status information,
  189. among other things.
  190. """
  191. report = ReportData()
  192. report.wacombatterycharging = 1
  193. return super().create_report(report, reportID=reportID)
  194. def create_report_pad(self, reportID, ring, ek0):
  195. report = ReportData()
  196. if ring is not None:
  197. self.ring = ring
  198. ring = self.ring
  199. if ek0 is not None:
  200. self.ek0 = ek0
  201. ek0 = self.ek0
  202. if ring >= 0:
  203. report.wacomtouchring = ring
  204. report.wacomtouchringstatus = 1
  205. else:
  206. report.wacomtouchring = 0x7F
  207. report.wacomtouchringstatus = 0
  208. report.wacomexpresskey00 = ek0
  209. return super().create_report(report, reportID=reportID)
  210. def event(self, x, y, pressure, buttons=None, toolid=None, proximity=None):
  211. """
  212. Send an input event on the default report ID.
  213. :param x: absolute x
  214. :param y: absolute y
  215. :param buttons: stylus button state. Use ``None`` for unchanged.
  216. :param toolid: tool identifiers. Use ``None`` for unchanged.
  217. :param proximity: a ProximityState indicating the sensor's ability
  218. to detect and report attributes of this tool. Use ``None``
  219. for unchanged.
  220. """
  221. r = self.create_report(x, y, pressure, buttons, toolid, proximity)
  222. self.call_input_event(r)
  223. return [r]
  224. def event_heartbeat(self, reportID):
  225. """
  226. Send a heartbeat event on the requested report ID.
  227. """
  228. r = self.create_report_heartbeat(reportID)
  229. self.call_input_event(r)
  230. return [r]
  231. def event_pad(self, reportID, ring=None, ek0=None):
  232. """
  233. Send a pad event on the requested report ID.
  234. """
  235. r = self.create_report_pad(reportID, ring, ek0)
  236. self.call_input_event(r)
  237. return [r]
  238. def get_report(self, req, rnum, rtype):
  239. if rtype != self.UHID_FEATURE_REPORT:
  240. return (1, [])
  241. rdesc = None
  242. for v in self.parsed_rdesc.feature_reports.values():
  243. if v.report_ID == rnum:
  244. rdesc = v
  245. if rdesc is None:
  246. return (1, [])
  247. result = (1, [])
  248. result = self.create_report_offset(rdesc) or result
  249. return result
  250. def create_report_offset(self, rdesc):
  251. require = [
  252. "Wacom Offset Left",
  253. "Wacom Offset Top",
  254. "Wacom Offset Right",
  255. "Wacom Offset Bottom",
  256. ]
  257. if not set(require).issubset(set([f.usage_name for f in rdesc])):
  258. return None
  259. report = ReportData()
  260. report.wacomoffsetleft = self.offset
  261. report.wacomoffsettop = self.offset
  262. report.wacomoffsetright = self.offset
  263. report.wacomoffsetbottom = self.offset
  264. r = rdesc.create_report([report], None)
  265. return (0, r)
  266. class OpaqueTablet(BaseTablet):
  267. """
  268. Bare-bones opaque tablet with a minimum of features.
  269. A tablet stripped down to its absolute core. It is capable of
  270. reporting X/Y position and if the pen is in contact. No pressure,
  271. no barrel switches, no eraser. Notably it *does* report an "In
  272. Range" flag, but this is only because the Wacom driver expects
  273. one to function properly. The device uses only standard HID usages,
  274. not any of Wacom's vendor-defined pages.
  275. """
  276. # fmt: off
  277. report_descriptor = [
  278. 0x05, 0x0D, # . Usage Page (Digitizer),
  279. 0x09, 0x01, # . Usage (Digitizer),
  280. 0xA1, 0x01, # . Collection (Application),
  281. 0x85, 0x01, # . Report ID (1),
  282. 0x09, 0x20, # . Usage (Stylus),
  283. 0xA1, 0x00, # . Collection (Physical),
  284. 0x09, 0x42, # . Usage (Tip Switch),
  285. 0x09, 0x32, # . Usage (In Range),
  286. 0x15, 0x00, # . Logical Minimum (0),
  287. 0x25, 0x01, # . Logical Maximum (1),
  288. 0x75, 0x01, # . Report Size (1),
  289. 0x95, 0x02, # . Report Count (2),
  290. 0x81, 0x02, # . Input (Variable),
  291. 0x95, 0x06, # . Report Count (6),
  292. 0x81, 0x03, # . Input (Constant, Variable),
  293. 0x05, 0x01, # . Usage Page (Desktop),
  294. 0x09, 0x30, # . Usage (X),
  295. 0x27, 0x80, 0x3E, 0x00, 0x00, # . Logical Maximum (16000),
  296. 0x47, 0x80, 0x3E, 0x00, 0x00, # . Physical Maximum (16000),
  297. 0x65, 0x11, # . Unit (Centimeter),
  298. 0x55, 0x0D, # . Unit Exponent (13),
  299. 0x75, 0x10, # . Report Size (16),
  300. 0x95, 0x01, # . Report Count (1),
  301. 0x81, 0x02, # . Input (Variable),
  302. 0x09, 0x31, # . Usage (Y),
  303. 0x27, 0x28, 0x23, 0x00, 0x00, # . Logical Maximum (9000),
  304. 0x47, 0x28, 0x23, 0x00, 0x00, # . Physical Maximum (9000),
  305. 0x81, 0x02, # . Input (Variable),
  306. 0xC0, # . End Collection,
  307. 0xC0, # . End Collection,
  308. ]
  309. # fmt: on
  310. def __init__(self, rdesc=report_descriptor, name=None, info=(0x3, 0x056A, 0x9999)):
  311. super().__init__(rdesc, name, info)
  312. self.default_reportID = 1
  313. class OpaqueCTLTablet(BaseTablet):
  314. """
  315. Opaque tablet similar to something in the CTL product line.
  316. A pen-only tablet with most basic features you would expect from
  317. an actual device. Position, eraser, pressure, barrel buttons.
  318. Uses the Wacom vendor-defined usage page.
  319. """
  320. # fmt: off
  321. report_descriptor = [
  322. 0x06, 0x0D, 0xFF, # . Usage Page (Vnd Wacom Emr),
  323. 0x09, 0x01, # . Usage (Digitizer),
  324. 0xA1, 0x01, # . Collection (Application),
  325. 0x85, 0x10, # . Report ID (16),
  326. 0x09, 0x20, # . Usage (Stylus),
  327. 0x35, 0x00, # . Physical Minimum (0),
  328. 0x45, 0x00, # . Physical Maximum (0),
  329. 0x15, 0x00, # . Logical Minimum (0),
  330. 0x25, 0x01, # . Logical Maximum (1),
  331. 0xA1, 0x00, # . Collection (Physical),
  332. 0x09, 0x42, # . Usage (Tip Switch),
  333. 0x09, 0x44, # . Usage (Barrel Switch),
  334. 0x09, 0x5A, # . Usage (Secondary Barrel Switch),
  335. 0x09, 0x45, # . Usage (Eraser),
  336. 0x09, 0x3C, # . Usage (Invert),
  337. 0x09, 0x32, # . Usage (In Range),
  338. 0x09, 0x36, # . Usage (In Proximity),
  339. 0x25, 0x01, # . Logical Maximum (1),
  340. 0x75, 0x01, # . Report Size (1),
  341. 0x95, 0x07, # . Report Count (7),
  342. 0x81, 0x02, # . Input (Variable),
  343. 0x95, 0x01, # . Report Count (1),
  344. 0x81, 0x03, # . Input (Constant, Variable),
  345. 0x0A, 0x30, 0x01, # . Usage (X),
  346. 0x65, 0x11, # . Unit (Centimeter),
  347. 0x55, 0x0D, # . Unit Exponent (13),
  348. 0x47, 0x80, 0x3E, 0x00, 0x00, # . Physical Maximum (16000),
  349. 0x27, 0x80, 0x3E, 0x00, 0x00, # . Logical Maximum (16000),
  350. 0x75, 0x18, # . Report Size (24),
  351. 0x95, 0x01, # . Report Count (1),
  352. 0x81, 0x02, # . Input (Variable),
  353. 0x0A, 0x31, 0x01, # . Usage (Y),
  354. 0x47, 0x28, 0x23, 0x00, 0x00, # . Physical Maximum (9000),
  355. 0x27, 0x28, 0x23, 0x00, 0x00, # . Logical Maximum (9000),
  356. 0x81, 0x02, # . Input (Variable),
  357. 0x09, 0x30, # . Usage (Tip Pressure),
  358. 0x55, 0x00, # . Unit Exponent (0),
  359. 0x65, 0x00, # . Unit,
  360. 0x47, 0x00, 0x00, 0x00, 0x00, # . Physical Maximum (0),
  361. 0x26, 0xFF, 0x0F, # . Logical Maximum (4095),
  362. 0x75, 0x10, # . Report Size (16),
  363. 0x81, 0x02, # . Input (Variable),
  364. 0x75, 0x08, # . Report Size (8),
  365. 0x95, 0x06, # . Report Count (6),
  366. 0x81, 0x03, # . Input (Constant, Variable),
  367. 0x0A, 0x32, 0x01, # . Usage (Z),
  368. 0x25, 0x3F, # . Logical Maximum (63),
  369. 0x75, 0x08, # . Report Size (8),
  370. 0x95, 0x01, # . Report Count (1),
  371. 0x81, 0x02, # . Input (Variable),
  372. 0x09, 0x5B, # . Usage (Transducer Serial Number),
  373. 0x09, 0x5C, # . Usage (Transducer Serial Number Hi),
  374. 0x17, 0x00, 0x00, 0x00, 0x80, # . Logical Minimum (-2147483648),
  375. 0x27, 0xFF, 0xFF, 0xFF, 0x7F, # . Logical Maximum (2147483647),
  376. 0x75, 0x20, # . Report Size (32),
  377. 0x95, 0x02, # . Report Count (2),
  378. 0x81, 0x02, # . Input (Variable),
  379. 0x09, 0x77, # . Usage (Tool Type),
  380. 0x15, 0x00, # . Logical Minimum (0),
  381. 0x26, 0xFF, 0x0F, # . Logical Maximum (4095),
  382. 0x75, 0x10, # . Report Size (16),
  383. 0x95, 0x01, # . Report Count (1),
  384. 0x81, 0x02, # . Input (Variable),
  385. 0xC0, # . End Collection,
  386. 0xC0 # . End Collection
  387. ]
  388. # fmt: on
  389. def __init__(self, rdesc=report_descriptor, name=None, info=(0x3, 0x056A, 0x9999)):
  390. super().__init__(rdesc, name, info)
  391. self.default_reportID = 16
  392. class PTHX60_Pen(BaseTablet):
  393. """
  394. Pen interface of a PTH-660 / PTH-860 / PTH-460 tablet.
  395. This generation of devices are nearly identical to each other, though
  396. the PTH-460 uses a slightly different descriptor construction (splits
  397. the pad among several physical collections)
  398. """
  399. def __init__(self, rdesc=None, name=None, info=None):
  400. super().__init__(rdesc, name, info)
  401. self.default_reportID = 16
  402. class BaseTest:
  403. class TestTablet(base.BaseTestCase.TestUhid):
  404. kernel_modules = [KERNEL_MODULE]
  405. def sync_and_assert_events(
  406. self, report, expected_events, auto_syn=True, strict=False
  407. ):
  408. """
  409. Assert we see the expected events in response to a report.
  410. """
  411. uhdev = self.uhdev
  412. syn_event = self.syn_event
  413. if auto_syn:
  414. expected_events.append(syn_event)
  415. actual_events = uhdev.next_sync_events()
  416. self.debug_reports(report, uhdev, actual_events)
  417. if strict:
  418. self.assertInputEvents(expected_events, actual_events)
  419. else:
  420. self.assertInputEventsIn(expected_events, actual_events)
  421. def get_usages(self, uhdev):
  422. def get_report_usages(report):
  423. application = report.application
  424. for field in report.fields:
  425. if field.usages is not None:
  426. for usage in field.usages:
  427. yield (field, usage, application)
  428. else:
  429. yield (field, field.usage, application)
  430. desc = uhdev.parsed_rdesc
  431. reports = [
  432. *desc.input_reports.values(),
  433. *desc.feature_reports.values(),
  434. *desc.output_reports.values(),
  435. ]
  436. for report in reports:
  437. for usage in get_report_usages(report):
  438. yield usage
  439. def assertName(self, uhdev, type):
  440. """
  441. Assert that the name is as we expect.
  442. The Wacom driver applies a number of decorations to the name
  443. provided by the hardware. We cannot rely on the definition of
  444. this assertion from the base class to work properly.
  445. """
  446. evdev = uhdev.get_evdev()
  447. expected_name = uhdev.name + type
  448. if "wacom" not in expected_name.lower():
  449. expected_name = "Wacom " + expected_name
  450. assert evdev.name == expected_name
  451. def test_descriptor_physicals(self):
  452. """
  453. Verify that all HID usages which should have a physical range
  454. actually do, and those which shouldn't don't. Also verify that
  455. the associated unit is correct and within a sensible range.
  456. """
  457. def usage_id(page_name, usage_name):
  458. page = HUT.usage_page_from_name(page_name)
  459. return (page.page_id << 16) | page[usage_name].usage
  460. required = {
  461. usage_id("Generic Desktop", "X"): PhysRange(
  462. PhysRange.CENTIMETER, 5, 150
  463. ),
  464. usage_id("Generic Desktop", "Y"): PhysRange(
  465. PhysRange.CENTIMETER, 5, 150
  466. ),
  467. usage_id("Digitizers", "Width"): PhysRange(
  468. PhysRange.CENTIMETER, 5, 150
  469. ),
  470. usage_id("Digitizers", "Height"): PhysRange(
  471. PhysRange.CENTIMETER, 5, 150
  472. ),
  473. usage_id("Digitizers", "X Tilt"): PhysRange(PhysRange.DEGREE, 90, 180),
  474. usage_id("Digitizers", "Y Tilt"): PhysRange(PhysRange.DEGREE, 90, 180),
  475. usage_id("Digitizers", "Twist"): PhysRange(PhysRange.DEGREE, 358, 360),
  476. usage_id("Wacom", "X Tilt"): PhysRange(PhysRange.DEGREE, 90, 180),
  477. usage_id("Wacom", "Y Tilt"): PhysRange(PhysRange.DEGREE, 90, 180),
  478. usage_id("Wacom", "Twist"): PhysRange(PhysRange.DEGREE, 358, 360),
  479. usage_id("Wacom", "X"): PhysRange(PhysRange.CENTIMETER, 5, 150),
  480. usage_id("Wacom", "Y"): PhysRange(PhysRange.CENTIMETER, 5, 150),
  481. usage_id("Wacom", "Wacom TouchRing"): PhysRange(
  482. PhysRange.DEGREE, 358, 360
  483. ),
  484. usage_id("Wacom", "Wacom Offset Left"): PhysRange(
  485. PhysRange.CENTIMETER, 0, 0.5
  486. ),
  487. usage_id("Wacom", "Wacom Offset Top"): PhysRange(
  488. PhysRange.CENTIMETER, 0, 0.5
  489. ),
  490. usage_id("Wacom", "Wacom Offset Right"): PhysRange(
  491. PhysRange.CENTIMETER, 0, 0.5
  492. ),
  493. usage_id("Wacom", "Wacom Offset Bottom"): PhysRange(
  494. PhysRange.CENTIMETER, 0, 0.5
  495. ),
  496. }
  497. for field, usage, application in self.get_usages(self.uhdev):
  498. if application == usage_id("Generic Desktop", "Mouse"):
  499. # Ignore the vestigial Mouse collection which exists
  500. # on Wacom tablets only for backwards compatibility.
  501. continue
  502. expect_physical = usage in required
  503. phys_set = field.physical_min != 0 or field.physical_max != 0
  504. assert phys_set == expect_physical
  505. unit_set = field.unit != 0
  506. assert unit_set == expect_physical
  507. if unit_set:
  508. assert required[usage].contains(field)
  509. class PenTabletTest(BaseTest.TestTablet):
  510. def assertName(self, uhdev):
  511. super().assertName(uhdev, " Pen")
  512. class TouchTabletTest(BaseTest.TestTablet):
  513. def assertName(self, uhdev):
  514. super().assertName(uhdev, " Finger")
  515. class TestOpaqueTablet(PenTabletTest):
  516. def create_device(self):
  517. return OpaqueTablet()
  518. def test_sanity(self):
  519. """
  520. Bring a pen into contact with the tablet, then remove it.
  521. Ensure that we get the basic tool/touch/motion events that should
  522. be sent by the driver.
  523. """
  524. uhdev = self.uhdev
  525. self.sync_and_assert_events(
  526. uhdev.event(
  527. 100,
  528. 200,
  529. pressure=300,
  530. buttons=Buttons.clear(),
  531. toolid=ToolID(serial=1, tooltype=1),
  532. proximity=ProximityState.IN_RANGE,
  533. ),
  534. [
  535. libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 1),
  536. libevdev.InputEvent(libevdev.EV_ABS.ABS_X, 100),
  537. libevdev.InputEvent(libevdev.EV_ABS.ABS_Y, 200),
  538. libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 1),
  539. ],
  540. )
  541. self.sync_and_assert_events(
  542. uhdev.event(110, 220, pressure=0),
  543. [
  544. libevdev.InputEvent(libevdev.EV_ABS.ABS_X, 110),
  545. libevdev.InputEvent(libevdev.EV_ABS.ABS_Y, 220),
  546. libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 0),
  547. ],
  548. )
  549. self.sync_and_assert_events(
  550. uhdev.event(
  551. 120,
  552. 230,
  553. pressure=0,
  554. toolid=ToolID.clear(),
  555. proximity=ProximityState.OUT,
  556. ),
  557. [
  558. libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 0),
  559. ],
  560. )
  561. self.sync_and_assert_events(
  562. uhdev.event(130, 240, pressure=0), [], auto_syn=False, strict=True
  563. )
  564. def test_prop_pointer(self):
  565. """
  566. Verify that INPUT_PROP_POINTER is set and INPUT_PROP_DIRECT
  567. is not set on opaque devices.
  568. """
  569. evdev = self.uhdev.get_evdev()
  570. assert libevdev.INPUT_PROP_POINTER in evdev.properties
  571. assert libevdev.INPUT_PROP_DIRECT not in evdev.properties
  572. class TestOpaqueCTLTablet(TestOpaqueTablet):
  573. def create_device(self):
  574. return OpaqueCTLTablet()
  575. def test_buttons(self):
  576. """
  577. Test that the barrel buttons (side switches) work as expected.
  578. Press and release each button individually to verify that we get
  579. the expected events.
  580. """
  581. uhdev = self.uhdev
  582. self.sync_and_assert_events(
  583. uhdev.event(
  584. 100,
  585. 200,
  586. pressure=0,
  587. buttons=Buttons.clear(),
  588. toolid=ToolID(serial=1, tooltype=1),
  589. proximity=ProximityState.IN_RANGE,
  590. ),
  591. [
  592. libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 1),
  593. libevdev.InputEvent(libevdev.EV_ABS.ABS_X, 100),
  594. libevdev.InputEvent(libevdev.EV_ABS.ABS_Y, 200),
  595. libevdev.InputEvent(libevdev.EV_MSC.MSC_SERIAL, 1),
  596. ],
  597. )
  598. self.sync_and_assert_events(
  599. uhdev.event(100, 200, pressure=0, buttons=Buttons(primary=True)),
  600. [
  601. libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS, 1),
  602. libevdev.InputEvent(libevdev.EV_MSC.MSC_SERIAL, 1),
  603. ],
  604. )
  605. self.sync_and_assert_events(
  606. uhdev.event(100, 200, pressure=0, buttons=Buttons(primary=False)),
  607. [
  608. libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS, 0),
  609. libevdev.InputEvent(libevdev.EV_MSC.MSC_SERIAL, 1),
  610. ],
  611. )
  612. self.sync_and_assert_events(
  613. uhdev.event(100, 200, pressure=0, buttons=Buttons(secondary=True)),
  614. [
  615. libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS2, 1),
  616. libevdev.InputEvent(libevdev.EV_MSC.MSC_SERIAL, 1),
  617. ],
  618. )
  619. self.sync_and_assert_events(
  620. uhdev.event(100, 200, pressure=0, buttons=Buttons(secondary=False)),
  621. [
  622. libevdev.InputEvent(libevdev.EV_KEY.BTN_STYLUS2, 0),
  623. libevdev.InputEvent(libevdev.EV_MSC.MSC_SERIAL, 1),
  624. ],
  625. )
  626. PTHX60_Devices = [
  627. {"rdesc": wacom_pth660_v145, "info": (0x3, 0x056A, 0x0357)},
  628. {"rdesc": wacom_pth660_v150, "info": (0x3, 0x056A, 0x0357)},
  629. {"rdesc": wacom_pth860_v145, "info": (0x3, 0x056A, 0x0358)},
  630. {"rdesc": wacom_pth860_v150, "info": (0x3, 0x056A, 0x0358)},
  631. {"rdesc": wacom_pth460_v105, "info": (0x3, 0x056A, 0x0392)},
  632. ]
  633. PTHX60_Names = [
  634. "PTH-660/v145",
  635. "PTH-660/v150",
  636. "PTH-860/v145",
  637. "PTH-860/v150",
  638. "PTH-460/v105",
  639. ]
  640. class TestPTHX60_Pen(TestOpaqueCTLTablet):
  641. @pytest.fixture(
  642. autouse=True, scope="class", params=PTHX60_Devices, ids=PTHX60_Names
  643. )
  644. def set_device_params(self, request):
  645. request.cls.device_params = request.param
  646. def create_device(self):
  647. return PTHX60_Pen(**self.device_params)
  648. @pytest.mark.xfail
  649. def test_descriptor_physicals(self):
  650. # XFAIL: Various documented errata
  651. super().test_descriptor_physicals()
  652. def test_heartbeat_spurious(self):
  653. """
  654. Test that the heartbeat report does not send spurious events.
  655. """
  656. uhdev = self.uhdev
  657. self.sync_and_assert_events(
  658. uhdev.event(
  659. 100,
  660. 200,
  661. pressure=300,
  662. buttons=Buttons.clear(),
  663. toolid=ToolID(serial=1, tooltype=0x822),
  664. proximity=ProximityState.IN_RANGE,
  665. ),
  666. [
  667. libevdev.InputEvent(libevdev.EV_KEY.BTN_TOOL_PEN, 1),
  668. libevdev.InputEvent(libevdev.EV_ABS.ABS_X, 100),
  669. libevdev.InputEvent(libevdev.EV_ABS.ABS_Y, 200),
  670. libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 1),
  671. ],
  672. )
  673. # Exactly zero events: not even a SYN
  674. self.sync_and_assert_events(
  675. uhdev.event_heartbeat(19), [], auto_syn=False, strict=True
  676. )
  677. self.sync_and_assert_events(
  678. uhdev.event(110, 200, pressure=300),
  679. [
  680. libevdev.InputEvent(libevdev.EV_ABS.ABS_X, 110),
  681. ],
  682. )
  683. def test_empty_pad_sync(self):
  684. self.empty_pad_sync(num=3, denom=16, reverse=True)
  685. def empty_pad_sync(self, num, denom, reverse):
  686. """
  687. Test that multiple pad collections do not trigger empty syncs.
  688. """
  689. def offset_rotation(value):
  690. """
  691. Offset touchring rotation values by the same factor as the
  692. Linux kernel. Tablets historically don't use the same origin
  693. as HID, and it sometimes changes from tablet to tablet...
  694. """
  695. evdev = self.uhdev.get_evdev()
  696. info = evdev.absinfo[libevdev.EV_ABS.ABS_WHEEL]
  697. delta = info.maximum - info.minimum + 1
  698. if reverse:
  699. value = info.maximum - value
  700. value += num * delta // denom
  701. if value > info.maximum:
  702. value -= delta
  703. elif value < info.minimum:
  704. value += delta
  705. return value
  706. uhdev = self.uhdev
  707. uhdev.application = "Pad"
  708. evdev = uhdev.get_evdev()
  709. print(evdev.name)
  710. self.sync_and_assert_events(
  711. uhdev.event_pad(reportID=17, ring=0, ek0=1),
  712. [
  713. libevdev.InputEvent(libevdev.EV_KEY.BTN_0, 1),
  714. libevdev.InputEvent(libevdev.EV_ABS.ABS_WHEEL, offset_rotation(0)),
  715. libevdev.InputEvent(libevdev.EV_ABS.ABS_MISC, 15),
  716. ],
  717. )
  718. self.sync_and_assert_events(
  719. uhdev.event_pad(reportID=17, ring=1, ek0=1),
  720. [libevdev.InputEvent(libevdev.EV_ABS.ABS_WHEEL, offset_rotation(1))],
  721. )
  722. self.sync_and_assert_events(
  723. uhdev.event_pad(reportID=17, ring=2, ek0=0),
  724. [
  725. libevdev.InputEvent(libevdev.EV_ABS.ABS_WHEEL, offset_rotation(2)),
  726. libevdev.InputEvent(libevdev.EV_KEY.BTN_0, 0),
  727. ],
  728. )
  729. class DirectTabletTest():
  730. def test_prop_direct(self):
  731. """
  732. Verify that INPUT_PROP_DIRECT is set and INPUT_PROP_POINTER
  733. is not set on display devices.
  734. """
  735. evdev = self.uhdev.get_evdev()
  736. assert libevdev.INPUT_PROP_DIRECT in evdev.properties
  737. assert libevdev.INPUT_PROP_POINTER not in evdev.properties
  738. class TestDTH2452Tablet(test_multitouch.BaseTest.TestMultitouch, TouchTabletTest, DirectTabletTest):
  739. ContactIds = namedtuple("ContactIds", "contact_id, tracking_id, slot_num")
  740. def create_device(self):
  741. return test_multitouch.Digitizer(
  742. "DTH 2452",
  743. rdesc="05 0d 09 04 a1 01 85 0c 95 01 75 08 15 00 26 ff 00 81 03 09 54 81 02 09 22 a1 02 05 0d 95 01 75 01 25 01 09 42 81 02 81 03 09 47 81 02 95 05 81 03 09 51 26 ff 00 75 10 95 01 81 02 35 00 65 11 55 0e 05 01 09 30 26 a0 44 46 96 14 81 42 09 31 26 9a 26 46 95 0b 81 42 05 0d 75 08 95 01 15 00 09 48 26 5f 00 46 7c 14 81 02 09 49 25 35 46 7d 0b 81 02 45 00 65 00 55 00 c0 05 0d 09 22 a1 02 05 0d 95 01 75 01 25 01 09 42 81 02 81 03 09 47 81 02 95 05 81 03 09 51 26 ff 00 75 10 95 01 81 02 35 00 65 11 55 0e 05 01 09 30 26 a0 44 46 96 14 81 42 09 31 26 9a 26 46 95 0b 81 42 05 0d 75 08 95 01 15 00 09 48 26 5f 00 46 7c 14 81 02 09 49 25 35 46 7d 0b 81 02 45 00 65 00 55 00 c0 05 0d 09 22 a1 02 05 0d 95 01 75 01 25 01 09 42 81 02 81 03 09 47 81 02 95 05 81 03 09 51 26 ff 00 75 10 95 01 81 02 35 00 65 11 55 0e 05 01 09 30 26 a0 44 46 96 14 81 42 09 31 26 9a 26 46 95 0b 81 42 05 0d 75 08 95 01 15 00 09 48 26 5f 00 46 7c 14 81 02 09 49 25 35 46 7d 0b 81 02 45 00 65 00 55 00 c0 05 0d 09 22 a1 02 05 0d 95 01 75 01 25 01 09 42 81 02 81 03 09 47 81 02 95 05 81 03 09 51 26 ff 00 75 10 95 01 81 02 35 00 65 11 55 0e 05 01 09 30 26 a0 44 46 96 14 81 42 09 31 26 9a 26 46 95 0b 81 42 05 0d 75 08 95 01 15 00 09 48 26 5f 00 46 7c 14 81 02 09 49 25 35 46 7d 0b 81 02 45 00 65 00 55 00 c0 05 0d 09 22 a1 02 05 0d 95 01 75 01 25 01 09 42 81 02 81 03 09 47 81 02 95 05 81 03 09 51 26 ff 00 75 10 95 01 81 02 35 00 65 11 55 0e 05 01 09 30 26 a0 44 46 96 14 81 42 09 31 26 9a 26 46 95 0b 81 42 05 0d 75 08 95 01 15 00 09 48 26 5f 00 46 7c 14 81 02 09 49 25 35 46 7d 0b 81 02 45 00 65 00 55 00 c0 05 0d 27 ff ff 00 00 75 10 95 01 09 56 81 02 75 08 95 0e 81 03 09 55 26 ff 00 75 08 b1 02 85 0a 06 00 ff 09 c5 96 00 01 b1 02 c0 06 00 ff 09 01 a1 01 09 01 85 13 15 00 26 ff 00 75 08 95 3f 81 02 06 00 ff 09 01 15 00 26 ff 00 75 08 95 3f 91 02 c0",
  744. input_info=(0x3, 0x056A, 0x0383),
  745. )
  746. def make_contact(self, contact_id=0, t=0):
  747. """
  748. Make a single touch contact that can move over time.
  749. Creates a touch object that has a well-known position in space that
  750. does not overlap with other contacts. The value of `t` may be
  751. incremented over time to move the point along a linear path.
  752. """
  753. x = 50 + 10 * contact_id + t * 11
  754. y = 100 + 100 * contact_id + t * 11
  755. return test_multitouch.Touch(contact_id, x, y)
  756. def make_contacts(self, n, t=0):
  757. """
  758. Make multiple touch contacts that can move over time.
  759. Returns a list of `n` touch objects that are positioned at well-known
  760. locations. The value of `t` may be incremented over time to move the
  761. points along a linear path.
  762. """
  763. return [self.make_contact(id, t) for id in range(0, n)]
  764. def assert_contact(self, evdev, contact_ids, t=0):
  765. """
  766. Assert properties of a contact generated by make_contact.
  767. """
  768. contact_id = contact_ids.contact_id
  769. tracking_id = contact_ids.tracking_id
  770. slot_num = contact_ids.slot_num
  771. x = 50 + 10 * contact_id + t * 11
  772. y = 100 + 100 * contact_id + t * 11
  773. # If the data isn't supposed to be stored in any slots, there is
  774. # nothing we can check for in the evdev stream.
  775. if slot_num is None:
  776. assert tracking_id == -1
  777. return
  778. assert evdev.slots[slot_num][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == tracking_id
  779. if tracking_id != -1:
  780. assert evdev.slots[slot_num][libevdev.EV_ABS.ABS_MT_POSITION_X] == x
  781. assert evdev.slots[slot_num][libevdev.EV_ABS.ABS_MT_POSITION_Y] == y
  782. def assert_contacts(self, evdev, data, t=0):
  783. """
  784. Assert properties of a list of contacts generated by make_contacts.
  785. """
  786. for contact_ids in data:
  787. self.assert_contact(evdev, contact_ids, t)
  788. def test_contact_id_0(self):
  789. """
  790. Bring a finger in contact with the tablet, then hold it down and remove it.
  791. Ensure that even with contact ID = 0 which is usually given as an invalid
  792. touch event by most tablets with the exception of a few, that given the
  793. confidence bit is set to 1 it should process it as a valid touch to cover
  794. the few tablets using contact ID = 0 as a valid touch value.
  795. """
  796. uhdev = self.uhdev
  797. evdev = uhdev.get_evdev()
  798. t0 = test_multitouch.Touch(0, 50, 100)
  799. r = uhdev.event([t0])
  800. events = uhdev.next_sync_events()
  801. self.debug_reports(r, uhdev, events)
  802. slot = self.get_slot(uhdev, t0, 0)
  803. assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 1) in events
  804. assert evdev.slots[slot][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == 0
  805. assert evdev.slots[slot][libevdev.EV_ABS.ABS_MT_POSITION_X] == 50
  806. assert evdev.slots[slot][libevdev.EV_ABS.ABS_MT_POSITION_Y] == 100
  807. t0.tipswitch = False
  808. if uhdev.quirks is None or "VALID_IS_INRANGE" not in uhdev.quirks:
  809. t0.inrange = False
  810. r = uhdev.event([t0])
  811. events = uhdev.next_sync_events()
  812. self.debug_reports(r, uhdev, events)
  813. assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 0) in events
  814. assert evdev.slots[slot][libevdev.EV_ABS.ABS_MT_TRACKING_ID] == -1
  815. def test_confidence_false(self):
  816. """
  817. Bring a finger in contact with the tablet with confidence set to false.
  818. Ensure that the confidence bit being set to false should not result in a touch event.
  819. """
  820. uhdev = self.uhdev
  821. _evdev = uhdev.get_evdev()
  822. t0 = test_multitouch.Touch(1, 50, 100)
  823. t0.confidence = False
  824. r = uhdev.event([t0])
  825. events = uhdev.next_sync_events()
  826. self.debug_reports(r, uhdev, events)
  827. _slot = self.get_slot(uhdev, t0, 0)
  828. assert not events
  829. def test_confidence_multitouch(self):
  830. """
  831. Bring multiple fingers in contact with the tablet, some with the
  832. confidence bit set, and some without.
  833. Ensure that all confident touches are reported and that all non-
  834. confident touches are ignored.
  835. """
  836. uhdev = self.uhdev
  837. evdev = uhdev.get_evdev()
  838. touches = self.make_contacts(5)
  839. touches[0].confidence = False
  840. touches[2].confidence = False
  841. touches[4].confidence = False
  842. r = uhdev.event(touches)
  843. events = uhdev.next_sync_events()
  844. self.debug_reports(r, uhdev, events)
  845. assert libevdev.InputEvent(libevdev.EV_KEY.BTN_TOUCH, 1) in events
  846. self.assert_contacts(
  847. evdev,
  848. [
  849. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=None),
  850. self.ContactIds(contact_id=1, tracking_id=0, slot_num=0),
  851. self.ContactIds(contact_id=2, tracking_id=-1, slot_num=None),
  852. self.ContactIds(contact_id=3, tracking_id=1, slot_num=1),
  853. self.ContactIds(contact_id=4, tracking_id=-1, slot_num=None),
  854. ],
  855. )
  856. def confidence_change_assert_playback(self, uhdev, evdev, timeline):
  857. """
  858. Assert proper behavior of contacts that move and change tipswitch /
  859. confidence status over time.
  860. Given a `timeline` list of touch states to iterate over, verify
  861. that the contacts move and are reported as up/down as expected
  862. by the state of the tipswitch and confidence bits.
  863. """
  864. t = 0
  865. for state in timeline:
  866. touches = self.make_contacts(len(state), t)
  867. for item in zip(touches, state):
  868. item[0].tipswitch = item[1][1]
  869. item[0].confidence = item[1][2]
  870. r = uhdev.event(touches)
  871. events = uhdev.next_sync_events()
  872. self.debug_reports(r, uhdev, events)
  873. ids = [x[0] for x in state]
  874. self.assert_contacts(evdev, ids, t)
  875. t += 1
  876. def test_confidence_loss_a(self):
  877. """
  878. Transition a confident contact to a non-confident contact by
  879. first clearing the tipswitch.
  880. Ensure that the driver reports the transitioned contact as
  881. being removed and that other contacts continue to report
  882. normally. This mode of confidence loss is used by the
  883. DTH-2452.
  884. """
  885. uhdev = self.uhdev
  886. evdev = uhdev.get_evdev()
  887. self.confidence_change_assert_playback(
  888. uhdev,
  889. evdev,
  890. [
  891. # t=0: Contact 0 == Down + confident; Contact 1 == Down + confident
  892. # Both fingers confidently in contact
  893. [
  894. (
  895. self.ContactIds(contact_id=0, tracking_id=0, slot_num=0),
  896. True,
  897. True,
  898. ),
  899. (
  900. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  901. True,
  902. True,
  903. ),
  904. ],
  905. # t=1: Contact 0 == !Down + confident; Contact 1 == Down + confident
  906. # First finger looses confidence and clears only the tipswitch flag
  907. [
  908. (
  909. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  910. False,
  911. True,
  912. ),
  913. (
  914. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  915. True,
  916. True,
  917. ),
  918. ],
  919. # t=2: Contact 0 == !Down + !confident; Contact 1 == Down + confident
  920. # First finger has lost confidence and has both flags cleared
  921. [
  922. (
  923. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  924. False,
  925. False,
  926. ),
  927. (
  928. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  929. True,
  930. True,
  931. ),
  932. ],
  933. # t=3: Contact 0 == !Down + !confident; Contact 1 == Down + confident
  934. # First finger has lost confidence and has both flags cleared
  935. [
  936. (
  937. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  938. False,
  939. False,
  940. ),
  941. (
  942. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  943. True,
  944. True,
  945. ),
  946. ],
  947. ],
  948. )
  949. def test_confidence_loss_b(self):
  950. """
  951. Transition a confident contact to a non-confident contact by
  952. cleraing both tipswitch and confidence bits simultaneously.
  953. Ensure that the driver reports the transitioned contact as
  954. being removed and that other contacts continue to report
  955. normally. This mode of confidence loss is used by some
  956. AES devices.
  957. """
  958. uhdev = self.uhdev
  959. evdev = uhdev.get_evdev()
  960. self.confidence_change_assert_playback(
  961. uhdev,
  962. evdev,
  963. [
  964. # t=0: Contact 0 == Down + confident; Contact 1 == Down + confident
  965. # Both fingers confidently in contact
  966. [
  967. (
  968. self.ContactIds(contact_id=0, tracking_id=0, slot_num=0),
  969. True,
  970. True,
  971. ),
  972. (
  973. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  974. True,
  975. True,
  976. ),
  977. ],
  978. # t=1: Contact 0 == !Down + !confident; Contact 1 == Down + confident
  979. # First finger looses confidence and has both flags cleared simultaneously
  980. [
  981. (
  982. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  983. False,
  984. False,
  985. ),
  986. (
  987. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  988. True,
  989. True,
  990. ),
  991. ],
  992. # t=2: Contact 0 == !Down + !confident; Contact 1 == Down + confident
  993. # First finger has lost confidence and has both flags cleared
  994. [
  995. (
  996. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  997. False,
  998. False,
  999. ),
  1000. (
  1001. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1002. True,
  1003. True,
  1004. ),
  1005. ],
  1006. # t=3: Contact 0 == !Down + !confident; Contact 1 == Down + confident
  1007. # First finger has lost confidence and has both flags cleared
  1008. [
  1009. (
  1010. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  1011. False,
  1012. False,
  1013. ),
  1014. (
  1015. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1016. True,
  1017. True,
  1018. ),
  1019. ],
  1020. ],
  1021. )
  1022. def test_confidence_loss_c(self):
  1023. """
  1024. Transition a confident contact to a non-confident contact by
  1025. clearing only the confidence bit.
  1026. Ensure that the driver reports the transitioned contact as
  1027. being removed and that other contacts continue to report
  1028. normally.
  1029. """
  1030. uhdev = self.uhdev
  1031. evdev = uhdev.get_evdev()
  1032. self.confidence_change_assert_playback(
  1033. uhdev,
  1034. evdev,
  1035. [
  1036. # t=0: Contact 0 == Down + confident; Contact 1 == Down + confident
  1037. # Both fingers confidently in contact
  1038. [
  1039. (
  1040. self.ContactIds(contact_id=0, tracking_id=0, slot_num=0),
  1041. True,
  1042. True,
  1043. ),
  1044. (
  1045. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1046. True,
  1047. True,
  1048. ),
  1049. ],
  1050. # t=1: Contact 0 == Down + !confident; Contact 1 == Down + confident
  1051. # First finger looses confidence and clears only the confidence flag
  1052. [
  1053. (
  1054. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  1055. True,
  1056. False,
  1057. ),
  1058. (
  1059. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1060. True,
  1061. True,
  1062. ),
  1063. ],
  1064. # t=2: Contact 0 == !Down + !confident; Contact 1 == Down + confident
  1065. # First finger has lost confidence and has both flags cleared
  1066. [
  1067. (
  1068. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  1069. False,
  1070. False,
  1071. ),
  1072. (
  1073. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1074. True,
  1075. True,
  1076. ),
  1077. ],
  1078. # t=3: Contact 0 == !Down + !confident; Contact 1 == Down + confident
  1079. # First finger has lost confidence and has both flags cleared
  1080. [
  1081. (
  1082. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  1083. False,
  1084. False,
  1085. ),
  1086. (
  1087. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1088. True,
  1089. True,
  1090. ),
  1091. ],
  1092. ],
  1093. )
  1094. def test_confidence_gain_a(self):
  1095. """
  1096. Transition a contact that was always non-confident to confident.
  1097. Ensure that the confident contact is reported normally.
  1098. """
  1099. uhdev = self.uhdev
  1100. evdev = uhdev.get_evdev()
  1101. self.confidence_change_assert_playback(
  1102. uhdev,
  1103. evdev,
  1104. [
  1105. # t=0: Contact 0 == Down + !confident; Contact 1 == Down + confident
  1106. # Only second finger is confidently in contact
  1107. [
  1108. (
  1109. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=None),
  1110. True,
  1111. False,
  1112. ),
  1113. (
  1114. self.ContactIds(contact_id=1, tracking_id=0, slot_num=0),
  1115. True,
  1116. True,
  1117. ),
  1118. ],
  1119. # t=1: Contact 0 == Down + !confident; Contact 1 == Down + confident
  1120. # First finger gains confidence
  1121. [
  1122. (
  1123. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=None),
  1124. True,
  1125. False,
  1126. ),
  1127. (
  1128. self.ContactIds(contact_id=1, tracking_id=0, slot_num=0),
  1129. True,
  1130. True,
  1131. ),
  1132. ],
  1133. # t=2: Contact 0 == Down + confident; Contact 1 == Down + confident
  1134. # First finger remains confident
  1135. [
  1136. (
  1137. self.ContactIds(contact_id=0, tracking_id=1, slot_num=1),
  1138. True,
  1139. True,
  1140. ),
  1141. (
  1142. self.ContactIds(contact_id=1, tracking_id=0, slot_num=0),
  1143. True,
  1144. True,
  1145. ),
  1146. ],
  1147. # t=3: Contact 0 == Down + confident; Contact 1 == Down + confident
  1148. # First finger remains confident
  1149. [
  1150. (
  1151. self.ContactIds(contact_id=0, tracking_id=1, slot_num=1),
  1152. True,
  1153. True,
  1154. ),
  1155. (
  1156. self.ContactIds(contact_id=1, tracking_id=0, slot_num=0),
  1157. True,
  1158. True,
  1159. ),
  1160. ],
  1161. ],
  1162. )
  1163. def test_confidence_gain_b(self):
  1164. """
  1165. Transition a contact from non-confident to confident.
  1166. Ensure that the confident contact is reported normally.
  1167. """
  1168. uhdev = self.uhdev
  1169. evdev = uhdev.get_evdev()
  1170. self.confidence_change_assert_playback(
  1171. uhdev,
  1172. evdev,
  1173. [
  1174. # t=0: Contact 0 == Down + confident; Contact 1 == Down + confident
  1175. # First and second finger confidently in contact
  1176. [
  1177. (
  1178. self.ContactIds(contact_id=0, tracking_id=0, slot_num=0),
  1179. True,
  1180. True,
  1181. ),
  1182. (
  1183. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1184. True,
  1185. True,
  1186. ),
  1187. ],
  1188. # t=1: Contact 0 == Down + !confident; Contact 1 == Down + confident
  1189. # Firtst finger looses confidence
  1190. [
  1191. (
  1192. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  1193. True,
  1194. False,
  1195. ),
  1196. (
  1197. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1198. True,
  1199. True,
  1200. ),
  1201. ],
  1202. # t=2: Contact 0 == Down + confident; Contact 1 == Down + confident
  1203. # First finger gains confidence
  1204. [
  1205. (
  1206. self.ContactIds(contact_id=0, tracking_id=2, slot_num=0),
  1207. True,
  1208. True,
  1209. ),
  1210. (
  1211. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1212. True,
  1213. True,
  1214. ),
  1215. ],
  1216. # t=3: Contact 0 == !Down + confident; Contact 1 == Down + confident
  1217. # First finger goes up
  1218. [
  1219. (
  1220. self.ContactIds(contact_id=0, tracking_id=-1, slot_num=0),
  1221. False,
  1222. True,
  1223. ),
  1224. (
  1225. self.ContactIds(contact_id=1, tracking_id=1, slot_num=1),
  1226. True,
  1227. True,
  1228. ),
  1229. ],
  1230. ],
  1231. )