# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
from typing import Optional, Union
from wpilib import EventLoop, DualSenseController
from .commandgenerichid import CommandGenericHID
from .trigger import Trigger
[docs]
class CommandDualSenseController:
"""
A version of :class:`wpilib.DualSenseController` with :class:`.Trigger` factories for command-based.
"""
_hid: CommandGenericHID
_controller: DualSenseController
def __init__(self, hid: Union[int, DualSenseController]):
"""
Construct an instance of a controller.
:param hid: The port index on the Driver Station that the controller is plugged into,
or the DualSenseController object to use for this controller.
"""
if isinstance(hid, int):
self._hid = CommandGenericHID.get_command_generic_hid(hid)
self._controller = DualSenseController(self._hid.get_hid())
else:
self._hid = CommandGenericHID(hid.get_hid())
self._controller = hid
[docs]
def get_hid(self) -> CommandGenericHID:
"""
Get the underlying CommandGenericHID object.
:returns: the wrapped CommandGenericHID object
"""
return self._hid
[docs]
def get_controller(self) -> DualSenseController:
"""
Get the wrapped controller object.
:returns: the wrapped controller object
"""
return self._controller
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Cross button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.CROSS, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Circle button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.CIRCLE, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Square button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.SQUARE, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Triangle button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.TRIANGLE, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Create button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.CREATE, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the PS button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.PS, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Options button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.OPTIONS, loop)
[docs]
def l3(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the L3 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.get_default_button_loop`
:returns: a Trigger instance representing the L3 button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.L3, loop)
[docs]
def r3(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the R3 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.get_default_button_loop`
:returns: a Trigger instance representing the R3 button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.R3, loop)
[docs]
def l1(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the L1 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.get_default_button_loop`
:returns: a Trigger instance representing the L1 button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.L1, loop)
[docs]
def r1(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the R1 button's digital signal.
:param loop: the event loop instance to attach the Trigger to, defaults
to :func:`commands2.CommandScheduler.get_default_button_loop`
:returns: a Trigger instance representing the R1 button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.R1, loop)
[docs]
def dpad_up(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.get_default_button_loop`
:returns: a Trigger instance representing the Dpad Up button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.DPAD_UP, loop)
[docs]
def dpad_down(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.get_default_button_loop`
:returns: a Trigger instance representing the Dpad Down button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.DPAD_DOWN, loop)
[docs]
def dpad_left(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.get_default_button_loop`
:returns: a Trigger instance representing the Dpad Left button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.DPAD_LEFT, loop)
[docs]
def dpad_right(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.get_default_button_loop`
:returns: a Trigger instance representing the Dpad Right button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.DPAD_RIGHT, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Microphone button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.MICROPHONE, loop)
[docs]
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.get_default_button_loop`
:returns: a Trigger instance representing the Touchpad button's digital signal
attached to the given loop.
"""
return self.button(DualSenseController.Button.TOUCHPAD, loop)
[docs]
def l2(
self,
threshold: float = 0.5,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs a Trigger instance around the L2 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.get_default_button_loop`
:returns: a Trigger instance that is true when the L2 axis exceeds the
provided threshold, attached to the given event loop.
"""
return self.axis_greater_than(
DualSenseController.Axis.L2,
threshold,
loop,
)
[docs]
def r2(
self,
threshold: float = 0.5,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs a Trigger instance around the R2 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.get_default_button_loop`
:returns: a Trigger instance that is true when the R2 axis exceeds the
provided threshold, attached to the given event loop.
"""
return self.axis_greater_than(
DualSenseController.Axis.R2,
threshold,
loop,
)
[docs]
def axis_less_than(
self,
axis: DualSenseController.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.DualSenseController.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.axis_less_than(axis.value, threshold, loop)
[docs]
def axis_greater_than(
self,
axis: DualSenseController.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.DualSenseController.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.axis_greater_than(axis.value, threshold, loop)
[docs]
def axis_magnitude_greater_than(
self,
axis: DualSenseController.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.DualSenseController.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.axis_magnitude_greater_than(axis.value, threshold, loop)
[docs]
def get_axis(self, axis: DualSenseController.Axis) -> float:
"""
Get the value of the axis.
:param axis: the :class:`wpilib.DualSenseController.Axis` to read
"""
return self._hid.get_raw_axis(axis.value)
[docs]
def get_left_x(self) -> float:
"""
Get the Left X value of the controller.
:returns: the axis value.
"""
return self._controller.get_left_x()
[docs]
def get_left_y(self) -> float:
"""
Get the Left Y value of the controller.
:returns: the axis value.
"""
return self._controller.get_left_y()
[docs]
def get_right_x(self) -> float:
"""
Get the Right X value of the controller.
:returns: the axis value.
"""
return self._controller.get_right_x()
[docs]
def get_right_y(self) -> float:
"""
Get the Right Y value of the controller.
:returns: the axis value.
"""
return self._controller.get_right_y()
[docs]
def get_l2(self) -> float:
"""
Get the L2 value of the controller.
:returns: the axis value.
"""
return self._controller.get_l2()
[docs]
def get_r2(self) -> float:
"""
Get the R2 value of the controller.
:returns: the axis value.
"""
return self._controller.get_r2()