Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
0a3042b93c | |||
73fecc1904 | |||
ed252a6548 | |||
ad3214dd23 | |||
311b047bf5 | |||
13901aeb50 | |||
5f3f25cc8c | |||
96ae8860d5 | |||
8a8f6deb89 | |||
79230bfef3 | |||
063af49887 | |||
21da6857b0 | |||
0a892386ae | |||
83d7177a78 | |||
cc8afa8519 | |||
4cf83ce9d1 | |||
30379bd8e3 | |||
a6b4964e80 | |||
98ea8ef5b9 | |||
985e6a769d | |||
b0d364b15e |
29
.gitea/workflows/test.yml
Normal file
29
.gitea/workflows/test.yml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: Run Controller Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore: [ main ]
|
||||||
|
pull-request:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/setup-python@v3
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.10'
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run:
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pygame
|
||||||
|
|
||||||
|
- name: Run Unit Tests
|
||||||
|
run:
|
||||||
|
python -m unittest discover tests
|
@@ -1,3 +1,6 @@
|
|||||||
# PyGame-Controller
|
# PyGame-Controller
|
||||||
|
|
||||||
Small module to make it easy to add controller support.
|
Small module to make it easy to add controller support.
|
||||||
|
|
||||||
|

|
||||||
|

|
1
main.py
1
main.py
@@ -4,7 +4,6 @@ from pygameControls import globals
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
pygame.init()
|
pygame.init()
|
||||||
globals.init()
|
|
||||||
|
|
||||||
done = False
|
done = False
|
||||||
|
|
||||||
|
@@ -1,20 +1,18 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from . import globals
|
from . import globals
|
||||||
|
|
||||||
__version__ = "0.2.0"
|
__version__ = "0.2.7"
|
||||||
|
|
||||||
class Controllers:
|
class Controllers:
|
||||||
def __init__(self, joy):
|
def __init__(self, joy):
|
||||||
|
globals.init()
|
||||||
self.controllers = []
|
self.controllers = []
|
||||||
cont = self.detect_controller(joy.get_guid())
|
cont = self.detect_controller(joy.get_guid())
|
||||||
print(cont)
|
|
||||||
self.controllers.append(cont(joy))
|
self.controllers.append(cont(joy))
|
||||||
|
|
||||||
def detect_controller(self, guid):
|
def detect_controller(self, guid):
|
||||||
for gp in globals.GAMEPADS:
|
for gp in globals.GAMEPADS:
|
||||||
print(gp)
|
|
||||||
for p in globals.GAMEPADS[gp]:
|
for p in globals.GAMEPADS[gp]:
|
||||||
print(p)
|
|
||||||
if p["guid"] != guid:
|
if p["guid"] != guid:
|
||||||
continue
|
continue
|
||||||
return p["class"]
|
return p["class"]
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from .enums import ConnectionType
|
|
||||||
from pydualsense import *
|
from pydualsense import *
|
||||||
|
|
||||||
BATTERY_STATE = {
|
BATTERY_STATE = {
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
from pydualsense import *
|
from pydualsense import *
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
|
|
||||||
class GenericController(ControlsBase):
|
class GenericController(ControlsBase):
|
||||||
def __init__(self, joy):
|
def __init__(self, joy):
|
||||||
|
@@ -126,10 +126,10 @@ def init():
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"vidpid": "054c:09cc",
|
"vidpid": "054c:09cc",
|
||||||
"guid": "",
|
"guid": "05009b514c050000cc09000000810000",
|
||||||
"connection": ConnectionType.BLUETOOTH,
|
"connection": ConnectionType.BLUETOOTH,
|
||||||
"input": InputType.DirectInput,
|
"input": InputType.DirectInput,
|
||||||
"name": ["DualShock 4 v2 Controller"],
|
"name": ["Wireless Controller"],
|
||||||
"class": CONTROLLERS["Sony PLAYSTATION(R)4 Controller"]
|
"class": CONTROLLERS["Sony PLAYSTATION(R)4 Controller"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -183,7 +183,7 @@ def init():
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"vidpid": "046d:c21d",
|
"vidpid": "046d:c21d",
|
||||||
"guid": "",
|
"guid": "0333443e6d0400001fc2000005030000",
|
||||||
"connection": ConnectionType.USB,
|
"connection": ConnectionType.USB,
|
||||||
"input": InputType.XInput,
|
"input": InputType.XInput,
|
||||||
"name": [
|
"name": [
|
||||||
@@ -194,14 +194,15 @@ def init():
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"vidpid": "046d:c216",
|
"vidpid": "046d:c216",
|
||||||
"guid": "",
|
"guid": "03005d8e6d04000019c2000011010000",
|
||||||
"connection": ConnectionType.USB,
|
"connection": ConnectionType.USB,
|
||||||
"input": InputType.DirectInput,
|
"input": InputType.DirectInput,
|
||||||
"name": [
|
"name": [
|
||||||
"Logitech, Inc. F710 Gamepad [DirectInput Mode]",
|
"Logitech, Inc. F710 Gamepad [DirectInput Mode]",
|
||||||
"Logitech Dual Action"
|
"Logitech Dual Action",
|
||||||
|
"Logitech Cordless Rumblepad 2"
|
||||||
],
|
],
|
||||||
"class": CONTROLLERS["Logitech Dual Action"]
|
"class": CONTROLLERS["Logitech Rumblepad 2"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@@ -14,7 +14,6 @@ This controller is a usb controller, with the following features.
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
|
|
||||||
class LogitechDualActionController(ControlsBase):
|
class LogitechDualActionController(ControlsBase):
|
||||||
def __init__(self, joy):
|
def __init__(self, joy):
|
||||||
|
@@ -14,7 +14,6 @@ This controller is a usb controller, with the following features.
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
|
|
||||||
class LogitechF310Controller(ControlsBase):
|
class LogitechF310Controller(ControlsBase):
|
||||||
def __init__(self, joy):
|
def __init__(self, joy):
|
||||||
|
@@ -7,7 +7,6 @@ Subsequent updates will be done, based on updates for the F310.
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
|
|
||||||
class LogitechF510Controller(ControlsBase):
|
class LogitechF510Controller(ControlsBase):
|
||||||
def __init__(self, joy):
|
def __init__(self, joy):
|
||||||
|
@@ -5,7 +5,6 @@ This controller is a usb/wireless controller.
|
|||||||
|
|
||||||
import pygame
|
import pygame
|
||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
|
|
||||||
class LogitechF710Controller(ControlsBase):
|
class LogitechF710Controller(ControlsBase):
|
||||||
def __init__(self, joy):
|
def __init__(self, joy):
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class PlayStation3Controller(ControlsBase):
|
class PlayStation3Controller(ControlsBase):
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class PlayStation4Controller(ControlsBase):
|
class PlayStation4Controller(ControlsBase):
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class SonyPlayStation3Controller(ControlsBase):
|
class SonyPlayStation3Controller(ControlsBase):
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class SonyPlayStation4Controller(ControlsBase):
|
class SonyPlayStation4Controller(ControlsBase):
|
||||||
@@ -24,12 +23,8 @@ class SonyPlayStation4Controller(ControlsBase):
|
|||||||
"left stick button": 11,
|
"left stick button": 11,
|
||||||
"right stick button": 12,
|
"right stick button": 12,
|
||||||
"logo button": 10,
|
"logo button": 10,
|
||||||
"select button": 8,
|
"share button": 8,
|
||||||
"start button": 9,
|
"options button": 9
|
||||||
"down button": 14,
|
|
||||||
"up button": 13,
|
|
||||||
"left button": 15,
|
|
||||||
"right button": 16
|
|
||||||
}
|
}
|
||||||
print(f"{self.name} connected.")
|
print(f"{self.name} connected.")
|
||||||
|
|
||||||
|
31
pygameControls/tests/test_controller.py
Normal file
31
pygameControls/tests/test_controller.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import unittest
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
from pygameControls import Controller
|
||||||
|
|
||||||
|
class TestController(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.mock_js = MagicMock()
|
||||||
|
self.mock_js.get_button.side_effect = lambda i: 1 if i == 0 else 0
|
||||||
|
self.mock_js.get_axis.side_effect = lambda i: 0.5 if i == 1 else 0.0
|
||||||
|
self.mock_js.get_name.return_value = "DualSense Wireless Controller"
|
||||||
|
self.mock_js.get_guid.return_value = "030000004c0500000c0e000011010000"
|
||||||
|
|
||||||
|
self.controller = Controller(self.mock_js)
|
||||||
|
|
||||||
|
def test_button_press(self):
|
||||||
|
self.assertEqual(self.controller.get_button(0), 1)
|
||||||
|
self.assertEqual(self.controller.get_button(1), 0)
|
||||||
|
|
||||||
|
def test_axis_reading(self):
|
||||||
|
self.assertAlmostEqual(self.controller.get_axis(1), 0.5)
|
||||||
|
|
||||||
|
def test_profile_mapping(self):
|
||||||
|
self.assertEqual(self.controller.get_mapping(), "Sony DualSense")
|
||||||
|
|
||||||
|
def test_custom_config(self):
|
||||||
|
cfg = self.controller.get_custom_config()
|
||||||
|
self.assertIn("cross", cfg)
|
||||||
|
self.assertEqual(cfg["cross"], 0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType, InputType
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class Xbox360Controller(ControlsBase):
|
class Xbox360Controller(ControlsBase):
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
from pygameControls.controlsbase import ControlsBase
|
from pygameControls.controlsbase import ControlsBase
|
||||||
from enums import ConnectionType
|
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class XboxSeriesXController(ControlsBase):
|
class XboxSeriesXController(ControlsBase):
|
||||||
|
Reference in New Issue
Block a user