Ejemplo n.º 1
0
    def __init__(self, device):
        """Initializes the device data based on the given device.

        :param device pyGame joystick object
        """
        self._hardware_id = get_device_guid(device)
        self._windows_id = sdl2.SDL_JoystickInstanceID(device)
        self._vendor_id = sdl2.SDL_JoystickGetVendor(device)
        self._product_id = sdl2.SDL_JoystickGetProduct(device)
        name_object = sdl2.SDL_JoystickName(device)
        if name_object is None:
            self._name = "Unknown device"
            logging.getLogger("system").error(
                "Encountered an invalid device name for device {:d}".format(
                    self._windows_id))
        else:
            self._name = name_object.decode("utf-8")
        self._is_virtual = self._name == "vJoy Device"

        # Default mapping from axis id to physical axis number. This defaults
        # to a linear 1:1 mapping but for vJoy devices can change
        self._axes = []
        for i in range(sdl2.SDL_JoystickNumAxes(device)):
            self._axes.append((i + 1, i + 1))
        self._buttons = sdl2.SDL_JoystickNumButtons(device)
        self._hats = sdl2.SDL_JoystickNumHats(device)
        self._vjoy_id = 0
        self._device_id = common.DeviceIdentifier(self._hardware_id,
                                                  self._windows_id)
Ejemplo n.º 2
0
def get_device_guid(device):
    """Returns the GUID of the provided device.

    :param device SDL2 joystick device for which to get the GUID
    :return GUID for the provided device
    """
    vendor_id = sdl2.SDL_JoystickGetVendor(device)
    product_id = sdl2.SDL_JoystickGetProduct(device)
    return (vendor_id << 16) + product_id