[wpilib,cmd] Add new generation for gamepads (#8957)

SDL makes these schemas much simpler, so its easier to support more
controllers.
This commit is contained in:
Thad House
2026-06-11 16:06:45 -07:00
committed by GitHub
parent 025732093f
commit 97381549e6
65 changed files with 12597 additions and 3 deletions

View File

@@ -1,8 +1,10 @@
from .commandgenerichid import CommandGenericHID
from .commanddualsensecontroller import CommandDualSenseController
from .commandgamepad import CommandGamepad
from .commandjoystick import CommandJoystick
from .commandnidsps4controller import CommandNiDsPS4Controller
from .commandnidsxboxcontroller import CommandNiDsXboxController
from .commandxboxcontroller import CommandXboxController
from .joystickbutton import JoystickButton
from .networkbutton import NetworkButton
from .povbutton import POVButton
@@ -10,11 +12,13 @@ from .trigger import Trigger
__all__ = [
"Trigger",
"CommandDualSenseController",
"CommandGenericHID",
"CommandGamepad",
"CommandJoystick",
"CommandNiDsPS4Controller",
"CommandNiDsXboxController",
"CommandXboxController",
"JoystickButton",
"NetworkButton",
"POVButton",

View File

@@ -0,0 +1,384 @@
# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
from typing import Optional
from wpilib import EventLoop, DualSenseController
from .commandgenerichid import CommandGenericHID
from .trigger import Trigger
def _enum_value(value) -> int:
try:
return int(value)
except TypeError:
return value.value
class CommandDualSenseController:
"""
A version of :class:`wpilib.DualSenseController` with :class:`.Trigger` factories for command-based.
"""
_hid: CommandGenericHID
_controller: DualSenseController
def __init__(self, port: int):
"""
Construct an instance of a controller.
:param port: The port index on the Driver Station that the controller is plugged into.
"""
self._hid = CommandGenericHID.getCommandGenericHID(port)
self._controller = DualSenseController(self._hid.getHID())
def __getattr__(self, name: str):
return getattr(self._hid, name)
def getHID(self) -> CommandGenericHID:
"""
Get the underlying CommandGenericHID object.
:returns: the wrapped CommandGenericHID object
"""
return self._hid
def getController(self) -> DualSenseController:
"""
Get the wrapped controller object.
:returns: the wrapped controller object
"""
return self._controller
def cross(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Cross button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Cross button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.CROSS), loop
)
def circle(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Circle button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Circle button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.CIRCLE), loop
)
def square(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Square button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Square button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.SQUARE), loop
)
def triangle(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Triangle button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Triangle button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.TRIANGLE), loop
)
def create(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Create button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Create button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.CREATE), loop
)
def PS(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the PS button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the PS button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.PS), loop
)
def options(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Options button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Options button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.OPTIONS), loop
)
def L3(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the L 3 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the L 3 button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.L3), loop
)
def R3(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the R 3 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the R 3 button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.R3), loop
)
def L1(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the L 1 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the L 1 button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.L1), loop
)
def R1(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the R 1 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the R 1 button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.R1), loop
)
def dpadUp(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Up button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Up button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.DPAD_UP), loop
)
def dpadDown(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Down button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Down button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.DPAD_DOWN), loop
)
def dpadLeft(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Left button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Left button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.DPAD_LEFT), loop
)
def dpadRight(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Right button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Right button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.DPAD_RIGHT), loop
)
def microphone(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Microphone button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Microphone button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.MICROPHONE), loop
)
def touchpad(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Touchpad button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Touchpad button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(DualSenseController.Button.TOUCHPAD), loop
)
def L2(
self,
threshold: float = 0.5,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs a Trigger instance around the L 2 axis value. The returned
Trigger will be true when the axis value is greater than ``threshold``.
:param threshold: the minimum axis value for the returned Trigger to be true. This value
should be in the range [0, 1] where 0 is the unpressed state of the axis.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance that is true when the L 2 axis exceeds the
provided threshold, attached to the given event loop.
"""
return self._hid.axisGreaterThan(
_enum_value(DualSenseController.Axis.L2),
threshold,
loop,
)
def R2(
self,
threshold: float = 0.5,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs a Trigger instance around the R 2 axis value. The returned
Trigger will be true when the axis value is greater than ``threshold``.
:param threshold: the minimum axis value for the returned Trigger to be true. This value
should be in the range [0, 1] where 0 is the unpressed state of the axis.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance that is true when the R 2 axis exceeds the
provided threshold, attached to the given event loop.
"""
return self._hid.axisGreaterThan(
_enum_value(DualSenseController.Axis.R2),
threshold,
loop,
)
def getLeftX(self) -> float:
"""
Get the Left X value of the controller.
:returns: the axis value.
"""
return self._controller.getLeftX()
def getLeftY(self) -> float:
"""
Get the Left Y value of the controller.
:returns: the axis value.
"""
return self._controller.getLeftY()
def getRightX(self) -> float:
"""
Get the Right X value of the controller.
:returns: the axis value.
"""
return self._controller.getRightX()
def getRightY(self) -> float:
"""
Get the Right Y value of the controller.
:returns: the axis value.
"""
return self._controller.getRightY()
def getL2(self) -> float:
"""
Get the L 2 value of the controller.
:returns: the axis value.
"""
return self._controller.getL2()
def getR2(self) -> float:
"""
Get the R 2 value of the controller.
:returns: the axis value.
"""
return self._controller.getR2()

View File

@@ -0,0 +1,356 @@
# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
from typing import Optional
from wpilib import EventLoop, XboxController
from .commandgenerichid import CommandGenericHID
from .trigger import Trigger
def _enum_value(value) -> int:
try:
return int(value)
except TypeError:
return value.value
class CommandXboxController:
"""
A version of :class:`wpilib.XboxController` with :class:`.Trigger` factories for command-based.
"""
_hid: CommandGenericHID
_controller: XboxController
def __init__(self, port: int):
"""
Construct an instance of a controller.
:param port: The port index on the Driver Station that the controller is plugged into.
"""
self._hid = CommandGenericHID.getCommandGenericHID(port)
self._controller = XboxController(self._hid.getHID())
def __getattr__(self, name: str):
return getattr(self._hid, name)
def getHID(self) -> CommandGenericHID:
"""
Get the underlying CommandGenericHID object.
:returns: the wrapped CommandGenericHID object
"""
return self._hid
def getController(self) -> XboxController:
"""
Get the wrapped controller object.
:returns: the wrapped controller object
"""
return self._controller
def a(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the A button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the A button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.A), loop
)
def b(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the B button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the B button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.B), loop
)
def x(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the X button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the X button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.X), loop
)
def y(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Y button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Y button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.Y), loop
)
def view(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the View button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the View button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.VIEW), loop
)
def xbox(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Xbox button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Xbox button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.XBOX), loop
)
def menu(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Menu button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Menu button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.MENU), loop
)
def leftStick(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Left Stick button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Left Stick button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.LEFT_STICK), loop
)
def rightStick(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Right Stick button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Right Stick button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.RIGHT_STICK), loop
)
def leftBumper(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Left Bumper button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Left Bumper button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.LEFT_BUMPER), loop
)
def rightBumper(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Right Bumper button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Right Bumper button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.RIGHT_BUMPER), loop
)
def dpadUp(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Up button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Up button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.DPAD_UP), loop
)
def dpadDown(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Down button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Down button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.DPAD_DOWN), loop
)
def dpadLeft(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Left button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Left button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.DPAD_LEFT), loop
)
def dpadRight(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Dpad Right button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance representing the Dpad Right button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value(XboxController.Button.DPAD_RIGHT), loop
)
def leftTrigger(
self,
threshold: float = 0.5,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs a Trigger instance around the Left Trigger axis value. The returned
Trigger will be true when the axis value is greater than ``threshold``.
:param threshold: the minimum axis value for the returned Trigger to be true. This value
should be in the range [0, 1] where 0 is the unpressed state of the axis.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance that is true when the Left Trigger axis exceeds the
provided threshold, attached to the given event loop.
"""
return self._hid.axisGreaterThan(
_enum_value(XboxController.Axis.LEFT_TRIGGER),
threshold,
loop,
)
def rightTrigger(
self,
threshold: float = 0.5,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs a Trigger instance around the Right Trigger axis value. The returned
Trigger will be true when the axis value is greater than ``threshold``.
:param threshold: the minimum axis value for the returned Trigger to be true. This value
should be in the range [0, 1] where 0 is the unpressed state of the axis.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.getDefaultButtonLoop`
:returns: a Trigger instance that is true when the Right Trigger axis exceeds the
provided threshold, attached to the given event loop.
"""
return self._hid.axisGreaterThan(
_enum_value(XboxController.Axis.RIGHT_TRIGGER),
threshold,
loop,
)
def getLeftX(self) -> float:
"""
Get the Left X value of the controller.
:returns: the axis value.
"""
return self._controller.getLeftX()
def getLeftY(self) -> float:
"""
Get the Left Y value of the controller.
:returns: the axis value.
"""
return self._controller.getLeftY()
def getRightX(self) -> float:
"""
Get the Right X value of the controller.
:returns: the axis value.
"""
return self._controller.getRightX()
def getRightY(self) -> float:
"""
Get the Right Y value of the controller.
:returns: the axis value.
"""
return self._controller.getRightY()
def getLeftTrigger(self) -> float:
"""
Get the Left Trigger value of the controller.
:returns: the axis value.
"""
return self._controller.getLeftTrigger()
def getRightTrigger(self) -> float:
"""
Get the Right Trigger value of the controller.
:returns: the axis value.
"""
return self._controller.getRightTrigger()