[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

@@ -0,0 +1,100 @@
# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
from typing import Optional
from wpilib import EventLoop, {{ ClassName }}Controller
from .commandgenerichid import CommandGenericHID
from .trigger import Trigger
def _enum_value(value) -> int:
try:
return int(value)
except TypeError:
return value.value
class Command{{ ClassName }}Controller:
"""
A version of :class:`wpilib.{{ ClassName }}Controller` with :class:`.Trigger` factories for command-based.
"""
_hid: CommandGenericHID
_controller: {{ ClassName }}Controller
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 = {{ ClassName }}Controller(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) -> {{ ClassName }}Controller:
"""
Get the wrapped controller object.
:returns: the wrapped controller object
"""
return self._controller
{% for button in buttons %}
def {{ button.Name }}(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the {{ button.DocName }} 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 {{ button.DocName }} button's digital signal
attached to the given loop.
"""
return self._hid.button(
_enum_value({{ ClassName }}Controller.Button.{{ button.ConstantName }}), loop
)
{% endfor -%}
{% for trigger in triggerAxes %}
def {{ trigger.Name }}(
self,
threshold: float{% if trigger.HasDefaultThresholdMethod %} = 0.5{% endif %},
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs a Trigger instance around the {{ trigger.DocName }} 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 {{ trigger.DocName }} axis exceeds the
provided threshold, attached to the given event loop.
"""
return self._hid.axisGreaterThan(
_enum_value({{ ClassName }}Controller.Axis.{{ trigger.AxisConstantName }}),
threshold,
loop,
)
{% endfor -%}
{% for axis in axes %}
def get{{ axis.MethodName }}(self) -> float:
"""
Get the {{ axis.DocName }} value of the controller.
:returns: the axis value.
"""
return self._controller.get{{ axis.MethodName }}()
{% endfor -%}