Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/hid: add tests for the Raptor Mach 2 joystick

The only interesting bit is the HAT switch, and we use a BPF program
to fix it. So ensure this works correctly.

Link: https://lore.kernel.org/r/20240410-bpf_sources-v1-18-a8bf16033ef8@kernel.org
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>

+46 -1
+46 -1
tools/testing/selftests/hid/tests/test_gamepad.py
··· 10 10 import libevdev 11 11 import pytest 12 12 13 - from .base_gamepad import BaseGamepad, JoystickGamepad 13 + from .base_gamepad import BaseGamepad, JoystickGamepad, AxisMapping 14 14 from hidtools.util import BusType 15 15 16 16 import logging ··· 609 609 self.buttons = (1, 2, 4, 5, 7, 8, 14, 15, 13) 610 610 611 611 612 + class RaptorMach2Joystick(JoystickGamepad): 613 + axes_map = { 614 + "left_stick": { 615 + "x": AxisMapping("x"), 616 + "y": AxisMapping("y"), 617 + }, 618 + "right_stick": { 619 + "x": AxisMapping("z"), 620 + "y": AxisMapping("Rz"), 621 + }, 622 + } 623 + 624 + def __init__( 625 + self, 626 + name, 627 + rdesc=None, 628 + application="Joystick", 629 + input_info=(BusType.USB, 0x11C0, 0x5606), 630 + ): 631 + super().__init__(rdesc, application, name, input_info) 632 + self.buttons = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) 633 + self.hat_switch = 240 # null value is 240 as max is 239 634 + 635 + def event( 636 + self, *, left=(None, None), right=(None, None), hat_switch=None, buttons=None 637 + ): 638 + if hat_switch is not None: 639 + hat_switch *= 30 640 + 641 + return super().event( 642 + left=left, right=right, hat_switch=hat_switch, buttons=buttons 643 + ) 644 + 645 + 612 646 class TestSaitekGamepad(BaseTest.TestGamepad): 613 647 def create_device(self): 614 648 return SaitekGamepad() ··· 651 617 class TestAsusGamepad(BaseTest.TestGamepad): 652 618 def create_device(self): 653 619 return AsusGamepad() 620 + 621 + 622 + class TestRaptorMach2Joystick(BaseTest.TestGamepad): 623 + hid_bpfs = [("FR-TEC__Raptor-Mach-2.bpf.o", True)] 624 + 625 + def create_device(self): 626 + return RaptorMach2Joystick( 627 + "uhid test Sanmos Group FR-TEC Raptor MACH 2", 628 + rdesc="05 01 09 04 a1 01 05 01 85 01 05 01 09 30 75 10 95 01 15 00 26 ff 07 46 ff 07 81 02 05 01 09 31 75 10 95 01 15 00 26 ff 07 46 ff 07 81 02 05 01 09 33 75 10 95 01 15 00 26 ff 03 46 ff 03 81 02 05 00 09 00 75 10 95 01 15 00 26 ff 03 46 ff 03 81 02 05 01 09 32 75 10 95 01 15 00 26 ff 03 46 ff 03 81 02 05 01 09 35 75 10 95 01 15 00 26 ff 03 46 ff 03 81 02 05 01 09 34 75 10 95 01 15 00 26 ff 07 46 ff 07 81 02 05 01 09 36 75 10 95 01 15 00 26 ff 03 46 ff 03 81 02 05 09 19 01 2a 1d 00 15 00 25 01 75 01 96 80 00 81 02 05 01 09 39 26 ef 00 46 68 01 65 14 75 10 95 01 81 42 05 01 09 00 75 08 95 1d 81 01 15 00 26 ef 00 85 58 26 ff 00 46 ff 00 75 08 95 3f 09 00 91 02 85 59 75 08 95 80 09 00 b1 02 c0", 629 + input_info=(BusType.USB, 0x11C0, 0x5606), 630 + )