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

@@ -30,7 +30,7 @@ class TextPrint:
def main(): def main():
# Set the width and height of the screen (width, height), and name the window. # Set the width and height of the screen (width, height), and name the window.
screen = pygame.display.set_mode((500, 700)) screen = pygame.display.set_mode((800, 700))
pygame.display.set_caption("Joystick example") pygame.display.set_caption("Joystick example")
# Used to manage how fast the screen updates. # Used to manage how fast the screen updates.

55
joystick_debug.py Normal file
View File

@@ -0,0 +1,55 @@
import os
import pygame
from evdev import InputDevice, list_devices
def format_vidpid(info):
return f"{info.vendor:04x}:{info.product:04x}"
def get_evdev_devices():
evdev_devices = {}
for path in list_devices():
try:
dev = InputDevice(path)
evdev_devices[os.path.basename(path)] = {
'name': dev.name,
'phys': dev.phys,
'vidpid': format_vidpid(dev.info),
'path': path
}
except Exception:
pass
return evdev_devices
def match_evdev_to_pygame():
pygame.init()
pygame.joystick.init()
evdev_devices = get_evdev_devices()
for i in range(pygame.joystick.get_count()):
js = pygame.joystick.Joystick(i)
js.init()
name = js.get_name()
guid = js.get_guid()
# Try to guess the matching evdev device based on name
matched = None
for ev in evdev_devices.values():
if name.lower() in ev['name'].lower() or ev['name'].lower() in name.lower():
matched = ev
break
print(f"Joystick {i}:")
print(f" pygame name : {name}")
print(f" pygame guid : {guid}")
if matched:
print(f" evdev name : {matched['name']}")
print(f" path : {matched['path']}")
print(f" phys : {matched['phys']}")
print(f" VID:PID : {matched['vidpid']}")
else:
print(f" evdev info : [not matched]")
print("-" * 40)
if __name__ == "__main__":
match_evdev_to_pygame()

View File

@@ -1,8 +1,10 @@
import pygame import pygame
import pygameControls as PC import pygameControls as PC
from pygameControls import globals
if __name__ == "__main__": if __name__ == "__main__":
pygame.init() pygame.init()
globals.init()
done = False done = False

View File

@@ -1,57 +1,21 @@
import pygame import pygame
from .globals import * from . import globals
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" __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: class Controllers:
def __init__(self, joy): def __init__(self, joy):
self.controllers = [] self.controllers = []
if not joy.get_name() in CONTROLLERS: cont = self.detect_controller(joy.get_guid())
self.controllers.append(GenericController(joy, self.get_connection_type(joy.get_name()))) print(cont)
else: self.controllers.append(cont(joy))
self.controllers.append(CONTROLLERS[joy.get_name()](joy, self.get_connection_type(joy.get_name())))
def get_connection_type(self, controller_name): def detect_controller(self, guid):
for path in list_devices() for gp in globals.GAMEPADS:
device = InputDevice(path) print(gp)
name = device.name.lower() for p in globals.GAMEPADS[gp]:
if name != controller_name.lower(): print(p)
if p["guid"] != guid:
continue continue
return p["class"]
if 'usb' in device.phys.lower(): return globals.CONTROLLERS["Generic Controller"]
return 'usb'
elif 'bluetooth' in device.phys.lower():
return 'bluetooth'
elif 'rf' in device.phys.lower() or 'wireless' in name:
return 'wireless'

View File

