Skip to content

Commit 10c64d4

Browse files
PinglinuxJiri Kosina
authored andcommitted
selftests/hid-tablet: add ABS_DISTANCE test for stylus/pen
For pen and stylus, the ABS_Z event reports ABS_DISTANCE values in the hid generic kernel driver. This test is to make sure that the assignment is properly done for all pen and stylus tools. Same as tilt, distance is an optional event. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Ping Cheng <ping.cheng@wacom.com> Signed-off-by: Tatsunosuke Tobit <tatsunosuke.tobita@wacom.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 7953794 commit 10c64d4

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

tools/testing/selftests/hid/tests/test_tablet.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ class Pen(object):
452452
def __init__(self, x, y):
453453
self.x = x
454454
self.y = y
455+
self.distance = -10
455456
self.tipswitch = False
456457
self.tippressure = 15
457458
self.azimuth = 0
@@ -473,6 +474,7 @@ def restore(self):
473474
for i in [
474475
"x",
475476
"y",
477+
"distance",
476478
"tippressure",
477479
"azimuth",
478480
"width",
@@ -554,6 +556,7 @@ def move_to(self, pen, state, button):
554556
pen.tipswitch = False
555557
pen.tippressure = 0
556558
pen.azimuth = 0
559+
pen.distance = 0
557560
pen.inrange = False
558561
pen.width = 0
559562
pen.height = 0
@@ -868,6 +871,29 @@ def test_tolerated_broken_pen_states(self, state_list, scribble):
868871
state machine."""
869872
self._test_states(state_list, scribble, allow_intermediate_states=True)
870873

874+
@pytest.mark.skip_if_uhdev(
875+
lambda uhdev: "Z" not in uhdev.fields,
876+
"Device not compatible, missing Z usage",
877+
)
878+
@pytest.mark.parametrize("scribble", [True, False], ids=["scribble", "static"])
879+
@pytest.mark.parametrize(
880+
"state_list",
881+
[pytest.param(v, id=k) for k, v in PenState.legal_transitions().items()],
882+
)
883+
def test_z_reported_as_distance(self, state_list, scribble):
884+
"""Verify stylus Z values are reported as ABS_DISTANCE."""
885+
self._test_states(state_list, scribble, allow_intermediate_states=False)
886+
887+
uhdev = self.uhdev
888+
evdev = uhdev.get_evdev()
889+
p = Pen(0, 0)
890+
uhdev.move_to(p, PenState.PEN_IS_OUT_OF_RANGE, None)
891+
p = Pen(100, 200)
892+
uhdev.move_to(p, PenState.PEN_IS_IN_RANGE, None)
893+
p.distance = -1
894+
events = self.post(uhdev, p, None)
895+
assert evdev.value[libevdev.EV_ABS.ABS_DISTANCE] == -1
896+
871897

872898
class GXTP_pen(PenDigitizer):
873899
def event(self, pen, test_button):
@@ -1292,6 +1318,35 @@ def event(self, pen, button):
12921318
return rs
12931319

12941320

1321+
class Wacom_2d1f_014b(PenDigitizer):
1322+
"""
1323+
Pen that reports distance values with HID_GD_Z usage.
1324+
"""
1325+
def __init__(
1326+
self,
1327+
name,
1328+
rdesc_str=None,
1329+
rdesc=None,
1330+
application="Pen",
1331+
physical="Stylus",
1332+
input_info=(BusType.USB, 0x2D1F, 0x014B),
1333+
evdev_name_suffix=None,
1334+
):
1335+
super().__init__(
1336+
name, rdesc_str, rdesc, application, physical, input_info, evdev_name_suffix
1337+
)
1338+
1339+
def match_evdev_rule(self, application, evdev):
1340+
# there are 2 nodes created by the device, only one matters
1341+
return evdev.name.endswith("Stylus")
1342+
1343+
def event(self, pen, test_button):
1344+
# this device reports the distance through Z
1345+
pen.z = pen.distance
1346+
1347+
return super().event(pen, test_button)
1348+
1349+
12951350
################################################################################
12961351
#
12971352
# Windows 7 compatible devices
@@ -1504,3 +1559,19 @@ def create_device(self):
15041559
rdesc="05 0d 09 02 a1 01 85 0a 09 20 a1 01 09 42 09 44 09 43 09 3c 09 45 15 00 25 01 75 01 95 06 81 02 09 32 75 01 95 01 81 02 81 03 05 01 09 30 09 31 55 0d 65 33 26 ff 7f 35 00 46 00 08 75 10 95 02 81 02 05 0d 09 30 26 ff 3f 75 10 95 01 81 02 09 3d 09 3e 15 a6 25 5a 75 08 95 02 81 02 c0 c0 05 0d 09 04 a1 01 85 04 09 22 a1 02 05 0d 95 01 75 06 09 51 15 00 25 3f 81 02 09 42 25 01 75 01 95 01 81 02 75 01 95 01 81 03 05 01 75 10 55 0e 65 11 09 30 26 ff 7f 35 00 46 15 0c 81 42 09 31 26 ff 7f 46 cb 06 81 42 05 0d 09 30 26 ff 1f 75 10 95 01 81 02 c0 05 0d 09 22 a1 02 05 0d 95 01 75 06 09 51 15 00 25 3f 81 02 09 42 25 01 75 01 95 01 81 02 75 01 95 01 81 03 05 01 75 10 55 0e 65 11 09 30 26 ff 7f 35 00 46 15 0c 81 42 09 31 26 ff 7f 46 cb 06 81 42 05 0d 09 30 26 ff 1f 75 10 95 01 81 02 c0 05 0d 09 56 55 00 65 00 27 ff ff ff 7f 95 01 75 20 81 02 09 54 25 7f 95 01 75 08 81 02 75 08 95 08 81 03 85 05 09 55 25 0a 75 08 95 01 b1 02 06 00 ff 09 c5 85 06 15 00 26 ff 00 75 08 96 00 01 b1 02 c0",
15051560
input_info=(BusType.USB, 0x256C, 0x006B),
15061561
)
1562+
1563+
1564+
################################################################################
1565+
#
1566+
# Devices Reporting Distance
1567+
#
1568+
################################################################################
1569+
1570+
1571+
class TestWacom_2d1f_014b(BaseTest.TestTablet):
1572+
def create_device(self):
1573+
return Wacom_2d1f_014b(
1574+
"uhid test Wacom 2d1f_014b",
1575+
rdesc="05 0d 09 02 a1 01 85 02 09 20 a1 00 09 42 09 44 09 45 09 3c 09 5a 09 32 15 00 25 01 75 01 95 06 81 02 95 02 81 03 05 01 09 30 26 88 3e 46 88 3e 65 11 55 0d 75 10 95 01 81 02 09 31 26 60 53 46 60 53 81 02 05 0d 09 30 26 ff 0f 45 00 65 00 55 00 81 02 06 00 ff 09 04 75 08 26 ff 00 46 ff 00 65 11 55 0e 81 02 05 0d 09 3d 75 10 16 d8 dc 26 28 23 36 d8 dc 46 28 23 65 14 81 02 09 3e 81 02 05 01 09 32 16 01 ff 25 00 36 01 ff 45 00 65 11 81 02 05 0d 09 56 15 00 27 ff ff 00 00 35 00 47 ff ff 00 00 66 01 10 55 0c 81 02 45 00 65 00 55 00 c0 09 00 75 08 26 ff 00 b1 12 85 03 09 00 95 12 b1 12 85 05 09 00 95 04 b1 02 85 06 09 00 95 24 b1 02 85 16 09 00 15 00 26 ff 00 95 06 b1 02 85 17 09 00 95 0c b1 02 85 19 09 00 95 01 b1 02 85 0a 09 00 75 08 95 01 15 10 26 ff 00 b1 02 85 1e 09 00 95 10 b1 02 c0 06 00 ff 09 00 a1 01 85 09 05 0d 09 20 a1 00 09 00 15 00 26 ff 00 75 08 95 10 81 02 c0 09 00 95 03 b1 12 c0 06 00 ff 09 02 a1 01 85 07 09 00 96 09 01 b1 02 85 08 09 00 95 03 81 02 09 00 b1 02 85 0e 09 00 96 0a 01 b1 02 c0 05 0d 09 02 a1 01 85 1a 09 20 a1 00 09 42 09 44 09 45 09 3c 09 5a 09 32 15 00 25 01 75 01 95 06 81 02 09 38 25 03 75 02 95 01 81 02 05 01 09 30 26 88 3e 46 88 3e 65 11 55 0d 75 10 95 01 81 02 09 31 26 60 53 46 60 53 81 02 05 0d 09 30 26 ff 0f 46 b0 0f 66 11 e1 55 02 81 02 06 00 ff 09 04 75 08 26 ff 00 46 ff 00 65 11 55 0e 81 02 05 0d 09 3d 75 10 16 d8 dc 26 28 23 36 d8 dc 46 28 23 65 14 81 02 09 3e 81 02 05 01 09 32 16 01 ff 25 00 36 01 ff 45 00 65 11 81 02 05 0d 09 56 15 00 27 ff ff 00 00 35 00 47 ff ff 00 00 66 01 10 55 0c 81 02 45 00 65 00 55 00 c0 c0 06 00 ff 09 00 a1 01 85 1b 05 0d 09 20 a1 00 09 00 26 ff 00 75 08 95 10 81 02 c0 c0",
1576+
input_info=(BusType.USB, 0x2D1F, 0x014B),
1577+
)

0 commit comments

Comments
 (0)