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

Source file repositories/reference/linux-study-clean/tools/testing/selftests/hid/tests/base_gamepad.py

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/hid/tests/base_gamepad.py
Extension
.py
Size
7308 bytes
Lines
239
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

# SPDX-License-Identifier: GPL-2.0
import libevdev

from .base_device import BaseDevice
from hidtools.util import BusType


class InvalidHIDCommunication(Exception):
    pass


class GamepadData(object):
    pass


class AxisMapping(object):
    """Represents a mapping between a HID type
    and an evdev event"""

    def __init__(self, hid, evdev=None):
        self.hid = hid.lower()

        if evdev is None:
            evdev = f"ABS_{hid.upper()}"

        self.evdev = libevdev.evbit("EV_ABS", evdev)


class BaseGamepad(BaseDevice):
    buttons_map = {
        1: "BTN_SOUTH",
        2: "BTN_EAST",
        3: "BTN_C",
        4: "BTN_NORTH",
        5: "BTN_WEST",
        6: "BTN_Z",
        7: "BTN_TL",
        8: "BTN_TR",
        9: "BTN_TL2",
        10: "BTN_TR2",
        11: "BTN_SELECT",
        12: "BTN_START",
        13: "BTN_MODE",
        14: "BTN_THUMBL",
        15: "BTN_THUMBR",
    }

    axes_map = {
        "left_stick": {
            "x": AxisMapping("x"),
            "y": AxisMapping("y"),
        },
        "right_stick": {
            "x": AxisMapping("z"),
            "y": AxisMapping("Rz"),
        },
    }

    def __init__(self, rdesc, application="Game Pad", name=None, input_info=None):
        assert rdesc is not None
        super().__init__(name, application, input_info=input_info, rdesc=rdesc)
        self.buttons = (1, 2, 3)
        self._buttons = {}
        self.left = (127, 127)
        self.right = (127, 127)
        self.hat_switch = 15
        assert self.parsed_rdesc is not None

        self.fields = []
        for r in self.parsed_rdesc.input_reports.values():

Annotation

Implementation Notes