Files
PyGame-Controller/pygameControls/controller.py
Lerking d26316d273 Update pygameControls/controller.py
Added connection type to class init. /JL
2025-05-05 09:02:09 +02:00

50 lines
2.1 KiB
Python

import pygame
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 .generic_controller import GenericController
from .logitech_dual_action_controller import LogitechDualActionController
__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,
"Xbox Series X Controller": XboxSeriesXController,
"Sony PLAYSTATION(R)3 Controller": SonyPlayStation3Controller,
"PLAYSTATION(R)3 Controller": PlayStation3Controller
}
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())))
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'