diff --git a/pygameControls/controller.py b/pygameControls/controller.py index bd42067..4533b92 100644 --- a/pygameControls/controller.py +++ b/pygameControls/controller.py @@ -6,10 +6,11 @@ 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 .dualshock3_controller import DualShock3Controller from .generic_controller import GenericController from .logitech_dual_action_controller import LogitechDualActionController -__version__ = "0.1.11" +__version__ = "0.1.12" CONTROLLERS = { "DualSense Wireless Controller": DualSenseController, @@ -18,7 +19,8 @@ CONTROLLERS = { "Logitech Gamepad F510": LogitechF510Controller, "Logitech Gamepad F710": LogitechF710Controller, "Logitech Dual Action": LogitechDualActionController, - "Xbox Series X Controller": XboxSeriesXController + "Xbox Series X Controller": XboxSeriesXController, + "PLAYSTATION(R)3 Controller": DualShock3Controller } class Controllers: diff --git a/pygameControls/dualshock3_controller.py b/pygameControls/dualshock3_controller.py new file mode 100644 index 0000000..dccf31c --- /dev/null +++ b/pygameControls/dualshock3_controller.py @@ -0,0 +1,70 @@ +from pygameControls.controlsbase import ControlsBase + +class DualShock3Controller(ControlsBase): + def __init__(self, joy): + self.device = joy + self.instance_id: int = self.device.get_instance_id() + self.name = self.device.get_name() + self.guid = self.device.get_guid() + self.numaxis: int = self.device.get_numaxes() + self.axis: list = [self.device.get_axis(a) for a in range(self.numaxis)] + self.numhats: int = self.device.get_numhats() + self.hats: list = [self.device.get_hat(h) for h in range(self.numhats)] + self.numbuttons: int = self.device.get_numbuttons() + self.buttons: list = [self.device.get_button(b) for b in range(self.numbuttons)] + self.mapping = { + "l1 button": 4, + "r1 button": 5, + "cross button": 0, + "triangle button": 2, + "circle button": 1, + "square button": 3, + "left stick button": 11, + "right stick button": 12, + "logo button": 10, + "select button": 8, + "start button": 9, + "down button": 14, + "up button": 13, + "left button": 15, + "right button": 16 + } + print(f"{self.name} connected.") + + def close(self): + self.device.quit() + + def handle_input(self, event): + pass + + def left(self): + pass + + def right(self): + pass + + def up(self): + pass + + def down(self): + pass + + def pause(self): + pass + + def rumble(self, left, right, duration=0): + if not left in range(256) or not right in range(256): + raise ValueError("left and right values must be in the range 0 - 255") + self.device.rumble(left / 255, right / 255, duration) + + def stop_rumble(self): + self.device.stop_rumble() + + @property + def name(self) -> str: + return self._name + + @name.setter + def name(self, name: str) -> None: + self._name = name + \ No newline at end of file diff --git a/setup.py b/setup.py index 783a4ca..f29256a 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ if __name__ == "__main__": setup( name='pygameControls', - version='0.1.11', + version='0.1.12', packages=find_packages(), install_requires=[], author='Jan Lerking',