Update pygameControls/controller.py

Added support for getting connection type of controller. /JL
This commit is contained in:
2025-05-05 08:30:54 +02:00
parent 2285535276
commit 2a9746d510

View File

@@ -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'