Files
PyGame-Controller/pygameControls/controller.py

56 lines
2.4 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 .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
__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())))
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'