@@ -1,5 +1,5 @@
from pygameControls.controlsbase import ControlsBase from pygameControls.controlsbase import ControlsBase
from enums import ConnectionType from .enums import ConnectionType
from pydualsense import * from pydualsense import *
BATTERY_STATE = { BATTERY_STATE = {
@@ -12,12 +12,11 @@ BATTERY_STATE = {
} }
class DualSenseController(ControlsBase): class DualSenseController(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = pydualsense() self.device = pydualsense()
self.device.init() self.device.init()
self.name = self.device.device.get_product_string() self.name = self.device.device.get_product_string()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.powerlevel = self.device.battery.Level self.powerlevel = self.device.battery.Level
self.batterystate = BATTERY_STATE[str(self.device.battery.State)] self.batterystate = BATTERY_STATE[str(self.device.battery.State)]
self.set_player_id(PlayerID.PLAYER_1) self.set_player_id(PlayerID.PLAYER_1)
@@ -43,7 +42,6 @@ class DualSenseController(ControlsBase):
print(f"{self.name} connected") print(f"{self.name} connected")
print(f"Power level: {self.powerlevel}") print(f"Power level: {self.powerlevel}")
print(f"Battery state: {self.batterystate}") print(f"Battery state: {self.batterystate}")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.close() self.device.close()

View File

@@ -4,12 +4,11 @@ from pydualsense import *
class DualSenseEdgeController(ControlsBase): class DualSenseEdgeController(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = pydualsense() self.device = pydualsense()
self.device.init() self.device.init()
self.name = self.device.device.get_product_string() self.name = self.device.device.get_product_string()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.powerlevel = self.device.battery.Level self.powerlevel = self.device.battery.Level
self.batterystate = BATTERY_STATE[str(self.device.battery.State)] self.batterystate = BATTERY_STATE[str(self.device.battery.State)]
self.set_player_id(PlayerID.PLAYER_1) self.set_player_id(PlayerID.PLAYER_1)
@@ -43,7 +42,6 @@ class DualSenseEdgeController(ControlsBase):
print(f"{self.name} connected") print(f"{self.name} connected")
print(f"Power level: {self.powerlevel}") print(f"Power level: {self.powerlevel}")
print(f"Battery state: {self.batterystate}") print(f"Battery state: {self.batterystate}")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.close() self.device.close()

View File

@@ -3,12 +3,11 @@ from pygameControls.controlsbase import ControlsBase
from enums import ConnectionType from enums import ConnectionType
class GenericController(ControlsBase): class GenericController(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -31,7 +30,6 @@ class GenericController(ControlsBase):
"logo button": None "logo button": None
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
pass pass

View File

@@ -1,5 +1,21 @@
from .enums import ConnectionType, InputType from .enums import ConnectionType, InputType
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
def init():
global VID_PID
VID_PID = { VID_PID = {
"046d:c216": "Logitech Gamepad F310", "046d:c216": "Logitech Gamepad F310",
"046d:c21d": "Microsoft X-Box 360 pad", "046d:c21d": "Microsoft X-Box 360 pad",
@@ -11,7 +27,7 @@ VID_PID = {
"054c:0ce6": "DualSense Wireless Controller", "054c:0ce6": "DualSense Wireless Controller",
"054c:0df2": "DualSense Wireless Controller", "054c:0df2": "DualSense Wireless Controller",
} }
global CONTROLLERS
CONTROLLERS = { CONTROLLERS = {
"DualSense Wireless Controller": DualSenseController, "DualSense Wireless Controller": DualSenseController,
"DualSense Edge Wireless Controller": DualSenseEdgeController, "DualSense Edge Wireless Controller": DualSenseEdgeController,
@@ -19,99 +35,173 @@ CONTROLLERS = {
"Logitech Gamepad F510": LogitechF510Controller, "Logitech Gamepad F510": LogitechF510Controller,
"Logitech Gamepad F710": LogitechF710Controller, "Logitech Gamepad F710": LogitechF710Controller,
"Logitech Dual Action": LogitechDualActionController, "Logitech Dual Action": LogitechDualActionController,
"Microsoft X-Box 360 pad": LogitechDualActionController "Microsoft X-Box 360 pad": LogitechDualActionController,
"Xbox Series X Controller": XboxSeriesXController, "Xbox Series X Controller": XboxSeriesXController,
"Sony PLAYSTATION(R)3 Controller": SonyPlayStation3Controller, "Sony PLAYSTATION(R)3 Controller": SonyPlayStation3Controller,
"PLAYSTATION(R)3 Controller": PlayStation3Controller, "PLAYSTATION(R)3 Controller": PlayStation3Controller,
"Sony PLAYSTATION(R)4 Controller": SonyPlayStation4Controller, "Sony PLAYSTATION(R)4 Controller": SonyPlayStation4Controller,
"PLAYSTATION(R)4 Controller": PlayStation4Controller "PLAYSTATION(R)4 Controller": PlayStation4Controller,
"Generic Controller": GenericController
} }
global GAMEPADS
GAMEPADS = { GAMEPADS = {
"Sony DualSense (PS5)": { "Sony Controller": [
[ {
"vidpid": "054c:0ce6", "vidpid": "054c:0ce6",
"guid": "030000004c0500000c0e000011010000", "guid": "0300fd574c050000e60c000011810000",
"connection": ConnectionType.USB, "connection": ConnectionType.USB,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name": ["DualSense Wireless Controller"], "name": [
"class": CONTROLLERS[DualSenseController] "Sony Interactive Entertainment DualSense Wireless Controller",
"Sony Corp. DualSense wireless controller (PS5)",
"DualSense Wireless Controller"
], ],
[ "class": CONTROLLERS["DualSense Wireless Controller"]
},
{
"vidpid": "054c:0df2", "vidpid": "054c:0df2",
"guid": "030000004c0500000c0e000011010000", "guid": "050057564c050000e60c000000810000",
"connection": ConnectionType.BLUETOOTH, "connection": ConnectionType.BLUETOOTH,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name" ["DualSense Wireless Controller"], "name": [
"class": CONTROLLERS[DualSenseController] "DualSense Wireless Controller"
] ],
"class": CONTROLLERS["DualSense Wireless Controller"]
}, },
"Sony DualSense Edge (PS5)": { {
[ "vidpid": "054c:0dfc",
"vidhid": "054c:0dfc", "guid": "",
"connection": ConnectionType.USB, "connection": ConnectionType.USB,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name" ["DualSense Edge Wireless Controller"], "name": ["DualSense Edge Wireless Controller"],
"class": CONTROLLERS[DualSenseEdgeController] "class": CONTROLLERS["DualSense Edge Wireless Controller"]
], },
[ {
"vidhid": "054c:0dfc", "vidpid": "054c:0dfc",
"guid": "",
"connection": ConnectionType.BLUETOOTH, "connection": ConnectionType.BLUETOOTH,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name": ["DualSense Edge Wireless Controller"], "name": ["DualSense Edge Wireless Controller"],
"class": CONTROLLERS[DualSenseEdgeController] "class": CONTROLLERS["DualSense Edge Wireless Controller"]
]
}, },
"Sony DualShock 3 (PS3)": { {
[ "vidpid": "054c:0268",
"vidhid": "054c:0268", "guid": "0300afd34c0500006802000011810000",
"connection": ConnectionType.USB, "connection": ConnectionType.USB,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name": ["PLAYSTATION(R) 3 Controller"],
"class": CONTROLLERS[PlayStation3Controller]
],
[
"vidhid": None,
"connection": ConnectionType.BLUETOOTH,
"input": InputType.DirectInput,
"name": ["Sony PLAYSTATION(R)3 Controller"], "name": ["Sony PLAYSTATION(R)3 Controller"],
"class": CONTROLLERS[SonyPlayStation3Controller] "class": CONTROLLERS["Sony PLAYSTATION(R)3 Controller"]
]
}, },
"Sony DualShock 4 v1 (PS4)": { {
[ "vidpid": "",
"vidhid": "054c:05c4", "guid": "0500f9d24c0500006802000000800000",
"connection": ConnectionType.BLUETOOTH,
"input": InputType.DirectInput,
"name": ["PLAYSTATION(R)3 Controller"],
"class": CONTROLLERS["PLAYSTATION(R)3 Controller"]
},
{
"vidpid": "054c:05c4",
"guid": "", "guid": "",
"connection": ConnectionType.USB, "connection": ConnectionType.USB,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name": ["DualShock 4 v1 Controller"], "name": ["DualShock 4 v1 Controller"],
"class": CONTROLLERS["PLAYSTATION(R)4 Controller"] "class": CONTROLLERS["PLAYSTATION(R)4 Controller"]
], },
[ {
"vidhid": "054c:05c4", "vidpid": "054c:05c4",
"guid": "", "guid": "",
"connection": ConnectionType.BLUETOOTH, "connection": ConnectionType.BLUETOOTH,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name": ["DualShock 4 v1 Controller"], "name": ["DualShock 4 v1 Controller"],
"class": CONTROLLERS["Sony PLAYSTATION(R)4 Controller"] "class": CONTROLLERS["Sony PLAYSTATION(R)4 Controller"]
]
}, },
"Sony DualShock 4 v2 (PS4)": { {
[ "vidpid": "054c:09cc",
"vidhid": "054c:09cc",
"guid": "", "guid": "",
"connection": ConnectionType.USB, "connection": ConnectionType.USB,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name": ["DualShock 4 v2 Controller"], "name": ["DualShock 4 v2 Controller"],
"class": CONTROLLERS["PLAYSTATION(R)4 Controller"] "class": CONTROLLERS["PLAYSTATION(R)4 Controller"]
], },
[ {
"vidhid": "054c:09cc", "vidpid": "054c:09cc",
"guid": "", "guid": "",
"connection": ConnectionType.BLUETOOTH, "connection": ConnectionType.BLUETOOTH,
"input": InputType.DirectInput, "input": InputType.DirectInput,
"name": ["DualShock 4 v2 Controller"], "name": ["DualShock 4 v2 Controller"],
"class": CONTROLLERS["Sony PLAYSTATION(R)4 Controller"] "class": CONTROLLERS["Sony PLAYSTATION(R)4 Controller"]
}
],
"Microsoft Controller": [
{
"vidpid": "045e:0b12",
"guid": "0300509d5e040000120b000017050000",
"connection": ConnectionType.USB,
"input": InputType.XInput,
"name": [
"Xbox Series X Controller",
"Microsoft Corp. Xbox Controller"
],
"class": CONTROLLERS["Xbox Series X Controller"]
},
{
"vidpid": "045e:0b13",
"guid": "0500509d5e040000130b000023050000",
"connection": ConnectionType.BLUETOOTH,
"input": InputType.XInput,
"name": [
"Xbox Series X Controller",
"Xbox Wireless Controller"
],
"class": CONTROLLERS["Xbox Series X Controller"]
}
],
"Logitech Controller": [
{
"vidpid": "046d:c21d",
"guid": "030005ff6d0400001dc2000014400000",
"connection": ConnectionType.USB,
"input": InputType.XInput,
"name": [
"Logitech, Inc. F310 Gamepad [XInput Mode]",
"Logitech Gamepad F310"
],
"class": CONTROLLERS["Logitech Gamepad F310"]
},
{
"vidpid": "046d:c216",
"guid": "0300040e6d04000016c2000011010000",
"connection": ConnectionType.USB,
"input": InputType.DirectInput,
"name": [
"Logitech, Inc. F310 Gamepad [DirectInput Mode]",
"Logitech Dual Action",
"Logitech Logitech Dual Action"
],
"class": CONTROLLERS["Logitech Dual Action"]
},
{
"vidpid": "046d:c21d",
"guid": "",
"connection": ConnectionType.USB,
"input": InputType.XInput,
"name": [
"Logitech, Inc. F710 Gamepad [XInput Mode]",
"Logitech Gamepad F710"
],
"class": CONTROLLERS["Logitech Gamepad F710"]
},
{
"vidpid": "046d:c216",
"guid": "",
"connection": ConnectionType.USB,
"input": InputType.DirectInput,
"name": [
"Logitech, Inc. F710 Gamepad [DirectInput Mode]",
"Logitech Dual Action"
],
"class": CONTROLLERS["Logitech Dual Action"]
}
] ]
} }
}

View File

@@ -17,12 +17,11 @@ from pygameControls.controlsbase import ControlsBase
from enums import ConnectionType from enums import ConnectionType
class LogitechDualActionController(ControlsBase): class LogitechDualActionController(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.powerlevel = self.device.get_power_level() self.powerlevel = self.device.get_power_level()
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
@@ -46,7 +45,6 @@ class LogitechDualActionController(ControlsBase):
"logo button": None "logo button": None
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
pass pass

View File

@@ -17,12 +17,11 @@ from pygameControls.controlsbase import ControlsBase
from enums import ConnectionType from enums import ConnectionType
class LogitechF310Controller(ControlsBase): class LogitechF310Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.powerlevel = self.device.get_power_level() self.powerlevel = self.device.get_power_level()
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
@@ -44,7 +43,6 @@ class LogitechF310Controller(ControlsBase):
"logo button": 8 "logo button": 8
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
pass pass

View File

@@ -10,12 +10,11 @@ from pygameControls.controlsbase import ControlsBase
from enums import ConnectionType from enums import ConnectionType
class LogitechF510Controller(ControlsBase): class LogitechF510Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.numaxis: int = self.device.get_numaxis() self.numaxis: int = self.device.get_numaxis()
self.axis: list = [] self.axis: list = []
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -36,7 +35,6 @@ class LogitechF510Controller(ControlsBase):
"logo button": 8 "logo button": 8
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
pass pass

View File

@@ -8,12 +8,11 @@ from pygameControls.controlsbase import ControlsBase
from enums import ConnectionType from enums import ConnectionType
class LogitechF710Controller(ControlsBase): class LogitechF710Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.numaxis: int = self.device.get_numaxis() self.numaxis: int = self.device.get_numaxis()
self.axis: list = [] self.axis: list = []
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -34,7 +33,6 @@ class LogitechF710Controller(ControlsBase):
"logo button": 8 "logo button": 8
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
pass pass

View File

@@ -3,12 +3,11 @@ from enums import ConnectionType
import pygame import pygame
class PlayStation3Controller(ControlsBase): class PlayStation3Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -33,7 +32,6 @@ class PlayStation3Controller(ControlsBase):
"right button": 16 "right button": 16
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.quit() self.device.quit()

View File

@@ -3,12 +3,11 @@ from enums import ConnectionType
import pygame import pygame
class PlayStation4Controller(ControlsBase): class PlayStation4Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -33,7 +32,6 @@ class PlayStation4Controller(ControlsBase):
"right button": 16 "right button": 16
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.quit() self.device.quit()

View File

@@ -3,12 +3,11 @@ from enums import ConnectionType
import pygame import pygame
class SonyPlayStation3Controller(ControlsBase): class SonyPlayStation3Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -33,7 +32,6 @@ class SonyPlayStation3Controller(ControlsBase):
"right button": 16 "right button": 16
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.quit() self.device.quit()

View File

@@ -3,12 +3,11 @@ from enums import ConnectionType
import pygame import pygame
class SonyPlayStation4Controller(ControlsBase): class SonyPlayStation4Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -33,7 +32,6 @@ class SonyPlayStation4Controller(ControlsBase):
"right button": 16 "right button": 16
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.quit() self.device.quit()

View File

@@ -3,13 +3,11 @@ from enums import ConnectionType, InputType
import pygame import pygame
class Xbox360Controller(ControlsBase): class Xbox360Controller(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.input_type = InputType.XInput
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -31,7 +29,6 @@ class Xbox360Controller(ControlsBase):
"copy button": 10 "copy button": 10
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.quit() self.device.quit()

View File

@@ -3,13 +3,11 @@ from enums import ConnectionType
import pygame import pygame
class XboxSeriesXController(ControlsBase): class XboxSeriesXController(ControlsBase):
def __init__(self, joy, connection_type): def __init__(self, joy):
self.device = joy self.device = joy
self.instance_id: int = self.device.get_instance_id() self.instance_id: int = self.device.get_instance_id()
self.name = self.device.get_name() self.name = self.device.get_name()
self.guid = self.device.get_guid() self.guid = self.device.get_guid()
self.connection_type = ConnectionType(connection_type.values())
self.input_type = InputType.XInput
self.numaxis: int = self.device.get_numaxes() self.numaxis: int = self.device.get_numaxes()
self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)]
self.numhats: int = self.device.get_numhats() self.numhats: int = self.device.get_numhats()
@@ -31,7 +29,6 @@ class XboxSeriesXController(ControlsBase):
"copy button": 10 "copy button": 10
} }
print(f"{self.name} connected.") print(f"{self.name} connected.")
print(f"Connection type: {connection_type.capitalize()}")
def close(self): def close(self):
self.device.quit() self.device.quit()

View File

@@ -3,7 +3,7 @@ if __name__ == "__main__":
setup( setup(
name='pygameControls', name='pygameControls',
version='0.1.13', version='0.2.0',
packages=find_packages(), packages=find_packages(),
install_requires=[], install_requires=[],
author='Jan Lerking', author='Jan Lerking',