mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
There were a few issues with the generated classes. Python had a __getattr__ forwarder that we defintely did not want. C++ was using a struct with constexpr values, and not an enum class for button types. In all 3, the forwarders from gamepad didn't exist on the generated types. This fixes all 3. --------- Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
171 lines
6.4 KiB
Django/Jinja
171 lines
6.4 KiB
Django/Jinja
# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
|
|
|
|
from typing import Optional, Union
|
|
|
|
from wpilib import EventLoop, {{ ClassName }}Controller
|
|
|
|
from .commandgenerichid import CommandGenericHID
|
|
from .trigger import Trigger
|
|
|
|
|
|
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, hid: Union[int, {{ ClassName }}Controller]):
|
|
"""
|
|
Construct an instance of a controller.
|
|
|
|
:param hid: The port index on the Driver Station that the controller is plugged into,
|
|
or the {{ ClassName }}Controller object to use for this controller.
|
|
"""
|
|
if isinstance(hid, int):
|
|
self._hid = CommandGenericHID.getCommandGenericHID(hid)
|
|
self._controller = {{ ClassName }}Controller(self._hid.getHID())
|
|
else:
|
|
self._hid = CommandGenericHID(hid.getHID())
|
|
self._controller = hid
|
|
|
|
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
|
|
|
|
def button(
|
|
self,
|
|
button: {{ ClassName }}Controller.Button,
|
|
loop: Optional[EventLoop] = None,
|
|
) -> Trigger:
|
|
"""
|
|
Constructs an event instance around this button's digital signal.
|
|
|
|
:param button: the :class:`wpilib.{{ ClassName }}Controller.Button` to read
|
|
:param loop: the event loop instance to attach the event to
|
|
"""
|
|
return self._hid.button(button.value, loop)
|
|
{% 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.button({{ 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.axisGreaterThan(
|
|
{{ ClassName }}Controller.Axis.{{ trigger.AxisConstantName }},
|
|
threshold,
|
|
loop,
|
|
)
|
|
{% endfor %}
|
|
def axisLessThan(
|
|
self,
|
|
axis: {{ ClassName }}Controller.Axis,
|
|
threshold: float,
|
|
loop: Optional[EventLoop] = None,
|
|
) -> Trigger:
|
|
"""
|
|
Constructs a Trigger instance that is true when the axis value is less than
|
|
``threshold``, attached to the given loop.
|
|
|
|
:param axis: the :class:`wpilib.{{ ClassName }}Controller.Axis` to read
|
|
:param threshold: the value below which this Trigger should return true.
|
|
:param loop: the event loop instance to attach the Trigger to
|
|
|
|
:returns: a Trigger instance that is true when the axis value is less than
|
|
the provided threshold.
|
|
"""
|
|
return self._hid.axisLessThan(axis.value, threshold, loop)
|
|
|
|
def axisGreaterThan(
|
|
self,
|
|
axis: {{ ClassName }}Controller.Axis,
|
|
threshold: float,
|
|
loop: Optional[EventLoop] = None,
|
|
) -> Trigger:
|
|
"""
|
|
Constructs a Trigger instance that is true when the axis value is greater
|
|
than ``threshold``, attached to the given loop.
|
|
|
|
:param axis: the :class:`wpilib.{{ ClassName }}Controller.Axis` to read
|
|
:param threshold: the value above which this Trigger should return true.
|
|
:param loop: the event loop instance to attach the Trigger to.
|
|
|
|
:returns: a Trigger instance that is true when the axis value is greater
|
|
than the provided threshold.
|
|
"""
|
|
return self._hid.axisGreaterThan(axis.value, threshold, loop)
|
|
|
|
def axisMagnitudeGreaterThan(
|
|
self,
|
|
axis: {{ ClassName }}Controller.Axis,
|
|
threshold: float,
|
|
loop: Optional[EventLoop] = None,
|
|
) -> Trigger:
|
|
"""
|
|
Constructs a Trigger instance that is true when the axis magnitude is
|
|
greater than ``threshold``, attached to the given loop.
|
|
|
|
:param axis: the :class:`wpilib.{{ ClassName }}Controller.Axis` to read
|
|
:param threshold: the value above which this Trigger should return true.
|
|
:param loop: the event loop instance to attach the Trigger to.
|
|
|
|
:returns: a Trigger instance that is true when the axis magnitude is
|
|
greater than the provided threshold.
|
|
"""
|
|
return self._hid.axisMagnitudeGreaterThan(axis.value, threshold, loop)
|
|
|
|
def getAxis(self, axis: {{ ClassName }}Controller.Axis) -> float:
|
|
"""
|
|
Get the value of the axis.
|
|
|
|
:param axis: the :class:`wpilib.{{ ClassName }}Controller.Axis` to read
|
|
"""
|
|
return self._hid.getRawAxis(axis.value)
|
|
{% 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 -%}
|