GUID identification used to determine gamepad. /JL

This commit is contained in:
2025-05-06 20:47:01 +02:00
parent e99f8f761c
commit e02148c937
20 changed files with 287 additions and 204 deletions

View File

@@ -1,57 +1,21 @@
import pygame
from .globals import *
from evdev import InputDevice, list_devices
from .controlsbase import ControlsBase
from .dualsense_controller import DualSenseController
from .dualsense_edge_controller import DualSenseEdgeController
from .logitech_f310_controller import LogitechF310Controller
from .logitech_f510_controller import LogitechF510Controller
from .logitech_f710_controller import LogitechF710Controller
from .xbox_series_x_controller import XboxSeriesXController
from .sony_playstation3_controller import SonyPlayStation3Controller
from .playstation3_controller import PlayStation3Controller
from .sony_playstation4_controller import SonyPlayStation4Controller
from .playstation4_controller import PlayStation4Controller
from .generic_controller import GenericController
from .logitech_dual_action_controller import LogitechDualActionController
from .enums import InputType
from . import globals
__version__ = "0.2.0"
CONTROLLERS = {
"DualSense Wireless Controller": DualSenseController,
"DualSense Edge Wireless Controller": DualSenseEdgeController,
"Logitech Gamepad F310": LogitechF310Controller,
"Logitech Gamepad F510": LogitechF510Controller,
"Logitech Gamepad F710": LogitechF710Controller,
"Logitech Dual Action": LogitechDualActionController,
"Microsoft X-Box 360 pad": LogitechDualActionController
"Xbox Series X Controller": XboxSeriesXController,
"Sony PLAYSTATION(R)3 Controller": SonyPlayStation3Controller,
"PLAYSTATION(R)3 Controller": PlayStation3Controller,
"Sony PLAYSTATION(R)4 Controller": SonyPlayStation4Controller,
"PLAYSTATION(R)4 Controller": PlayStation4Controller
}
class Controllers:
def __init__(self, joy):
self.controllers = []
if not joy.get_name() in CONTROLLERS:
self.controllers.append(GenericController(joy, self.get_connection_type(joy.get_name())))
else:
self.controllers.append(CONTROLLERS[joy.get_name()](joy, self.get_connection_type(joy.get_name())))
cont = self.detect_controller(joy.get_guid())
print(cont)
self.controllers.append(cont(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'
def detect_controller(self, guid):
for gp in globals.GAMEPADS:
print(gp)
for p in globals.GAMEPADS[gp]:
print(p)
if p["guid"] != guid:
continue
return p["class"]
return globals.CONTROLLERS["Generic Controller"]