Path: blob/master/tools/testing/selftests/hid/tests/test_gamepad.py
26308 views
#!/bin/env python31# SPDX-License-Identifier: GPL-2.02# -*- coding: utf-8 -*-3#4# Copyright (c) 2019 Benjamin Tissoires <[email protected]>5# Copyright (c) 2019 Red Hat, Inc.6#78from . import base9import libevdev10import pytest1112from .base_gamepad import BaseGamepad, JoystickGamepad, AxisMapping13from hidtools.util import BusType14from .base import HidBpf1516import logging1718logger = logging.getLogger("hidtools.test.gamepad")192021class BaseTest:22class TestGamepad(base.BaseTestCase.TestUhid):23@pytest.fixture(autouse=True)24def send_initial_state(self):25"""send an empty report to initialize the axes"""26uhdev = self.uhdev2728r = uhdev.event()29events = uhdev.next_sync_events()30self.debug_reports(r, uhdev, events)3132def assert_button(self, button):33uhdev = self.uhdev34evdev = uhdev.get_evdev()35syn_event = self.syn_event3637buttons = {}38key = libevdev.evbit(uhdev.buttons_map[button])3940buttons[button] = True41r = uhdev.event(buttons=buttons)42expected_event = libevdev.InputEvent(key, 1)43events = uhdev.next_sync_events()44self.debug_reports(r, uhdev, events)45self.assertInputEventsIn((syn_event, expected_event), events)46assert evdev.value[key] == 14748buttons[button] = False49r = uhdev.event(buttons=buttons)50expected_event = libevdev.InputEvent(key, 0)51events = uhdev.next_sync_events()52self.debug_reports(r, uhdev, events)53self.assertInputEventsIn((syn_event, expected_event), events)54assert evdev.value[key] == 05556def test_buttons(self):57"""check for button reliability."""58uhdev = self.uhdev5960for b in uhdev.buttons:61self.assert_button(b)6263def test_dual_buttons(self):64"""check for button reliability when pressing 2 buttons"""65uhdev = self.uhdev66evdev = uhdev.get_evdev()67syn_event = self.syn_event6869# can change intended b1 b2 values70b1 = uhdev.buttons[0]71key1 = libevdev.evbit(uhdev.buttons_map[b1])72b2 = uhdev.buttons[1]73key2 = libevdev.evbit(uhdev.buttons_map[b2])7475buttons = {b1: True, b2: True}76r = uhdev.event(buttons=buttons)77expected_event0 = libevdev.InputEvent(key1, 1)78expected_event1 = libevdev.InputEvent(key2, 1)79events = uhdev.next_sync_events()80self.debug_reports(r, uhdev, events)81self.assertInputEventsIn(82(syn_event, expected_event0, expected_event1), events83)84assert evdev.value[key1] == 185assert evdev.value[key2] == 18687buttons = {b1: False, b2: None}88r = uhdev.event(buttons=buttons)89expected_event = libevdev.InputEvent(key1, 0)90events = uhdev.next_sync_events()91self.debug_reports(r, uhdev, events)92self.assertInputEventsIn((syn_event, expected_event), events)93assert evdev.value[key1] == 094assert evdev.value[key2] == 19596buttons = {b1: None, b2: False}97r = uhdev.event(buttons=buttons)98expected_event = libevdev.InputEvent(key2, 0)99events = uhdev.next_sync_events()100self.debug_reports(r, uhdev, events)101self.assertInputEventsIn((syn_event, expected_event), events)102assert evdev.value[key1] == 0103assert evdev.value[key2] == 0104105def _get_libevdev_abs_events(self, which):106"""Returns which ABS_* evdev axes are expected for the given stick"""107abs_map = self.uhdev.axes_map[which]108109x = abs_map["x"].evdev110y = abs_map["y"].evdev111112assert x113assert y114115return x, y116117def _test_joystick_press(self, which, data):118uhdev = self.uhdev119120libevdev_axes = self._get_libevdev_abs_events(which)121122r = None123if which == "left_stick":124r = uhdev.event(left=data)125else:126r = uhdev.event(right=data)127events = uhdev.next_sync_events()128self.debug_reports(r, uhdev, events)129130for i, d in enumerate(data):131if d is not None and d != 127:132assert libevdev.InputEvent(libevdev_axes[i], d) in events133else:134assert libevdev.InputEvent(libevdev_axes[i]) not in events135136def test_left_joystick_press_left(self):137"""check for the left joystick reliability"""138self._test_joystick_press("left_stick", (63, None))139self._test_joystick_press("left_stick", (0, 127))140141def test_left_joystick_press_right(self):142"""check for the left joystick reliability"""143self._test_joystick_press("left_stick", (191, 127))144self._test_joystick_press("left_stick", (255, None))145146def test_left_joystick_press_up(self):147"""check for the left joystick reliability"""148self._test_joystick_press("left_stick", (None, 63))149self._test_joystick_press("left_stick", (127, 0))150151def test_left_joystick_press_down(self):152"""check for the left joystick reliability"""153self._test_joystick_press("left_stick", (127, 191))154self._test_joystick_press("left_stick", (None, 255))155156def test_right_joystick_press_left(self):157"""check for the right joystick reliability"""158self._test_joystick_press("right_stick", (63, None))159self._test_joystick_press("right_stick", (0, 127))160161def test_right_joystick_press_right(self):162"""check for the right joystick reliability"""163self._test_joystick_press("right_stick", (191, 127))164self._test_joystick_press("right_stick", (255, None))165166def test_right_joystick_press_up(self):167"""check for the right joystick reliability"""168self._test_joystick_press("right_stick", (None, 63))169self._test_joystick_press("right_stick", (127, 0))170171def test_right_joystick_press_down(self):172"""check for the right joystick reliability"""173self._test_joystick_press("right_stick", (127, 191))174self._test_joystick_press("right_stick", (None, 255))175176@pytest.mark.skip_if_uhdev(177lambda uhdev: "Hat switch" not in uhdev.fields,178"Device not compatible, missing Hat switch usage",179)180@pytest.mark.parametrize(181"hat_value,expected_evdev,evdev_value",182[183(0, "ABS_HAT0Y", -1),184(2, "ABS_HAT0X", 1),185(4, "ABS_HAT0Y", 1),186(6, "ABS_HAT0X", -1),187],188)189def test_hat_switch(self, hat_value, expected_evdev, evdev_value):190uhdev = self.uhdev191192r = uhdev.event(hat_switch=hat_value)193events = uhdev.next_sync_events()194self.debug_reports(r, uhdev, events)195assert (196libevdev.InputEvent(197libevdev.evbit("EV_ABS", expected_evdev), evdev_value198)199in events200)201202203class SaitekGamepad(JoystickGamepad):204# fmt: off205report_descriptor = [2060x05, 0x01, # Usage Page (Generic Desktop) 02070x09, 0x04, # Usage (Joystick) 22080xa1, 0x01, # Collection (Application) 42090x09, 0x01, # .Usage (Pointer) 62100xa1, 0x00, # .Collection (Physical) 82110x85, 0x01, # ..Report ID (1) 102120x09, 0x30, # ..Usage (X) 122130x15, 0x00, # ..Logical Minimum (0) 142140x26, 0xff, 0x00, # ..Logical Maximum (255) 162150x35, 0x00, # ..Physical Minimum (0) 192160x46, 0xff, 0x00, # ..Physical Maximum (255) 212170x75, 0x08, # ..Report Size (8) 242180x95, 0x01, # ..Report Count (1) 262190x81, 0x02, # ..Input (Data,Var,Abs) 282200x09, 0x31, # ..Usage (Y) 302210x81, 0x02, # ..Input (Data,Var,Abs) 322220x05, 0x02, # ..Usage Page (Simulation Controls) 342230x09, 0xba, # ..Usage (Rudder) 362240x81, 0x02, # ..Input (Data,Var,Abs) 382250x09, 0xbb, # ..Usage (Throttle) 402260x81, 0x02, # ..Input (Data,Var,Abs) 422270x05, 0x09, # ..Usage Page (Button) 442280x19, 0x01, # ..Usage Minimum (1) 462290x29, 0x0c, # ..Usage Maximum (12) 482300x25, 0x01, # ..Logical Maximum (1) 502310x45, 0x01, # ..Physical Maximum (1) 522320x75, 0x01, # ..Report Size (1) 542330x95, 0x0c, # ..Report Count (12) 562340x81, 0x02, # ..Input (Data,Var,Abs) 582350x95, 0x01, # ..Report Count (1) 602360x75, 0x00, # ..Report Size (0) 622370x81, 0x03, # ..Input (Cnst,Var,Abs) 642380x05, 0x01, # ..Usage Page (Generic Desktop) 662390x09, 0x39, # ..Usage (Hat switch) 682400x25, 0x07, # ..Logical Maximum (7) 702410x46, 0x3b, 0x01, # ..Physical Maximum (315) 722420x55, 0x00, # ..Unit Exponent (0) 752430x65, 0x44, # ..Unit (Degrees^4,EngRotation) 772440x75, 0x04, # ..Report Size (4) 792450x81, 0x42, # ..Input (Data,Var,Abs,Null) 812460x65, 0x00, # ..Unit (None) 832470xc0, # .End Collection 852480x05, 0x0f, # .Usage Page (Vendor Usage Page 0x0f) 862490x09, 0x92, # .Usage (Vendor Usage 0x92) 882500xa1, 0x02, # .Collection (Logical) 902510x85, 0x02, # ..Report ID (2) 922520x09, 0xa0, # ..Usage (Vendor Usage 0xa0) 942530x09, 0x9f, # ..Usage (Vendor Usage 0x9f) 962540x25, 0x01, # ..Logical Maximum (1) 982550x45, 0x00, # ..Physical Maximum (0) 1002560x75, 0x01, # ..Report Size (1) 1022570x95, 0x02, # ..Report Count (2) 1042580x81, 0x02, # ..Input (Data,Var,Abs) 1062590x75, 0x06, # ..Report Size (6) 1082600x95, 0x01, # ..Report Count (1) 1102610x81, 0x03, # ..Input (Cnst,Var,Abs) 1122620x09, 0x22, # ..Usage (Vendor Usage 0x22) 1142630x75, 0x07, # ..Report Size (7) 1162640x25, 0x7f, # ..Logical Maximum (127) 1182650x81, 0x02, # ..Input (Data,Var,Abs) 1202660x09, 0x94, # ..Usage (Vendor Usage 0x94) 1222670x75, 0x01, # ..Report Size (1) 1242680x25, 0x01, # ..Logical Maximum (1) 1262690x81, 0x02, # ..Input (Data,Var,Abs) 1282700xc0, # .End Collection 1302710x09, 0x21, # .Usage (Vendor Usage 0x21) 1312720xa1, 0x02, # .Collection (Logical) 1332730x85, 0x0b, # ..Report ID (11) 1352740x09, 0x22, # ..Usage (Vendor Usage 0x22) 1372750x26, 0xff, 0x00, # ..Logical Maximum (255) 1392760x75, 0x08, # ..Report Size (8) 1422770x91, 0x02, # ..Output (Data,Var,Abs) 1442780x09, 0x53, # ..Usage (Vendor Usage 0x53) 1462790x25, 0x0a, # ..Logical Maximum (10) 1482800x91, 0x02, # ..Output (Data,Var,Abs) 1502810x09, 0x50, # ..Usage (Vendor Usage 0x50) 1522820x27, 0xfe, 0xff, 0x00, 0x00, # ..Logical Maximum (65534) 1542830x47, 0xfe, 0xff, 0x00, 0x00, # ..Physical Maximum (65534) 1592840x75, 0x10, # ..Report Size (16) 1642850x55, 0xfd, # ..Unit Exponent (237) 1662860x66, 0x01, 0x10, # ..Unit (Seconds,SILinear) 1682870x91, 0x02, # ..Output (Data,Var,Abs) 1712880x55, 0x00, # ..Unit Exponent (0) 1732890x65, 0x00, # ..Unit (None) 1752900x09, 0x54, # ..Usage (Vendor Usage 0x54) 1772910x55, 0xfd, # ..Unit Exponent (237) 1792920x66, 0x01, 0x10, # ..Unit (Seconds,SILinear) 1812930x91, 0x02, # ..Output (Data,Var,Abs) 1842940x55, 0x00, # ..Unit Exponent (0) 1862950x65, 0x00, # ..Unit (None) 1882960x09, 0xa7, # ..Usage (Vendor Usage 0xa7) 1902970x55, 0xfd, # ..Unit Exponent (237) 1922980x66, 0x01, 0x10, # ..Unit (Seconds,SILinear) 1942990x91, 0x02, # ..Output (Data,Var,Abs) 1973000x55, 0x00, # ..Unit Exponent (0) 1993010x65, 0x00, # ..Unit (None) 2013020xc0, # .End Collection 2033030x09, 0x5a, # .Usage (Vendor Usage 0x5a) 2043040xa1, 0x02, # .Collection (Logical) 2063050x85, 0x0c, # ..Report ID (12) 2083060x09, 0x22, # ..Usage (Vendor Usage 0x22) 2103070x26, 0xff, 0x00, # ..Logical Maximum (255) 2123080x45, 0x00, # ..Physical Maximum (0) 2153090x75, 0x08, # ..Report Size (8) 2173100x91, 0x02, # ..Output (Data,Var,Abs) 2193110x09, 0x5c, # ..Usage (Vendor Usage 0x5c) 2213120x26, 0x10, 0x27, # ..Logical Maximum (10000) 2233130x46, 0x10, 0x27, # ..Physical Maximum (10000) 2263140x75, 0x10, # ..Report Size (16) 2293150x55, 0xfd, # ..Unit Exponent (237) 2313160x66, 0x01, 0x10, # ..Unit (Seconds,SILinear) 2333170x91, 0x02, # ..Output (Data,Var,Abs) 2363180x55, 0x00, # ..Unit Exponent (0) 2383190x65, 0x00, # ..Unit (None) 2403200x09, 0x5b, # ..Usage (Vendor Usage 0x5b) 2423210x25, 0x7f, # ..Logical Maximum (127) 2443220x75, 0x08, # ..Report Size (8) 2463230x91, 0x02, # ..Output (Data,Var,Abs) 2483240x09, 0x5e, # ..Usage (Vendor Usage 0x5e) 2503250x26, 0x10, 0x27, # ..Logical Maximum (10000) 2523260x75, 0x10, # ..Report Size (16) 2553270x55, 0xfd, # ..Unit Exponent (237) 2573280x66, 0x01, 0x10, # ..Unit (Seconds,SILinear) 2593290x91, 0x02, # ..Output (Data,Var,Abs) 2623300x55, 0x00, # ..Unit Exponent (0) 2643310x65, 0x00, # ..Unit (None) 2663320x09, 0x5d, # ..Usage (Vendor Usage 0x5d) 2683330x25, 0x7f, # ..Logical Maximum (127) 2703340x75, 0x08, # ..Report Size (8) 2723350x91, 0x02, # ..Output (Data,Var,Abs) 2743360xc0, # .End Collection 2763370x09, 0x73, # .Usage (Vendor Usage 0x73) 2773380xa1, 0x02, # .Collection (Logical) 2793390x85, 0x0d, # ..Report ID (13) 2813400x09, 0x22, # ..Usage (Vendor Usage 0x22) 2833410x26, 0xff, 0x00, # ..Logical Maximum (255) 2853420x45, 0x00, # ..Physical Maximum (0) 2883430x91, 0x02, # ..Output (Data,Var,Abs) 2903440x09, 0x70, # ..Usage (Vendor Usage 0x70) 2923450x15, 0x81, # ..Logical Minimum (-127) 2943460x25, 0x7f, # ..Logical Maximum (127) 2963470x36, 0xf0, 0xd8, # ..Physical Minimum (-10000) 2983480x46, 0x10, 0x27, # ..Physical Maximum (10000) 3013490x91, 0x02, # ..Output (Data,Var,Abs) 3043500xc0, # .End Collection 3063510x09, 0x6e, # .Usage (Vendor Usage 0x6e) 3073520xa1, 0x02, # .Collection (Logical) 3093530x85, 0x0e, # ..Report ID (14) 3113540x09, 0x22, # ..Usage (Vendor Usage 0x22) 3133550x15, 0x00, # ..Logical Minimum (0) 3153560x26, 0xff, 0x00, # ..Logical Maximum (255) 3173570x35, 0x00, # ..Physical Minimum (0) 3203580x45, 0x00, # ..Physical Maximum (0) 3223590x91, 0x02, # ..Output (Data,Var,Abs) 3243600x09, 0x70, # ..Usage (Vendor Usage 0x70) 3263610x25, 0x7f, # ..Logical Maximum (127) 3283620x46, 0x10, 0x27, # ..Physical Maximum (10000) 3303630x91, 0x02, # ..Output (Data,Var,Abs) 3333640x09, 0x6f, # ..Usage (Vendor Usage 0x6f) 3353650x15, 0x81, # ..Logical Minimum (-127) 3373660x36, 0xf0, 0xd8, # ..Physical Minimum (-10000) 3393670x91, 0x02, # ..Output (Data,Var,Abs) 3423680x09, 0x71, # ..Usage (Vendor Usage 0x71) 3443690x15, 0x00, # ..Logical Minimum (0) 3463700x26, 0xff, 0x00, # ..Logical Maximum (255) 3483710x35, 0x00, # ..Physical Minimum (0) 3513720x46, 0x68, 0x01, # ..Physical Maximum (360) 3533730x91, 0x02, # ..Output (Data,Var,Abs) 3563740x09, 0x72, # ..Usage (Vendor Usage 0x72) 3583750x75, 0x10, # ..Report Size (16) 3603760x26, 0x10, 0x27, # ..Logical Maximum (10000) 3623770x46, 0x10, 0x27, # ..Physical Maximum (10000) 3653780x55, 0xfd, # ..Unit Exponent (237) 3683790x66, 0x01, 0x10, # ..Unit (Seconds,SILinear) 3703800x91, 0x02, # ..Output (Data,Var,Abs) 3733810x55, 0x00, # ..Unit Exponent (0) 3753820x65, 0x00, # ..Unit (None) 3773830xc0, # .End Collection 3793840x09, 0x77, # .Usage (Vendor Usage 0x77) 3803850xa1, 0x02, # .Collection (Logical) 3823860x85, 0x51, # ..Report ID (81) 3843870x09, 0x22, # ..Usage (Vendor Usage 0x22) 3863880x25, 0x7f, # ..Logical Maximum (127) 3883890x45, 0x00, # ..Physical Maximum (0) 3903900x75, 0x08, # ..Report Size (8) 3923910x91, 0x02, # ..Output (Data,Var,Abs) 3943920x09, 0x78, # ..Usage (Vendor Usage 0x78) 3963930xa1, 0x02, # ..Collection (Logical) 3983940x09, 0x7b, # ...Usage (Vendor Usage 0x7b) 4003950x09, 0x79, # ...Usage (Vendor Usage 0x79) 4023960x09, 0x7a, # ...Usage (Vendor Usage 0x7a) 4043970x15, 0x01, # ...Logical Minimum (1) 4063980x25, 0x03, # ...Logical Maximum (3) 4083990x91, 0x00, # ...Output (Data,Arr,Abs) 4104000xc0, # ..End Collection 4124010x09, 0x7c, # ..Usage (Vendor Usage 0x7c) 4134020x15, 0x00, # ..Logical Minimum (0) 4154030x26, 0xfe, 0x00, # ..Logical Maximum (254) 4174040x91, 0x02, # ..Output (Data,Var,Abs) 4204050xc0, # .End Collection 4224060x09, 0x92, # .Usage (Vendor Usage 0x92) 4234070xa1, 0x02, # .Collection (Logical) 4254080x85, 0x52, # ..Report ID (82) 4274090x09, 0x96, # ..Usage (Vendor Usage 0x96) 4294100xa1, 0x02, # ..Collection (Logical) 4314110x09, 0x9a, # ...Usage (Vendor Usage 0x9a) 4334120x09, 0x99, # ...Usage (Vendor Usage 0x99) 4354130x09, 0x97, # ...Usage (Vendor Usage 0x97) 4374140x09, 0x98, # ...Usage (Vendor Usage 0x98) 4394150x09, 0x9b, # ...Usage (Vendor Usage 0x9b) 4414160x09, 0x9c, # ...Usage (Vendor Usage 0x9c) 4434170x15, 0x01, # ...Logical Minimum (1) 4454180x25, 0x06, # ...Logical Maximum (6) 4474190x91, 0x00, # ...Output (Data,Arr,Abs) 4494200xc0, # ..End Collection 4514210xc0, # .End Collection 4524220x05, 0xff, # .Usage Page (Vendor Usage Page 0xff) 4534230x0a, 0x01, 0x03, # .Usage (Vendor Usage 0x301) 4554240xa1, 0x02, # .Collection (Logical) 4584250x85, 0x40, # ..Report ID (64) 4604260x0a, 0x02, 0x03, # ..Usage (Vendor Usage 0x302) 4624270xa1, 0x02, # ..Collection (Logical) 4654280x1a, 0x11, 0x03, # ...Usage Minimum (785) 4674290x2a, 0x20, 0x03, # ...Usage Maximum (800) 4704300x25, 0x10, # ...Logical Maximum (16) 4734310x91, 0x00, # ...Output (Data,Arr,Abs) 4754320xc0, # ..End Collection 4774330x0a, 0x03, 0x03, # ..Usage (Vendor Usage 0x303) 4784340x15, 0x00, # ..Logical Minimum (0) 4814350x27, 0xff, 0xff, 0x00, 0x00, # ..Logical Maximum (65535) 4834360x75, 0x10, # ..Report Size (16) 4884370x91, 0x02, # ..Output (Data,Var,Abs) 4904380xc0, # .End Collection 4924390x05, 0x0f, # .Usage Page (Vendor Usage Page 0x0f) 4934400x09, 0x7d, # .Usage (Vendor Usage 0x7d) 4954410xa1, 0x02, # .Collection (Logical) 4974420x85, 0x43, # ..Report ID (67) 4994430x09, 0x7e, # ..Usage (Vendor Usage 0x7e) 5014440x26, 0x80, 0x00, # ..Logical Maximum (128) 5034450x46, 0x10, 0x27, # ..Physical Maximum (10000) 5064460x75, 0x08, # ..Report Size (8) 5094470x91, 0x02, # ..Output (Data,Var,Abs) 5114480xc0, # .End Collection 5134490x09, 0x7f, # .Usage (Vendor Usage 0x7f) 5144500xa1, 0x02, # .Collection (Logical) 5164510x85, 0x0b, # ..Report ID (11) 5184520x09, 0x80, # ..Usage (Vendor Usage 0x80) 5204530x26, 0xff, 0x7f, # ..Logical Maximum (32767) 5224540x45, 0x00, # ..Physical Maximum (0) 5254550x75, 0x0f, # ..Report Size (15) 5274560xb1, 0x03, # ..Feature (Cnst,Var,Abs) 5294570x09, 0xa9, # ..Usage (Vendor Usage 0xa9) 5314580x25, 0x01, # ..Logical Maximum (1) 5334590x75, 0x01, # ..Report Size (1) 5354600xb1, 0x03, # ..Feature (Cnst,Var,Abs) 5374610x09, 0x83, # ..Usage (Vendor Usage 0x83) 5394620x26, 0xff, 0x00, # ..Logical Maximum (255) 5414630x75, 0x08, # ..Report Size (8) 5444640xb1, 0x03, # ..Feature (Cnst,Var,Abs) 5464650xc0, # .End Collection 5484660x09, 0xab, # .Usage (Vendor Usage 0xab) 5494670xa1, 0x03, # .Collection (Report) 5514680x85, 0x15, # ..Report ID (21) 5534690x09, 0x25, # ..Usage (Vendor Usage 0x25) 5554700xa1, 0x02, # ..Collection (Logical) 5574710x09, 0x26, # ...Usage (Vendor Usage 0x26) 5594720x09, 0x30, # ...Usage (Vendor Usage 0x30) 5614730x09, 0x32, # ...Usage (Vendor Usage 0x32) 5634740x09, 0x31, # ...Usage (Vendor Usage 0x31) 5654750x09, 0x33, # ...Usage (Vendor Usage 0x33) 5674760x09, 0x34, # ...Usage (Vendor Usage 0x34) 5694770x15, 0x01, # ...Logical Minimum (1) 5714780x25, 0x06, # ...Logical Maximum (6) 5734790xb1, 0x00, # ...Feature (Data,Arr,Abs) 5754800xc0, # ..End Collection 5774810xc0, # .End Collection 5784820x09, 0x89, # .Usage (Vendor Usage 0x89) 5794830xa1, 0x03, # .Collection (Report) 5814840x85, 0x16, # ..Report ID (22) 5834850x09, 0x8b, # ..Usage (Vendor Usage 0x8b) 5854860xa1, 0x02, # ..Collection (Logical) 5874870x09, 0x8c, # ...Usage (Vendor Usage 0x8c) 5894880x09, 0x8d, # ...Usage (Vendor Usage 0x8d) 5914890x09, 0x8e, # ...Usage (Vendor Usage 0x8e) 5934900x25, 0x03, # ...Logical Maximum (3) 5954910xb1, 0x00, # ...Feature (Data,Arr,Abs) 5974920xc0, # ..End Collection 5994930x09, 0x22, # ..Usage (Vendor Usage 0x22) 6004940x15, 0x00, # ..Logical Minimum (0) 6024950x26, 0xfe, 0x00, # ..Logical Maximum (254) 6044960xb1, 0x02, # ..Feature (Data,Var,Abs) 6074970xc0, # .End Collection 6094980x09, 0x90, # .Usage (Vendor Usage 0x90) 6104990xa1, 0x03, # .Collection (Report) 6125000x85, 0x50, # ..Report ID (80) 6145010x09, 0x22, # ..Usage (Vendor Usage 0x22) 6165020x26, 0xff, 0x00, # ..Logical Maximum (255) 6185030x91, 0x02, # ..Output (Data,Var,Abs) 6215040xc0, # .End Collection 6235050xc0, # End Collection 624506]507# fmt: on508509def __init__(self, rdesc=report_descriptor, name=None):510super().__init__(rdesc, name=name, input_info=(BusType.USB, 0x06A3, 0xFF0D))511self.buttons = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)512513514class AsusGamepad(BaseGamepad):515# fmt: off516report_descriptor = [5170x05, 0x01, # Usage Page (Generic Desktop) 05180x09, 0x05, # Usage (Game Pad) 25190xa1, 0x01, # Collection (Application) 45200x85, 0x01, # .Report ID (1) 65210x05, 0x09, # .Usage Page (Button) 85220x0a, 0x01, 0x00, # .Usage (Vendor Usage 0x01) 105230x0a, 0x02, 0x00, # .Usage (Vendor Usage 0x02) 135240x0a, 0x04, 0x00, # .Usage (Vendor Usage 0x04) 165250x0a, 0x05, 0x00, # .Usage (Vendor Usage 0x05) 195260x0a, 0x07, 0x00, # .Usage (Vendor Usage 0x07) 225270x0a, 0x08, 0x00, # .Usage (Vendor Usage 0x08) 255280x0a, 0x0e, 0x00, # .Usage (Vendor Usage 0x0e) 285290x0a, 0x0f, 0x00, # .Usage (Vendor Usage 0x0f) 315300x0a, 0x0d, 0x00, # .Usage (Vendor Usage 0x0d) 345310x05, 0x0c, # .Usage Page (Consumer Devices) 375320x0a, 0x24, 0x02, # .Usage (AC Back) 395330x0a, 0x23, 0x02, # .Usage (AC Home) 425340x15, 0x00, # .Logical Minimum (0) 455350x25, 0x01, # .Logical Maximum (1) 475360x75, 0x01, # .Report Size (1) 495370x95, 0x0b, # .Report Count (11) 515380x81, 0x02, # .Input (Data,Var,Abs) 535390x75, 0x01, # .Report Size (1) 555400x95, 0x01, # .Report Count (1) 575410x81, 0x03, # .Input (Cnst,Var,Abs) 595420x05, 0x01, # .Usage Page (Generic Desktop) 615430x75, 0x04, # .Report Size (4) 635440x95, 0x01, # .Report Count (1) 655450x25, 0x07, # .Logical Maximum (7) 675460x46, 0x3b, 0x01, # .Physical Maximum (315) 695470x66, 0x14, 0x00, # .Unit (Degrees,EngRotation) 725480x09, 0x39, # .Usage (Hat switch) 755490x81, 0x42, # .Input (Data,Var,Abs,Null) 775500x66, 0x00, 0x00, # .Unit (None) 795510x09, 0x01, # .Usage (Pointer) 825520xa1, 0x00, # .Collection (Physical) 845530x09, 0x30, # ..Usage (X) 865540x09, 0x31, # ..Usage (Y) 885550x09, 0x32, # ..Usage (Z) 905560x09, 0x35, # ..Usage (Rz) 925570x05, 0x02, # ..Usage Page (Simulation Controls) 945580x09, 0xc5, # ..Usage (Brake) 965590x09, 0xc4, # ..Usage (Accelerator) 985600x15, 0x00, # ..Logical Minimum (0) 1005610x26, 0xff, 0x00, # ..Logical Maximum (255) 1025620x35, 0x00, # ..Physical Minimum (0) 1055630x46, 0xff, 0x00, # ..Physical Maximum (255) 1075640x75, 0x08, # ..Report Size (8) 1105650x95, 0x06, # ..Report Count (6) 1125660x81, 0x02, # ..Input (Data,Var,Abs) 1145670xc0, # .End Collection 1165680x85, 0x02, # .Report ID (2) 1175690x05, 0x08, # .Usage Page (LEDs) 1195700x0a, 0x01, 0x00, # .Usage (Num Lock) 1215710x0a, 0x02, 0x00, # .Usage (Caps Lock) 1245720x0a, 0x03, 0x00, # .Usage (Scroll Lock) 1275730x0a, 0x04, 0x00, # .Usage (Compose) 1305740x15, 0x00, # .Logical Minimum (0) 1335750x25, 0x01, # .Logical Maximum (1) 1355760x75, 0x01, # .Report Size (1) 1375770x95, 0x04, # .Report Count (4) 1395780x91, 0x02, # .Output (Data,Var,Abs) 1415790x75, 0x04, # .Report Size (4) 1435800x95, 0x01, # .Report Count (1) 1455810x91, 0x03, # .Output (Cnst,Var,Abs) 1475820xc0, # End Collection 1495830x05, 0x0c, # Usage Page (Consumer Devices) 1505840x09, 0x01, # Usage (Consumer Control) 1525850xa1, 0x01, # Collection (Application) 1545860x85, 0x03, # .Report ID (3) 1565870x05, 0x01, # .Usage Page (Generic Desktop) 1585880x09, 0x06, # .Usage (Keyboard) 1605890xa1, 0x02, # .Collection (Logical) 1625900x05, 0x06, # ..Usage Page (Generic Device Controls) 1645910x09, 0x20, # ..Usage (Battery Strength) 1665920x15, 0x00, # ..Logical Minimum (0) 1685930x26, 0xff, 0x00, # ..Logical Maximum (255) 1705940x75, 0x08, # ..Report Size (8) 1735950x95, 0x01, # ..Report Count (1) 1755960x81, 0x02, # ..Input (Data,Var,Abs) 1775970x06, 0xbc, 0xff, # ..Usage Page (Vendor Usage Page 0xffbc) 1795980x0a, 0xad, 0xbd, # ..Usage (Vendor Usage 0xbdad) 1825990x75, 0x08, # ..Report Size (8) 1856000x95, 0x06, # ..Report Count (6) 1876010x81, 0x02, # ..Input (Data,Var,Abs) 1896020xc0, # .End Collection 1916030xc0, # End Collection 192604]605# fmt: on606607def __init__(self, rdesc=report_descriptor, name=None):608super().__init__(rdesc, name=name, input_info=(BusType.USB, 0x18D1, 0x2C40))609self.buttons = (1, 2, 4, 5, 7, 8, 14, 15, 13)610611612class RaptorMach2Joystick(JoystickGamepad):613axes_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}623624def __init__(625self,626name,627rdesc=None,628application="Joystick",629input_info=(BusType.USB, 0x11C0, 0x5606),630):631super().__init__(rdesc, application, name, input_info)632self.buttons = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)633self.hat_switch = 240 # null value is 240 as max is 239634635def event(636self, *, left=(None, None), right=(None, None), hat_switch=None, buttons=None637):638if hat_switch is not None:639hat_switch *= 30640641return super().event(642left=left, right=right, hat_switch=hat_switch, buttons=buttons643)644645646class TestSaitekGamepad(BaseTest.TestGamepad):647def create_device(self):648return SaitekGamepad()649650651class TestAsusGamepad(BaseTest.TestGamepad):652def create_device(self):653return AsusGamepad()654655656class TestRaptorMach2Joystick(BaseTest.TestGamepad):657hid_bpfs = [HidBpf("FR-TEC__Raptor-Mach-2.bpf.o", True)]658659def create_device(self):660return RaptorMach2Joystick(661"uhid test Sanmos Group FR-TEC Raptor MACH 2",662rdesc="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",663input_info=(BusType.USB, 0x11C0, 0x5606),664)665666667