From 2a9746d510fddeccd3a394e6a95d90f6a69e86f7 Mon Sep 17 00:00:00 2001 From: Lerking Date: Mon, 5 May 2025 08:30:54 +0200 Subject: [PATCH] Update pygameControls/controller.py Added support for getting connection type of controller. /JL --- pygameControls/controller.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pygameControls/controller.py b/pygameControls/controller.py index a2c74f9..305585d 100644 --- a/pygameControls/controller.py +++ b/pygameControls/controller.py @@ -1,4 +1,5 @@ import pygame +from evdev import InputDevice, list_devices from .controlsbase import ControlsBase from .dualsense_controller import DualSenseController from .dualsense_edge_controller import DualSenseEdgeController @@ -11,7 +12,7 @@ from .playstation3_controller import PlayStation3Controller from .generic_controller import GenericController from .logitech_dual_action_controller import LogitechDualActionController -__version__ = "0.1.13" +__version__ = "0.2.0" CONTROLLERS = { "DualSense Wireless Controller": DualSenseController, @@ -29,7 +30,23 @@ class Controllers: def __init__(self, joy): self.controllers = [] if not joy.get_name() in CONTROLLERS: + self.get_connection_type(joy.get_name()) self.controllers.append(GenericController(joy)) else: + self.get_connection_type(joy.get_name()) self.controllers.append(CONTROLLERS[joy.get_name()](joy)) + + def get_connection_type(self, controller_name): + for path in list_devices() + device = InputDevice(path) + name = device.name.lower() + if name != controller_name.lower(): + continue + + if 'usb' in device.phys.lower(): + return 'usb' + elif 'bluetooth' in device.phys.lower(): + return 'bluetooth' + elif 'rf' in device.phys.lower() or 'wireless' in name: + return 'wireless' \ No newline at end of file