[wpilib,cmd2] Fix up issues with generated gamepads (#8985)

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>
This commit is contained in:
Thad House
2026-06-19 14:53:41 -07:00
committed by GitHub
parent 0b950ea6d9
commit 8d2f3212e7
33 changed files with 1571 additions and 600 deletions

View File

@@ -6,6 +6,7 @@
package org.wpilib.command2.button;
import java.util.Objects;
import org.wpilib.command2.CommandScheduler;
import org.wpilib.driverstation.{{ ClassName }}Controller;
import org.wpilib.event.EventLoop;
@@ -30,6 +31,17 @@ public class Command{{ ClassName }}Controller {
m_controller = new {{ ClassName }}Controller(m_hid.getHID());
}
/**
* Construct an instance of a controller with a {{ ClassName }}Controller object.
*
* @param controller The {{ ClassName }}Controller object to use for this controller.
*/
public Command{{ ClassName }}Controller({{ ClassName }}Controller controller) {
m_controller =
Objects.requireNonNull(controller, "Provided {{ ClassName }}Controller cannot be null");
m_hid = new CommandGenericHID(m_controller.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*
@@ -47,6 +59,29 @@ public class Command{{ ClassName }}Controller {
public {{ ClassName }}Controller getController() {
return m_controller;
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @return an event instance representing the button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #button({{ ClassName }}Controller.Button, EventLoop)
*/
public Trigger button({{ ClassName }}Controller.Button button) {
return button(button, CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the button's digital signal attached to the given loop.
*/
public Trigger button({{ ClassName }}Controller.Button button, EventLoop loop) {
return m_hid.button(button.value, loop);
}
{% for button in buttons %}
/**
* Constructs a Trigger instance around the {{ button.DocName }} button's digital signal.
@@ -67,7 +102,7 @@ public class Command{{ ClassName }}Controller {
* to the given loop.
*/
public Trigger {{ button.Name }}(EventLoop loop) {
return m_hid.button({{ ClassName }}Controller.Button.{{ button.ConstantName }}.value, loop);
return button({{ ClassName }}Controller.Button.{{ button.ConstantName }}, loop);
}
{% endfor -%}
{% for trigger in triggerAxes %}
@@ -82,8 +117,8 @@ public class Command{{ ClassName }}Controller {
* threshold, attached to the given event loop
*/
public Trigger {{ trigger.Name }}(double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(
{{ ClassName }}Controller.Axis.{{ trigger.AxisConstantName }}.value, threshold, loop);
return axisGreaterThan(
{{ ClassName }}Controller.Axis.{{ trigger.AxisConstantName }}, threshold, loop);
}
/**
@@ -112,8 +147,104 @@ public class Command{{ ClassName }}Controller {
public Trigger {{ trigger.Name }}() {
return {{ trigger.Name }}(0.5);
}
{% endif -%}
{% endfor -%}
{% endif %}
{% endfor %}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button
* loop}.
*
* @param axis The axis to read
* @param threshold The value below which this trigger should return true.
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan({{ ClassName }}Controller.Axis axis, double threshold) {
return m_hid.axisLessThan(axis.value, threshold);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to the given loop.
*
* @param axis The 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
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan(
{{ ClassName }}Controller.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisLessThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button
* loop}.
*
* @param axis The axis to read
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan({{ ClassName }}Controller.Axis axis, double threshold) {
return m_hid.axisGreaterThan(axis.value, threshold);
}
/**
* Constructs a Trigger instance that is true when the axis value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan(
{{ ClassName }}Controller.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis magnitude value is greater than the
* provided threshold.
*/
public Trigger axisMagnitudeGreaterThan(
{{ ClassName }}Controller.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
* scheduler button loop}.
*
* @param axis The axis to read
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the deadbanded axis value is active (non-zero).
*/
public Trigger axisMagnitudeGreaterThan({{ ClassName }}Controller.Axis axis, double threshold) {
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold);
}
/**
* Get the value of the axis.
*
* @param axis The axis to read
* @return The value of the axis.
*/
public double getAxis({{ ClassName }}Controller.Axis axis) {
return m_hid.getRawAxis(axis.value);
}
{% for axis in axes %}
/**
* Get the {{ axis.DocName }} value of the controller.

View File

@@ -8,8 +8,17 @@
using namespace wpi::cmd;
Command{{ ClassName }}Controller::Command{{ ClassName }}Controller(int port)
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
m_controller{m_hid->GetHID()} {}
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)} {
m_ownedController =
std::make_unique<wpi::{{ ClassName }}Controller>(m_hid->GetHID());
m_controller = m_ownedController.get();
}
Command{{ ClassName }}Controller::Command{{ ClassName }}Controller(
wpi::{{ ClassName }}Controller* controller)
: m_ownedHid{std::make_unique<CommandGenericHID>(controller->GetHID())},
m_hid{m_ownedHid.get()},
m_controller{controller} {}
CommandGenericHID& Command{{ ClassName }}Controller::GetHID() {
return *m_hid;
@@ -17,30 +26,56 @@ CommandGenericHID& Command{{ ClassName }}Controller::GetHID() {
wpi::{{ ClassName }}Controller&
Command{{ ClassName }}Controller::GetController() {
return m_controller;
return *m_controller;
}
const wpi::{{ ClassName }}Controller&
Command{{ ClassName }}Controller::GetController() const {
return m_controller;
return *m_controller;
}
Trigger Command{{ ClassName }}Controller::Button(
enum wpi::{{ ClassName }}Controller::Button button,
wpi::EventLoop* loop) const {
return m_hid->Button(static_cast<int>(button), loop);
}
{% for button in buttons %}
Trigger Command{{ ClassName }}Controller::{{ button.MethodName }}(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::{{ ClassName }}Controller::Button::{{ button.ConstantName }},
loop);
return Button(wpi::{{ ClassName }}Controller::Button::{{ button.ConstantName }},
loop);
}
{% endfor -%}
{% for trigger in triggerAxes %}
Trigger Command{{ ClassName }}Controller::{{ trigger.MethodName }}(
double threshold, wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(
return AxisGreaterThan(
wpi::{{ ClassName }}Controller::Axis::{{ trigger.AxisConstantName }},
threshold, loop);
}
{% endfor -%}
{% endfor %}
Trigger Command{{ ClassName }}Controller::AxisLessThan(
wpi::{{ ClassName }}Controller::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
}
Trigger Command{{ ClassName }}Controller::AxisGreaterThan(
wpi::{{ ClassName }}Controller::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
}
Trigger Command{{ ClassName }}Controller::AxisMagnitudeGreaterThan(
wpi::{{ ClassName }}Controller::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisMagnitudeGreaterThan(static_cast<int>(axis), threshold,
loop);
}
{% for axis in axes %}
double Command{{ ClassName }}Controller::Get{{ axis.MethodName }}() const {
return m_controller.Get{{ axis.MethodName }}();
return m_controller->Get{{ axis.MethodName }}();
}
{% endfor -%}

View File

@@ -5,6 +5,8 @@
// THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
#pragma once
#include <memory>
#include "wpi/driverstation/{{ ClassName }}Controller.hpp"
#include "wpi/commands2/CommandScheduler.hpp"
@@ -28,6 +30,13 @@ class Command{{ ClassName }}Controller {
*/
explicit Command{{ ClassName }}Controller(int port);
/**
* Construct an instance of a controller with a {{ ClassName }}Controller object.
*
* @param controller The {{ ClassName }}Controller object to use for this controller.
*/
explicit Command{{ ClassName }}Controller(wpi::{{ ClassName }}Controller* controller);
/**
* Get the underlying CommandGenericHID object.
*
@@ -48,6 +57,20 @@ class Command{{ ClassName }}Controller {
* @return the wrapped controller object
*/
const wpi::{{ ClassName }}Controller& GetController() const;
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the button's digital signal attached
* to the given loop.
*/
Trigger Button(enum wpi::{{ ClassName }}Controller::Button button,
wpi::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
{% for button in buttons %}
/**
* Constructs a Trigger instance around the {{ button.DocName }} button's
@@ -80,7 +103,58 @@ class Command{{ ClassName }}Controller {
double threshold{% if trigger.HasDefaultThresholdMethod %} = 0.5{% endif %},
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
{% endfor -%}
{% endfor %}
/**
* Constructs a Trigger instance that is true when the axis value is less than
* {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read, starting at 0.
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is less than
* the provided threshold.
*/
Trigger AxisLessThan(
wpi::{{ ClassName }}Controller::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis value is greater
* than {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is greater than
* the provided threshold.
*/
Trigger AxisGreaterThan(
wpi::{{ ClassName }}Controller::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis magnitude value is
* greater than {@code threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis magnitude value is
* greater than the provided threshold.
*/
Trigger AxisMagnitudeGreaterThan(
wpi::{{ ClassName }}Controller::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
{% for axis in axes %}
/**
* Get the {{ axis.DocName }} value of the controller.
@@ -90,7 +164,9 @@ class Command{{ ClassName }}Controller {
double Get{{ axis.MethodName }}() const;
{% endfor %}
private:
CommandGenericHID* m_hid;
wpi::{{ ClassName }}Controller m_controller;
std::unique_ptr<CommandGenericHID> m_ownedHid;
CommandGenericHID* m_hid = nullptr;
std::unique_ptr<wpi::{{ ClassName }}Controller> m_ownedController;
wpi::{{ ClassName }}Controller* m_controller = nullptr;
};
} // namespace wpi::cmd

View File

@@ -1,6 +1,6 @@
# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
from typing import Optional
from typing import Optional, Union
from wpilib import EventLoop, {{ ClassName }}Controller
@@ -8,13 +8,6 @@ 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.
@@ -23,17 +16,19 @@ class Command{{ ClassName }}Controller:
_hid: CommandGenericHID
_controller: {{ ClassName }}Controller
def __init__(self, port: int):
def __init__(self, hid: Union[int, {{ ClassName }}Controller]):
"""
Construct an instance of a controller.
:param port: The port index on the Driver Station that the controller is plugged into.
: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.
"""
self._hid = CommandGenericHID.getCommandGenericHID(port)
self._controller = {{ ClassName }}Controller(self._hid.getHID())
def __getattr__(self, name: str):
return getattr(self._hid, name)
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:
"""
@@ -50,6 +45,19 @@ class Command{{ ClassName }}Controller:
: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:
"""
@@ -61,9 +69,7 @@ class Command{{ ClassName }}Controller:
: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
)
return self.button({{ ClassName }}Controller.Button.{{ button.ConstantName }}, loop)
{% endfor -%}
{% for trigger in triggerAxes %}
def {{ trigger.Name }}(
@@ -83,12 +89,76 @@ class Command{{ ClassName }}Controller:
: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 }}),
return self.axisGreaterThan(
{{ ClassName }}Controller.Axis.{{ trigger.AxisConstantName }},
threshold,
loop,
)
{% endfor -%}
{% 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:
"""

View File

@@ -6,6 +6,7 @@
package org.wpilib.command2.button;
import java.util.Objects;
import org.wpilib.command2.CommandScheduler;
import org.wpilib.driverstation.DualSenseController;
import org.wpilib.event.EventLoop;
@@ -30,6 +31,17 @@ public class CommandDualSenseController {
m_controller = new DualSenseController(m_hid.getHID());
}
/**
* Construct an instance of a controller with a DualSenseController object.
*
* @param controller The DualSenseController object to use for this controller.
*/
public CommandDualSenseController(DualSenseController controller) {
m_controller =
Objects.requireNonNull(controller, "Provided DualSenseController cannot be null");
m_hid = new CommandGenericHID(m_controller.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*
@@ -48,6 +60,29 @@ public class CommandDualSenseController {
return m_controller;
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @return an event instance representing the button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #button(DualSenseController.Button, EventLoop)
*/
public Trigger button(DualSenseController.Button button) {
return button(button, CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the button's digital signal attached to the given loop.
*/
public Trigger button(DualSenseController.Button button, EventLoop loop) {
return m_hid.button(button.value, loop);
}
/**
* Constructs a Trigger instance around the Cross button's digital signal.
*
@@ -67,7 +102,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger cross(EventLoop loop) {
return m_hid.button(DualSenseController.Button.CROSS.value, loop);
return button(DualSenseController.Button.CROSS, loop);
}
/**
@@ -89,7 +124,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger circle(EventLoop loop) {
return m_hid.button(DualSenseController.Button.CIRCLE.value, loop);
return button(DualSenseController.Button.CIRCLE, loop);
}
/**
@@ -111,7 +146,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger square(EventLoop loop) {
return m_hid.button(DualSenseController.Button.SQUARE.value, loop);
return button(DualSenseController.Button.SQUARE, loop);
}
/**
@@ -133,7 +168,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger triangle(EventLoop loop) {
return m_hid.button(DualSenseController.Button.TRIANGLE.value, loop);
return button(DualSenseController.Button.TRIANGLE, loop);
}
/**
@@ -155,7 +190,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger create(EventLoop loop) {
return m_hid.button(DualSenseController.Button.CREATE.value, loop);
return button(DualSenseController.Button.CREATE, loop);
}
/**
@@ -177,7 +212,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger PS(EventLoop loop) {
return m_hid.button(DualSenseController.Button.PS.value, loop);
return button(DualSenseController.Button.PS, loop);
}
/**
@@ -199,7 +234,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger options(EventLoop loop) {
return m_hid.button(DualSenseController.Button.OPTIONS.value, loop);
return button(DualSenseController.Button.OPTIONS, loop);
}
/**
@@ -221,7 +256,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger L3(EventLoop loop) {
return m_hid.button(DualSenseController.Button.L3.value, loop);
return button(DualSenseController.Button.L3, loop);
}
/**
@@ -243,7 +278,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger R3(EventLoop loop) {
return m_hid.button(DualSenseController.Button.R3.value, loop);
return button(DualSenseController.Button.R3, loop);
}
/**
@@ -265,7 +300,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger L1(EventLoop loop) {
return m_hid.button(DualSenseController.Button.L1.value, loop);
return button(DualSenseController.Button.L1, loop);
}
/**
@@ -287,7 +322,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger R1(EventLoop loop) {
return m_hid.button(DualSenseController.Button.R1.value, loop);
return button(DualSenseController.Button.R1, loop);
}
/**
@@ -309,7 +344,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger dpadUp(EventLoop loop) {
return m_hid.button(DualSenseController.Button.DPAD_UP.value, loop);
return button(DualSenseController.Button.DPAD_UP, loop);
}
/**
@@ -331,7 +366,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger dpadDown(EventLoop loop) {
return m_hid.button(DualSenseController.Button.DPAD_DOWN.value, loop);
return button(DualSenseController.Button.DPAD_DOWN, loop);
}
/**
@@ -353,7 +388,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger dpadLeft(EventLoop loop) {
return m_hid.button(DualSenseController.Button.DPAD_LEFT.value, loop);
return button(DualSenseController.Button.DPAD_LEFT, loop);
}
/**
@@ -375,7 +410,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger dpadRight(EventLoop loop) {
return m_hid.button(DualSenseController.Button.DPAD_RIGHT.value, loop);
return button(DualSenseController.Button.DPAD_RIGHT, loop);
}
/**
@@ -397,7 +432,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger microphone(EventLoop loop) {
return m_hid.button(DualSenseController.Button.MICROPHONE.value, loop);
return button(DualSenseController.Button.MICROPHONE, loop);
}
/**
@@ -419,7 +454,7 @@ public class CommandDualSenseController {
* to the given loop.
*/
public Trigger touchpad(EventLoop loop) {
return m_hid.button(DualSenseController.Button.TOUCHPAD.value, loop);
return button(DualSenseController.Button.TOUCHPAD, loop);
}
/**
@@ -433,8 +468,8 @@ public class CommandDualSenseController {
* threshold, attached to the given event loop
*/
public Trigger L2(double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(
DualSenseController.Axis.L2.value, threshold, loop);
return axisGreaterThan(
DualSenseController.Axis.L2, threshold, loop);
}
/**
@@ -464,6 +499,7 @@ public class CommandDualSenseController {
return L2(0.5);
}
/**
* Constructs a Trigger instance around the axis value of the R 2. The returned
* trigger will be true when the axis value is greater than {@code threshold}.
@@ -475,8 +511,8 @@ public class CommandDualSenseController {
* threshold, attached to the given event loop
*/
public Trigger R2(double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(
DualSenseController.Axis.R2.value, threshold, loop);
return axisGreaterThan(
DualSenseController.Axis.R2, threshold, loop);
}
/**
@@ -506,6 +542,104 @@ public class CommandDualSenseController {
return R2(0.5);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button
* loop}.
*
* @param axis The axis to read
* @param threshold The value below which this trigger should return true.
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan(DualSenseController.Axis axis, double threshold) {
return m_hid.axisLessThan(axis.value, threshold);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to the given loop.
*
* @param axis The 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
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan(
DualSenseController.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisLessThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button
* loop}.
*
* @param axis The axis to read
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan(DualSenseController.Axis axis, double threshold) {
return m_hid.axisGreaterThan(axis.value, threshold);
}
/**
* Constructs a Trigger instance that is true when the axis value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan(
DualSenseController.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis magnitude value is greater than the
* provided threshold.
*/
public Trigger axisMagnitudeGreaterThan(
DualSenseController.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
* scheduler button loop}.
*
* @param axis The axis to read
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the deadbanded axis value is active (non-zero).
*/
public Trigger axisMagnitudeGreaterThan(DualSenseController.Axis axis, double threshold) {
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold);
}
/**
* Get the value of the axis.
*
* @param axis The axis to read
* @return The value of the axis.
*/
public double getAxis(DualSenseController.Axis axis) {
return m_hid.getRawAxis(axis.value);
}
/**
* Get the Left X value of the controller.
*

View File

@@ -6,6 +6,7 @@
package org.wpilib.command2.button;
import java.util.Objects;
import org.wpilib.command2.CommandScheduler;
import org.wpilib.driverstation.XboxController;
import org.wpilib.event.EventLoop;
@@ -30,6 +31,17 @@ public class CommandXboxController {
m_controller = new XboxController(m_hid.getHID());
}
/**
* Construct an instance of a controller with a XboxController object.
*
* @param controller The XboxController object to use for this controller.
*/
public CommandXboxController(XboxController controller) {
m_controller =
Objects.requireNonNull(controller, "Provided XboxController cannot be null");
m_hid = new CommandGenericHID(m_controller.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*
@@ -48,6 +60,29 @@ public class CommandXboxController {
return m_controller;
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @return an event instance representing the button's digital signal attached to the {@link
* CommandScheduler#getDefaultButtonLoop() default scheduler button loop}.
* @see #button(XboxController.Button, EventLoop)
*/
public Trigger button(XboxController.Button button) {
return button(button, CommandScheduler.getInstance().getDefaultButtonLoop());
}
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @param loop the event loop instance to attach the event to.
* @return an event instance representing the button's digital signal attached to the given loop.
*/
public Trigger button(XboxController.Button button, EventLoop loop) {
return m_hid.button(button.value, loop);
}
/**
* Constructs a Trigger instance around the A button's digital signal.
*
@@ -67,7 +102,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger a(EventLoop loop) {
return m_hid.button(XboxController.Button.A.value, loop);
return button(XboxController.Button.A, loop);
}
/**
@@ -89,7 +124,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger b(EventLoop loop) {
return m_hid.button(XboxController.Button.B.value, loop);
return button(XboxController.Button.B, loop);
}
/**
@@ -111,7 +146,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger x(EventLoop loop) {
return m_hid.button(XboxController.Button.X.value, loop);
return button(XboxController.Button.X, loop);
}
/**
@@ -133,7 +168,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger y(EventLoop loop) {
return m_hid.button(XboxController.Button.Y.value, loop);
return button(XboxController.Button.Y, loop);
}
/**
@@ -155,7 +190,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger view(EventLoop loop) {
return m_hid.button(XboxController.Button.VIEW.value, loop);
return button(XboxController.Button.VIEW, loop);
}
/**
@@ -177,7 +212,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger xbox(EventLoop loop) {
return m_hid.button(XboxController.Button.XBOX.value, loop);
return button(XboxController.Button.XBOX, loop);
}
/**
@@ -199,7 +234,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger menu(EventLoop loop) {
return m_hid.button(XboxController.Button.MENU.value, loop);
return button(XboxController.Button.MENU, loop);
}
/**
@@ -221,7 +256,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger leftStick(EventLoop loop) {
return m_hid.button(XboxController.Button.LEFT_STICK.value, loop);
return button(XboxController.Button.LEFT_STICK, loop);
}
/**
@@ -243,7 +278,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger rightStick(EventLoop loop) {
return m_hid.button(XboxController.Button.RIGHT_STICK.value, loop);
return button(XboxController.Button.RIGHT_STICK, loop);
}
/**
@@ -265,7 +300,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger leftBumper(EventLoop loop) {
return m_hid.button(XboxController.Button.LEFT_BUMPER.value, loop);
return button(XboxController.Button.LEFT_BUMPER, loop);
}
/**
@@ -287,7 +322,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger rightBumper(EventLoop loop) {
return m_hid.button(XboxController.Button.RIGHT_BUMPER.value, loop);
return button(XboxController.Button.RIGHT_BUMPER, loop);
}
/**
@@ -309,7 +344,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger dpadUp(EventLoop loop) {
return m_hid.button(XboxController.Button.DPAD_UP.value, loop);
return button(XboxController.Button.DPAD_UP, loop);
}
/**
@@ -331,7 +366,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger dpadDown(EventLoop loop) {
return m_hid.button(XboxController.Button.DPAD_DOWN.value, loop);
return button(XboxController.Button.DPAD_DOWN, loop);
}
/**
@@ -353,7 +388,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger dpadLeft(EventLoop loop) {
return m_hid.button(XboxController.Button.DPAD_LEFT.value, loop);
return button(XboxController.Button.DPAD_LEFT, loop);
}
/**
@@ -375,7 +410,7 @@ public class CommandXboxController {
* to the given loop.
*/
public Trigger dpadRight(EventLoop loop) {
return m_hid.button(XboxController.Button.DPAD_RIGHT.value, loop);
return button(XboxController.Button.DPAD_RIGHT, loop);
}
/**
@@ -389,8 +424,8 @@ public class CommandXboxController {
* threshold, attached to the given event loop
*/
public Trigger leftTrigger(double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(
XboxController.Axis.LEFT_TRIGGER.value, threshold, loop);
return axisGreaterThan(
XboxController.Axis.LEFT_TRIGGER, threshold, loop);
}
/**
@@ -420,6 +455,7 @@ public class CommandXboxController {
return leftTrigger(0.5);
}
/**
* Constructs a Trigger instance around the axis value of the Right Trigger. The returned
* trigger will be true when the axis value is greater than {@code threshold}.
@@ -431,8 +467,8 @@ public class CommandXboxController {
* threshold, attached to the given event loop
*/
public Trigger rightTrigger(double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(
XboxController.Axis.RIGHT_TRIGGER.value, threshold, loop);
return axisGreaterThan(
XboxController.Axis.RIGHT_TRIGGER, threshold, loop);
}
/**
@@ -462,6 +498,104 @@ public class CommandXboxController {
return rightTrigger(0.5);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button
* loop}.
*
* @param axis The axis to read
* @param threshold The value below which this trigger should return true.
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan(XboxController.Axis axis, double threshold) {
return m_hid.axisLessThan(axis.value, threshold);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to the given loop.
*
* @param axis The 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
* @return a Trigger instance that is true when the axis value is less than the provided
* threshold.
*/
public Trigger axisLessThan(
XboxController.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisLessThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis value is less than {@code threshold},
* attached to {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button
* loop}.
*
* @param axis The axis to read
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan(XboxController.Axis axis, double threshold) {
return m_hid.axisGreaterThan(axis.value, threshold);
}
/**
* Constructs a Trigger instance that is true when the axis value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis value is greater than the provided
* threshold.
*/
public Trigger axisGreaterThan(
XboxController.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisGreaterThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis magnitude value is greater than the
* provided threshold.
*/
public Trigger axisMagnitudeGreaterThan(
XboxController.Axis axis, double threshold, EventLoop loop) {
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold, loop);
}
/**
* Constructs a Trigger instance that is true when the axis magnitude value is greater than {@code
* threshold}, attached to {@link CommandScheduler#getDefaultButtonLoop() the default command
* scheduler button loop}.
*
* @param axis The axis to read
* @param threshold The value above which this trigger should return true.
* @return a Trigger instance that is true when the deadbanded axis value is active (non-zero).
*/
public Trigger axisMagnitudeGreaterThan(XboxController.Axis axis, double threshold) {
return m_hid.axisMagnitudeGreaterThan(axis.value, threshold);
}
/**
* Get the value of the axis.
*
* @param axis The axis to read
* @return The value of the axis.
*/
public double getAxis(XboxController.Axis axis) {
return m_hid.getRawAxis(axis.value);
}
/**
* Get the Left X value of the controller.
*

View File

@@ -8,8 +8,17 @@
using namespace wpi::cmd;
CommandDualSenseController::CommandDualSenseController(int port)
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
m_controller{m_hid->GetHID()} {}
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)} {
m_ownedController =
std::make_unique<wpi::DualSenseController>(m_hid->GetHID());
m_controller = m_ownedController.get();
}
CommandDualSenseController::CommandDualSenseController(
wpi::DualSenseController* controller)
: m_ownedHid{std::make_unique<CommandGenericHID>(controller->GetHID())},
m_hid{m_ownedHid.get()},
m_controller{controller} {}
CommandGenericHID& CommandDualSenseController::GetHID() {
return *m_hid;
@@ -17,150 +26,177 @@ CommandGenericHID& CommandDualSenseController::GetHID() {
wpi::DualSenseController&
CommandDualSenseController::GetController() {
return m_controller;
return *m_controller;
}
const wpi::DualSenseController&
CommandDualSenseController::GetController() const {
return m_controller;
return *m_controller;
}
Trigger CommandDualSenseController::Button(
enum wpi::DualSenseController::Button button,
wpi::EventLoop* loop) const {
return m_hid->Button(static_cast<int>(button), loop);
}
Trigger CommandDualSenseController::Cross(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::CROSS,
loop);
return Button(wpi::DualSenseController::Button::CROSS,
loop);
}
Trigger CommandDualSenseController::Circle(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::CIRCLE,
loop);
return Button(wpi::DualSenseController::Button::CIRCLE,
loop);
}
Trigger CommandDualSenseController::Square(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::SQUARE,
loop);
return Button(wpi::DualSenseController::Button::SQUARE,
loop);
}
Trigger CommandDualSenseController::Triangle(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::TRIANGLE,
loop);
return Button(wpi::DualSenseController::Button::TRIANGLE,
loop);
}
Trigger CommandDualSenseController::Create(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::CREATE,
loop);
return Button(wpi::DualSenseController::Button::CREATE,
loop);
}
Trigger CommandDualSenseController::PS(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::PS,
loop);
return Button(wpi::DualSenseController::Button::PS,
loop);
}
Trigger CommandDualSenseController::Options(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::OPTIONS,
loop);
return Button(wpi::DualSenseController::Button::OPTIONS,
loop);
}
Trigger CommandDualSenseController::L3(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::L3,
loop);
return Button(wpi::DualSenseController::Button::L3,
loop);
}
Trigger CommandDualSenseController::R3(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::R3,
loop);
return Button(wpi::DualSenseController::Button::R3,
loop);
}
Trigger CommandDualSenseController::L1(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::L1,
loop);
return Button(wpi::DualSenseController::Button::L1,
loop);
}
Trigger CommandDualSenseController::R1(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::R1,
loop);
return Button(wpi::DualSenseController::Button::R1,
loop);
}
Trigger CommandDualSenseController::DpadUp(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::DPAD_UP,
loop);
return Button(wpi::DualSenseController::Button::DPAD_UP,
loop);
}
Trigger CommandDualSenseController::DpadDown(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::DPAD_DOWN,
loop);
return Button(wpi::DualSenseController::Button::DPAD_DOWN,
loop);
}
Trigger CommandDualSenseController::DpadLeft(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::DPAD_LEFT,
loop);
return Button(wpi::DualSenseController::Button::DPAD_LEFT,
loop);
}
Trigger CommandDualSenseController::DpadRight(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::DPAD_RIGHT,
loop);
return Button(wpi::DualSenseController::Button::DPAD_RIGHT,
loop);
}
Trigger CommandDualSenseController::Microphone(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::MICROPHONE,
loop);
return Button(wpi::DualSenseController::Button::MICROPHONE,
loop);
}
Trigger CommandDualSenseController::Touchpad(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::DualSenseController::Button::TOUCHPAD,
loop);
return Button(wpi::DualSenseController::Button::TOUCHPAD,
loop);
}
Trigger CommandDualSenseController::L2(
double threshold, wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(
return AxisGreaterThan(
wpi::DualSenseController::Axis::L2,
threshold, loop);
}
Trigger CommandDualSenseController::R2(
double threshold, wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(
return AxisGreaterThan(
wpi::DualSenseController::Axis::R2,
threshold, loop);
}
Trigger CommandDualSenseController::AxisLessThan(
wpi::DualSenseController::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
}
Trigger CommandDualSenseController::AxisGreaterThan(
wpi::DualSenseController::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
}
Trigger CommandDualSenseController::AxisMagnitudeGreaterThan(
wpi::DualSenseController::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisMagnitudeGreaterThan(static_cast<int>(axis), threshold,
loop);
}
double CommandDualSenseController::GetLeftX() const {
return m_controller.GetLeftX();
return m_controller->GetLeftX();
}
double CommandDualSenseController::GetLeftY() const {
return m_controller.GetLeftY();
return m_controller->GetLeftY();
}
double CommandDualSenseController::GetRightX() const {
return m_controller.GetRightX();
return m_controller->GetRightX();
}
double CommandDualSenseController::GetRightY() const {
return m_controller.GetRightY();
return m_controller->GetRightY();
}
double CommandDualSenseController::GetL2() const {
return m_controller.GetL2();
return m_controller->GetL2();
}
double CommandDualSenseController::GetR2() const {
return m_controller.GetR2();
return m_controller->GetR2();
}

View File

@@ -8,8 +8,17 @@
using namespace wpi::cmd;
CommandXboxController::CommandXboxController(int port)
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
m_controller{m_hid->GetHID()} {}
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)} {
m_ownedController =
std::make_unique<wpi::XboxController>(m_hid->GetHID());
m_controller = m_ownedController.get();
}
CommandXboxController::CommandXboxController(
wpi::XboxController* controller)
: m_ownedHid{std::make_unique<CommandGenericHID>(controller->GetHID())},
m_hid{m_ownedHid.get()},
m_controller{controller} {}
CommandGenericHID& CommandXboxController::GetHID() {
return *m_hid;
@@ -17,138 +26,165 @@ CommandGenericHID& CommandXboxController::GetHID() {
wpi::XboxController&
CommandXboxController::GetController() {
return m_controller;
return *m_controller;
}
const wpi::XboxController&
CommandXboxController::GetController() const {
return m_controller;
return *m_controller;
}
Trigger CommandXboxController::Button(
enum wpi::XboxController::Button button,
wpi::EventLoop* loop) const {
return m_hid->Button(static_cast<int>(button), loop);
}
Trigger CommandXboxController::A(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::A,
loop);
return Button(wpi::XboxController::Button::A,
loop);
}
Trigger CommandXboxController::B(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::B,
loop);
return Button(wpi::XboxController::Button::B,
loop);
}
Trigger CommandXboxController::X(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::X,
loop);
return Button(wpi::XboxController::Button::X,
loop);
}
Trigger CommandXboxController::Y(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::Y,
loop);
return Button(wpi::XboxController::Button::Y,
loop);
}
Trigger CommandXboxController::View(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::VIEW,
loop);
return Button(wpi::XboxController::Button::VIEW,
loop);
}
Trigger CommandXboxController::Xbox(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::XBOX,
loop);
return Button(wpi::XboxController::Button::XBOX,
loop);
}
Trigger CommandXboxController::Menu(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::MENU,
loop);
return Button(wpi::XboxController::Button::MENU,
loop);
}
Trigger CommandXboxController::LeftStick(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::LEFT_STICK,
loop);
return Button(wpi::XboxController::Button::LEFT_STICK,
loop);
}
Trigger CommandXboxController::RightStick(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::RIGHT_STICK,
loop);
return Button(wpi::XboxController::Button::RIGHT_STICK,
loop);
}
Trigger CommandXboxController::LeftBumper(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::LEFT_BUMPER,
loop);
return Button(wpi::XboxController::Button::LEFT_BUMPER,
loop);
}
Trigger CommandXboxController::RightBumper(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::RIGHT_BUMPER,
loop);
return Button(wpi::XboxController::Button::RIGHT_BUMPER,
loop);
}
Trigger CommandXboxController::DpadUp(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::DPAD_UP,
loop);
return Button(wpi::XboxController::Button::DPAD_UP,
loop);
}
Trigger CommandXboxController::DpadDown(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::DPAD_DOWN,
loop);
return Button(wpi::XboxController::Button::DPAD_DOWN,
loop);
}
Trigger CommandXboxController::DpadLeft(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::DPAD_LEFT,
loop);
return Button(wpi::XboxController::Button::DPAD_LEFT,
loop);
}
Trigger CommandXboxController::DpadRight(
wpi::EventLoop* loop) const {
return m_hid->Button(wpi::XboxController::Button::DPAD_RIGHT,
loop);
return Button(wpi::XboxController::Button::DPAD_RIGHT,
loop);
}
Trigger CommandXboxController::LeftTrigger(
double threshold, wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(
return AxisGreaterThan(
wpi::XboxController::Axis::LEFT_TRIGGER,
threshold, loop);
}
Trigger CommandXboxController::RightTrigger(
double threshold, wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(
return AxisGreaterThan(
wpi::XboxController::Axis::RIGHT_TRIGGER,
threshold, loop);
}
Trigger CommandXboxController::AxisLessThan(
wpi::XboxController::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
}
Trigger CommandXboxController::AxisGreaterThan(
wpi::XboxController::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
}
Trigger CommandXboxController::AxisMagnitudeGreaterThan(
wpi::XboxController::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return m_hid->AxisMagnitudeGreaterThan(static_cast<int>(axis), threshold,
loop);
}
double CommandXboxController::GetLeftX() const {
return m_controller.GetLeftX();
return m_controller->GetLeftX();
}
double CommandXboxController::GetLeftY() const {
return m_controller.GetLeftY();
return m_controller->GetLeftY();
}
double CommandXboxController::GetRightX() const {
return m_controller.GetRightX();
return m_controller->GetRightX();
}
double CommandXboxController::GetRightY() const {
return m_controller.GetRightY();
return m_controller->GetRightY();
}
double CommandXboxController::GetLeftTrigger() const {
return m_controller.GetLeftTrigger();
return m_controller->GetLeftTrigger();
}
double CommandXboxController::GetRightTrigger() const {
return m_controller.GetRightTrigger();
return m_controller->GetRightTrigger();
}

View File

@@ -5,6 +5,8 @@
// THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
#pragma once
#include <memory>
#include "wpi/driverstation/DualSenseController.hpp"
#include "wpi/commands2/CommandScheduler.hpp"
@@ -28,6 +30,13 @@ class CommandDualSenseController {
*/
explicit CommandDualSenseController(int port);
/**
* Construct an instance of a controller with a DualSenseController object.
*
* @param controller The DualSenseController object to use for this controller.
*/
explicit CommandDualSenseController(wpi::DualSenseController* controller);
/**
* Get the underlying CommandGenericHID object.
*
@@ -49,6 +58,20 @@ class CommandDualSenseController {
*/
const wpi::DualSenseController& GetController() const;
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the button's digital signal attached
* to the given loop.
*/
Trigger Button(enum wpi::DualSenseController::Button button,
wpi::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance around the Cross button's
* digital signal.
@@ -306,6 +329,58 @@ class CommandDualSenseController {
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis value is less than
* {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read, starting at 0.
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is less than
* the provided threshold.
*/
Trigger AxisLessThan(
wpi::DualSenseController::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis value is greater
* than {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is greater than
* the provided threshold.
*/
Trigger AxisGreaterThan(
wpi::DualSenseController::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis magnitude value is
* greater than {@code threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis magnitude value is
* greater than the provided threshold.
*/
Trigger AxisMagnitudeGreaterThan(
wpi::DualSenseController::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Get the Left X value of the controller.
*
@@ -349,7 +424,9 @@ class CommandDualSenseController {
double GetR2() const;
private:
CommandGenericHID* m_hid;
wpi::DualSenseController m_controller;
std::unique_ptr<CommandGenericHID> m_ownedHid;
CommandGenericHID* m_hid = nullptr;
std::unique_ptr<wpi::DualSenseController> m_ownedController;
wpi::DualSenseController* m_controller = nullptr;
};
} // namespace wpi::cmd

View File

@@ -5,6 +5,8 @@
// THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
#pragma once
#include <memory>
#include "wpi/driverstation/XboxController.hpp"
#include "wpi/commands2/CommandScheduler.hpp"
@@ -28,6 +30,13 @@ class CommandXboxController {
*/
explicit CommandXboxController(int port);
/**
* Construct an instance of a controller with a XboxController object.
*
* @param controller The XboxController object to use for this controller.
*/
explicit CommandXboxController(wpi::XboxController* controller);
/**
* Get the underlying CommandGenericHID object.
*
@@ -49,6 +58,20 @@ class CommandXboxController {
*/
const wpi::XboxController& GetController() const;
/**
* Constructs an event instance around this button's digital signal.
*
* @param button the button
* @param loop the event loop instance to attach the event to. Defaults to the
* CommandScheduler's default loop.
* @return an event instance representing the button's digital signal attached
* to the given loop.
*/
Trigger Button(enum wpi::XboxController::Button button,
wpi::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance around the A button's
* digital signal.
@@ -280,6 +303,58 @@ class CommandXboxController {
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis value is less than
* {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read, starting at 0.
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is less than
* the provided threshold.
*/
Trigger AxisLessThan(
wpi::XboxController::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis value is greater
* than {@code threshold}, attached to {@link
* CommandScheduler::GetDefaultButtonLoop() the default command scheduler
* button loop}.
* @param axis The axis to read
* @param threshold The value below which this trigger should return true.
* @param loop the event loop instance to attach the event to. Defaults to
* {@link CommandScheduler::GetDefaultButtonLoop() the default command
* scheduler button loop}.
* @return a Trigger instance that is true when the axis value is greater than
* the provided threshold.
*/
Trigger AxisGreaterThan(
wpi::XboxController::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance that is true when the axis magnitude value is
* greater than {@code threshold}, attached to the given loop.
*
* @param axis The 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.
* @return a Trigger instance that is true when the axis magnitude value is
* greater than the provided threshold.
*/
Trigger AxisMagnitudeGreaterThan(
wpi::XboxController::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Get the Left X value of the controller.
*
@@ -323,7 +398,9 @@ class CommandXboxController {
double GetRightTrigger() const;
private:
CommandGenericHID* m_hid;
wpi::XboxController m_controller;
std::unique_ptr<CommandGenericHID> m_ownedHid;
CommandGenericHID* m_hid = nullptr;
std::unique_ptr<wpi::XboxController> m_ownedController;
wpi::XboxController* m_controller = nullptr;
};
} // namespace wpi::cmd

View File

@@ -4,6 +4,7 @@
package org.wpilib.command2.button;
import java.util.Objects;
import org.wpilib.command2.CommandScheduler;
import org.wpilib.driverstation.DriverStation;
import org.wpilib.driverstation.Gamepad;
@@ -29,6 +30,16 @@ public class CommandGamepad {
m_gamepad = DriverStation.getGamepad(port);
}
/**
* Construct an instance of a controller with a Gamepad object.
*
* @param gamepad The Gamepad object to use for this controller.
*/
public CommandGamepad(Gamepad gamepad) {
m_gamepad = Objects.requireNonNull(gamepad, "Provided gamepad cannot be null");
m_hid = new CommandGenericHID(m_gamepad.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*

View File

@@ -4,6 +4,8 @@
#include "wpi/commands2/button/CommandGamepad.hpp"
#include <memory>
#include "wpi/commands2/button/CommandGenericHID.hpp"
using namespace wpi::cmd;
@@ -12,6 +14,11 @@ CommandGamepad::CommandGamepad(int port)
: m_hid{&CommandGenericHID::GetCommandGenericHID(port)},
m_gamepad{&wpi::DriverStation::GetGamepad(port)} {}
CommandGamepad::CommandGamepad(wpi::Gamepad* gamepad)
: m_ownedHid{std::make_unique<CommandGenericHID>(gamepad->GetHID())},
m_hid{m_ownedHid.get()},
m_gamepad{gamepad} {}
CommandGenericHID& CommandGamepad::GetHID() {
return *m_hid;
}

View File

@@ -3,6 +3,9 @@
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <memory>
#include "wpi/commands2/CommandScheduler.hpp"
#include "wpi/commands2/button/CommandGenericHID.hpp"
#include "wpi/commands2/button/Trigger.hpp"
@@ -25,6 +28,13 @@ class CommandGamepad {
*/
explicit CommandGamepad(int port);
/**
* Construct an instance of a controller with a Gamepad object.
*
* @param gamepad The Gamepad object to use for this controller.
*/
explicit CommandGamepad(wpi::Gamepad* gamepad);
/**
* Get the underlying CommandGenericHID object.
*
@@ -510,7 +520,8 @@ class CommandGamepad {
double GetRightTrigger() const;
private:
CommandGenericHID* m_hid;
wpi::Gamepad* m_gamepad;
std::unique_ptr<CommandGenericHID> m_ownedHid;
CommandGenericHID* m_hid = nullptr;
wpi::Gamepad* m_gamepad = nullptr;
};
} // namespace wpi::cmd

View File

@@ -1,6 +1,6 @@
# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
from typing import Optional
from typing import Optional, Union
from wpilib import EventLoop, DualSenseController
@@ -8,13 +8,6 @@ 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.
@@ -23,17 +16,19 @@ class CommandDualSenseController:
_hid: CommandGenericHID
_controller: DualSenseController
def __init__(self, port: int):
def __init__(self, hid: Union[int, DualSenseController]):
"""
Construct an instance of a controller.
:param port: The port index on the Driver Station that the controller is plugged into.
:param hid: The port index on the Driver Station that the controller is plugged into,
or the DualSenseController object to use for this controller.
"""
self._hid = CommandGenericHID.getCommandGenericHID(port)
self._controller = DualSenseController(self._hid.getHID())
def __getattr__(self, name: str):
return getattr(self._hid, name)
if isinstance(hid, int):
self._hid = CommandGenericHID.getCommandGenericHID(hid)
self._controller = DualSenseController(self._hid.getHID())
else:
self._hid = CommandGenericHID(hid.getHID())
self._controller = hid
def getHID(self) -> CommandGenericHID:
"""
@@ -51,6 +46,19 @@ class CommandDualSenseController:
"""
return self._controller
def button(
self,
button: DualSenseController.Button,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs an event instance around this button's digital signal.
:param button: the :class:`wpilib.DualSenseController.Button` to read
:param loop: the event loop instance to attach the event to
"""
return self._hid.button(button.value, loop)
def cross(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the Cross button's digital signal.
@@ -61,9 +69,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.CROSS, loop)
def circle(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -75,9 +81,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.CIRCLE, loop)
def square(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -89,9 +93,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.SQUARE, loop)
def triangle(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -103,9 +105,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.TRIANGLE, loop)
def create(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -117,9 +117,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.CREATE, loop)
def PS(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -131,9 +129,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.PS, loop)
def options(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -145,9 +141,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.OPTIONS, loop)
def L3(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -159,9 +153,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.L3, loop)
def R3(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -173,9 +165,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.R3, loop)
def L1(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -187,9 +177,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.L1, loop)
def R1(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -201,9 +189,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.R1, loop)
def dpadUp(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -215,9 +201,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.DPAD_UP, loop)
def dpadDown(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -229,9 +213,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.DPAD_DOWN, loop)
def dpadLeft(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -243,9 +225,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.DPAD_LEFT, loop)
def dpadRight(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -257,9 +237,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.DPAD_RIGHT, loop)
def microphone(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -271,9 +249,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.MICROPHONE, loop)
def touchpad(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -285,9 +261,7 @@ class CommandDualSenseController:
: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
)
return self.button(DualSenseController.Button.TOUCHPAD, loop)
def L2(
self,
@@ -306,8 +280,8 @@ class CommandDualSenseController:
: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),
return self.axisGreaterThan(
DualSenseController.Axis.L2,
threshold,
loop,
)
@@ -329,12 +303,77 @@ class CommandDualSenseController:
: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),
return self.axisGreaterThan(
DualSenseController.Axis.R2,
threshold,
loop,
)
def axisLessThan(
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.axisLessThan(axis.value, threshold, loop)
def axisGreaterThan(
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.axisGreaterThan(axis.value, threshold, loop)
def axisMagnitudeGreaterThan(
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.axisMagnitudeGreaterThan(axis.value, threshold, loop)
def getAxis(self, axis: DualSenseController.Axis) -> float:
"""
Get the value of the axis.
:param axis: the :class:`wpilib.DualSenseController.Axis` to read
"""
return self._hid.getRawAxis(axis.value)
def getLeftX(self) -> float:
"""
Get the Left X value of the controller.

View File

@@ -1,5 +1,5 @@
# validated: 2024-01-20 DS 92149efa11fa button/CommandGamepad.java
from typing import Optional
from typing import Optional, Union
from wpilib import DriverStation, EventLoop, Gamepad
@@ -22,15 +22,20 @@ class CommandGamepad:
_hid: CommandGenericHID
_gamepad: Gamepad
def __init__(self, port: int):
def __init__(self, hid: Union[int, Gamepad]):
"""
Construct an instance of a controller.
:param port: The port index on the Driver Station that the controller is plugged into.
:param hid: The port index on the Driver Station that the controller is plugged into,
or the Gamepad object to use for this controller.
"""
self._hid = CommandGenericHID.getCommandGenericHID(port)
self._gamepad = DriverStation.getGamepad(port)
if isinstance(hid, int):
self._hid = CommandGenericHID.getCommandGenericHID(hid)
self._gamepad = DriverStation.getGamepad(hid)
else:
self._hid = CommandGenericHID(hid.getHID())
self._gamepad = hid
def __getattr__(self, name: str):
return getattr(self._hid, name)

View File

@@ -1,6 +1,6 @@
# validated: 2024-01-20 DS 92149efa11fa button/CommandGenericHID.java
import threading
from typing import ClassVar, Optional, final
from typing import ClassVar, Optional, Union, final
from wpilib import DriverStation, EventLoop, GenericHID
@@ -17,13 +17,17 @@ class CommandGenericHID:
_hids: ClassVar[dict[int, "CommandGenericHID"]] = {}
_hids_lock = threading.Lock()
def __init__(self, port: int):
def __init__(self, hid: Union[int, GenericHID]):
"""
Construct an instance of a device.
:param port: The port on the Driver Station that the device is plugged into.
:param hid: The port on the Driver Station that the device is plugged into,
or the GenericHID object to use for this command HID.
"""
self._hid = DriverStation.getGenericHID(port)
if isinstance(hid, int):
self._hid = DriverStation.getGenericHID(hid)
else:
self._hid = hid
@classmethod
def getCommandGenericHID(cls, port: int) -> "CommandGenericHID":

View File

@@ -1,6 +1,6 @@
# THIS FILE WAS AUTO-GENERATED BY ./commandsv2/generate_hids.py. DO NOT MODIFY
from typing import Optional
from typing import Optional, Union
from wpilib import EventLoop, XboxController
@@ -8,13 +8,6 @@ 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.
@@ -23,17 +16,19 @@ class CommandXboxController:
_hid: CommandGenericHID
_controller: XboxController
def __init__(self, port: int):
def __init__(self, hid: Union[int, XboxController]):
"""
Construct an instance of a controller.
:param port: The port index on the Driver Station that the controller is plugged into.
:param hid: The port index on the Driver Station that the controller is plugged into,
or the XboxController object to use for this controller.
"""
self._hid = CommandGenericHID.getCommandGenericHID(port)
self._controller = XboxController(self._hid.getHID())
def __getattr__(self, name: str):
return getattr(self._hid, name)
if isinstance(hid, int):
self._hid = CommandGenericHID.getCommandGenericHID(hid)
self._controller = XboxController(self._hid.getHID())
else:
self._hid = CommandGenericHID(hid.getHID())
self._controller = hid
def getHID(self) -> CommandGenericHID:
"""
@@ -51,6 +46,19 @@ class CommandXboxController:
"""
return self._controller
def button(
self,
button: XboxController.Button,
loop: Optional[EventLoop] = None,
) -> Trigger:
"""
Constructs an event instance around this button's digital signal.
:param button: the :class:`wpilib.XboxController.Button` to read
:param loop: the event loop instance to attach the event to
"""
return self._hid.button(button.value, loop)
def a(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
Constructs a Trigger instance around the A button's digital signal.
@@ -61,9 +69,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.A, loop)
def b(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -75,9 +81,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.B, loop)
def x(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -89,9 +93,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.X, loop)
def y(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -103,9 +105,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.Y, loop)
def view(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -117,9 +117,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.VIEW, loop)
def xbox(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -131,9 +129,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.XBOX, loop)
def menu(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -145,9 +141,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.MENU, loop)
def leftStick(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -159,9 +153,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.LEFT_STICK, loop)
def rightStick(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -173,9 +165,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.RIGHT_STICK, loop)
def leftBumper(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -187,9 +177,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.LEFT_BUMPER, loop)
def rightBumper(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -201,9 +189,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.RIGHT_BUMPER, loop)
def dpadUp(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -215,9 +201,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.DPAD_UP, loop)
def dpadDown(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -229,9 +213,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.DPAD_DOWN, loop)
def dpadLeft(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -243,9 +225,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.DPAD_LEFT, loop)
def dpadRight(self, loop: Optional[EventLoop] = None) -> Trigger:
"""
@@ -257,9 +237,7 @@ class CommandXboxController:
: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
)
return self.button(XboxController.Button.DPAD_RIGHT, loop)
def leftTrigger(
self,
@@ -278,8 +256,8 @@ class CommandXboxController:
: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),
return self.axisGreaterThan(
XboxController.Axis.LEFT_TRIGGER,
threshold,
loop,
)
@@ -301,12 +279,77 @@ class CommandXboxController:
: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),
return self.axisGreaterThan(
XboxController.Axis.RIGHT_TRIGGER,
threshold,
loop,
)
def axisLessThan(
self,
axis: XboxController.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.XboxController.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: XboxController.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.XboxController.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: XboxController.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.XboxController.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: XboxController.Axis) -> float:
"""
Get the value of the axis.
:param axis: the :class:`wpilib.XboxController.Axis` to read
"""
return self._hid.getRawAxis(axis.value)
def getLeftX(self) -> float:
"""
Get the Left X value of the controller.

View File

@@ -6,6 +6,7 @@
package org.wpilib.command3.button;
import java.util.Objects;
import org.wpilib.command3.Scheduler;
import org.wpilib.command3.Trigger;
import org.wpilib.driverstation.{{ ClassName }}Controller;
@@ -31,6 +32,16 @@ public class Command{{ ClassName }}Controller {
this(Scheduler.getDefault(), port);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the {@link Scheduler#getDefault() default scheduler} using its default event loop.
*
* @param controller The {{ ClassName }}Controller object to use for this controller.
*/
public Command{{ ClassName }}Controller({{ ClassName }}Controller controller) {
this(Scheduler.getDefault(), controller);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the given scheduler using its default event loop.
@@ -43,6 +54,19 @@ public class Command{{ ClassName }}Controller {
m_controller = new {{ ClassName }}Controller(m_hid.getHID());
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the given scheduler using its default event loop.
*
* @param scheduler The scheduler that should execute the triggered commands.
* @param controller The {{ ClassName }}Controller object to use for this controller.
*/
public Command{{ ClassName }}Controller(Scheduler scheduler, {{ ClassName }}Controller controller) {
m_controller =
Objects.requireNonNull(controller, "Provided {{ ClassName }}Controller cannot be null");
m_hid = new CommandGenericHID(scheduler, m_controller.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*

View File

@@ -6,6 +6,7 @@
package org.wpilib.command3.button;
import java.util.Objects;
import org.wpilib.command3.Scheduler;
import org.wpilib.command3.Trigger;
import org.wpilib.driverstation.DualSenseController;
@@ -31,6 +32,16 @@ public class CommandDualSenseController {
this(Scheduler.getDefault(), port);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the {@link Scheduler#getDefault() default scheduler} using its default event loop.
*
* @param controller The DualSenseController object to use for this controller.
*/
public CommandDualSenseController(DualSenseController controller) {
this(Scheduler.getDefault(), controller);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the given scheduler using its default event loop.
@@ -43,6 +54,19 @@ public class CommandDualSenseController {
m_controller = new DualSenseController(m_hid.getHID());
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the given scheduler using its default event loop.
*
* @param scheduler The scheduler that should execute the triggered commands.
* @param controller The DualSenseController object to use for this controller.
*/
public CommandDualSenseController(Scheduler scheduler, DualSenseController controller) {
m_controller =
Objects.requireNonNull(controller, "Provided DualSenseController cannot be null");
m_hid = new CommandGenericHID(scheduler, m_controller.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*

View File

@@ -6,6 +6,7 @@
package org.wpilib.command3.button;
import java.util.Objects;
import org.wpilib.command3.Scheduler;
import org.wpilib.command3.Trigger;
import org.wpilib.driverstation.XboxController;
@@ -31,6 +32,16 @@ public class CommandXboxController {
this(Scheduler.getDefault(), port);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the {@link Scheduler#getDefault() default scheduler} using its default event loop.
*
* @param controller The XboxController object to use for this controller.
*/
public CommandXboxController(XboxController controller) {
this(Scheduler.getDefault(), controller);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the given scheduler using its default event loop.
@@ -43,6 +54,19 @@ public class CommandXboxController {
m_controller = new XboxController(m_hid.getHID());
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the given scheduler using its default event loop.
*
* @param scheduler The scheduler that should execute the triggered commands.
* @param controller The XboxController object to use for this controller.
*/
public CommandXboxController(Scheduler scheduler, XboxController controller) {
m_controller =
Objects.requireNonNull(controller, "Provided XboxController cannot be null");
m_hid = new CommandGenericHID(scheduler, m_controller.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*

View File

@@ -4,6 +4,7 @@
package org.wpilib.command3.button;
import java.util.Objects;
import org.wpilib.command3.Scheduler;
import org.wpilib.command3.Trigger;
import org.wpilib.driverstation.DriverStation;
@@ -29,6 +30,16 @@ public class CommandGamepad {
this(Scheduler.getDefault(), port);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the {@link Scheduler#getDefault() default scheduler} using its default event loop.
*
* @param gamepad The Gamepad object to use for this controller.
*/
public CommandGamepad(Gamepad gamepad) {
this(Scheduler.getDefault(), gamepad);
}
/**
* Construct an instance of a controller.
*
@@ -40,6 +51,18 @@ public class CommandGamepad {
m_gamepad = DriverStation.getGamepad(port);
}
/**
* Construct an instance of a controller. Commands bound to buttons on the controller will be
* scheduled on the given scheduler using its default event loop.
*
* @param scheduler The scheduler that should execute the triggered commands.
* @param gamepad The Gamepad object to use for this controller.
*/
public CommandGamepad(Scheduler scheduler, Gamepad gamepad) {
m_gamepad = Objects.requireNonNull(gamepad, "Provided gamepad cannot be null");
m_hid = new CommandGenericHID(scheduler, m_gamepad.getHID());
}
/**
* Get the underlying CommandGenericHID object.
*

View File

@@ -239,8 +239,6 @@ def wpilib_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includ
tmpl_class_names = [],
trampolines = [
("wpi::DualSenseController", "wpi__DualSenseController.hpp"),
("wpi::DualSenseController::Button", "wpi__DualSenseController__Button.hpp"),
("wpi::DualSenseController::Axis", "wpi__DualSenseController__Axis.hpp"),
],
),
struct(
@@ -251,8 +249,6 @@ def wpilib_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includ
tmpl_class_names = [],
trampolines = [
("wpi::XboxController", "wpi__XboxController.hpp"),
("wpi::XboxController::Button", "wpi__XboxController__Button.hpp"),
("wpi::XboxController::Axis", "wpi__XboxController__Axis.hpp"),
],
),
struct(

View File

@@ -40,18 +40,18 @@ double {{ ClassName }}Controller::Get{{ axis.MethodName }}() const {
return GetAxis(Axis::{{ axis.ConstantName }});
}
{% endfor %}
double {{ ClassName }}Controller::GetAxis(int axis) const {
return m_hid->GetRawAxis(axis);
double {{ ClassName }}Controller::GetAxis(Axis axis) const {
return m_hid->GetRawAxis(static_cast<int>(axis));
}
BooleanEvent {{ ClassName }}Controller::AxisLessThan(int axis, double threshold,
BooleanEvent {{ ClassName }}Controller::AxisLessThan(Axis axis, double threshold,
EventLoop* loop) const {
return m_hid->AxisLessThan(axis, threshold, loop);
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
}
BooleanEvent {{ ClassName }}Controller::AxisGreaterThan(
int axis, double threshold, EventLoop* loop) const {
return m_hid->AxisGreaterThan(axis, threshold, loop);
Axis axis, double threshold, EventLoop* loop) const {
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
}
{% for button in buttons %}
bool {{ ClassName }}Controller::Get{{ button.MethodName }}Button() const {
@@ -70,21 +70,21 @@ BooleanEvent {{ ClassName }}Controller::{{ button.MethodName }}(EventLoop* loop)
return ButtonEvent(Button::{{ button.ConstantName }}, loop);
}
{% endfor %}
bool {{ ClassName }}Controller::GetButton(int button) const {
return m_hid->GetRawButton(button);
bool {{ ClassName }}Controller::GetButton(Button button) const {
return m_hid->GetRawButton(static_cast<int>(button));
}
bool {{ ClassName }}Controller::GetButtonPressed(int button) {
return m_hid->GetRawButtonPressed(button);
bool {{ ClassName }}Controller::GetButtonPressed(Button button) {
return m_hid->GetRawButtonPressed(static_cast<int>(button));
}
bool {{ ClassName }}Controller::GetButtonReleased(int button) {
return m_hid->GetRawButtonReleased(button);
bool {{ ClassName }}Controller::GetButtonReleased(Button button) {
return m_hid->GetRawButtonReleased(static_cast<int>(button));
}
BooleanEvent {{ ClassName }}Controller::ButtonEvent(int button,
BooleanEvent {{ ClassName }}Controller::ButtonEvent(Button button,
EventLoop* loop) const {
return m_hid->Button(button, loop);
return m_hid->Button(static_cast<int>(button), loop);
}
void {{ ClassName }}Controller::SetLeds(int r, int g, int b) {

View File

@@ -28,11 +28,11 @@ using namespace wpi::sim;
}
{% for axis in axes %}
void {{ ClassName }}ControllerSim::Set{{ axis.MethodName }}(double value) {
SetRawAxis({{ ClassName }}Controller::Axis::{{ axis.ConstantName }}, value);
SetRawAxis(static_cast<int>({{ ClassName }}Controller::Axis::{{ axis.ConstantName }}), value);
}
{% endfor -%}
{% for button in buttons %}
void {{ ClassName }}ControllerSim::Set{{ button.MethodName }}Button(bool value) {
SetRawButton({{ ClassName }}Controller::Button::{{ button.ConstantName }}, value);
SetRawButton(static_cast<int>({{ ClassName }}Controller::Button::{{ button.ConstantName }}), value);
}
{% endfor -%}

View File

@@ -46,6 +46,22 @@ class {{ ClassName }}Controller
static constexpr GenericHID::SupportedOutputs SUPPORTED_OUTPUTS =
static_cast<GenericHID::SupportedOutputs>({{ SupportedOutputsValue }});
/** Represents a digital button on a {{ ClassName }}Controller. */
enum class Button {
{%- for button in buttons %}
/// {{ button.DocName }} button.
{{ button.ConstantName }} = {{ button.value }},
{%- endfor %}
};
/** Represents an axis on a {{ ClassName }}Controller. */
enum class Axis {
{%- for axis in axes %}
/// {{ axis.DocName }}.
{{ axis.ConstantName }} = {{ axis.value }},
{%- endfor %}
};
/**
* Construct an instance of a controller.
*
@@ -109,7 +125,7 @@ class {{ ClassName }}Controller
* @param axis The axis to read
* @return the axis value.
*/
double GetAxis(int axis) const;
double GetAxis(Axis axis) const;
/**
* Constructs an event instance that is true when the axis value is less than
@@ -121,7 +137,7 @@ class {{ ClassName }}Controller
* @return an event instance that is true when the axis value is less than the
* provided threshold.
*/
BooleanEvent AxisLessThan(int axis, double threshold, EventLoop* loop) const;
BooleanEvent AxisLessThan(Axis axis, double threshold, EventLoop* loop) const;
/**
* Constructs an event instance that is true when the axis value is greater
@@ -133,7 +149,7 @@ class {{ ClassName }}Controller
* @return an event instance that is true when the axis value is greater than
* the provided threshold.
*/
BooleanEvent AxisGreaterThan(int axis, double threshold,
BooleanEvent AxisGreaterThan(Axis axis, double threshold,
EventLoop* loop) const;
{% for button in buttons %}
/**
@@ -173,7 +189,7 @@ class {{ ClassName }}Controller
* @param button The button to read
* @return The state of the button.
*/
bool GetButton(int button) const;
bool GetButton(Button button) const;
/**
* Whether the button was pressed since the last check.
@@ -181,7 +197,7 @@ class {{ ClassName }}Controller
* @param button The button to read
* @return Whether the button was pressed since the last check.
*/
bool GetButtonPressed(int button);
bool GetButtonPressed(Button button);
/**
* Whether the button was released since the last check.
@@ -189,7 +205,7 @@ class {{ ClassName }}Controller
* @param button The button to read
* @return Whether the button was released since the last check.
*/
bool GetButtonReleased(int button);
bool GetButtonReleased(Button button);
/**
* Constructs an event instance around this button's digital signal.
@@ -199,7 +215,7 @@ class {{ ClassName }}Controller
* @return an event instance representing the button's digital signal attached
* to the given loop.
*/
BooleanEvent ButtonEvent(int button, EventLoop* loop) const;
BooleanEvent ButtonEvent(Button button, EventLoop* loop) const;
/**
* Set leds on the controller.
@@ -250,22 +266,6 @@ class {{ ClassName }}Controller
TouchpadFinger GetTouchpadFinger(int touchpad, int finger) const;
{%- endif %}
/** Represents a digital button on a {{ ClassName }}Controller. */
struct Button {
{%- for button in buttons %}
/// {{ button.DocName }} button.
static constexpr int {{ button.ConstantName }} = {{ button.value }};
{%- endfor %}
};
/** Represents an axis on a {{ ClassName }}Controller. */
struct Axis {
{%- for axis in axes %}
/// {{ axis.DocName }}.
static constexpr int {{ axis.ConstantName }} = {{ axis.value }};
{%- endfor %}
};
void InitSendable(wpi::util::SendableBuilder& builder) override;
private:

View File

@@ -60,18 +60,18 @@ double DualSenseController::GetR2() const {
return GetAxis(Axis::R2);
}
double DualSenseController::GetAxis(int axis) const {
return m_hid->GetRawAxis(axis);
double DualSenseController::GetAxis(Axis axis) const {
return m_hid->GetRawAxis(static_cast<int>(axis));
}
BooleanEvent DualSenseController::AxisLessThan(int axis, double threshold,
BooleanEvent DualSenseController::AxisLessThan(Axis axis, double threshold,
EventLoop* loop) const {
return m_hid->AxisLessThan(axis, threshold, loop);
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
}
BooleanEvent DualSenseController::AxisGreaterThan(
int axis, double threshold, EventLoop* loop) const {
return m_hid->AxisGreaterThan(axis, threshold, loop);
Axis axis, double threshold, EventLoop* loop) const {
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
}
bool DualSenseController::GetCrossButton() const {
@@ -346,21 +346,21 @@ BooleanEvent DualSenseController::Touchpad(EventLoop* loop) const {
return ButtonEvent(Button::TOUCHPAD, loop);
}
bool DualSenseController::GetButton(int button) const {
return m_hid->GetRawButton(button);
bool DualSenseController::GetButton(Button button) const {
return m_hid->GetRawButton(static_cast<int>(button));
}
bool DualSenseController::GetButtonPressed(int button) {
return m_hid->GetRawButtonPressed(button);
bool DualSenseController::GetButtonPressed(Button button) {
return m_hid->GetRawButtonPressed(static_cast<int>(button));
}
bool DualSenseController::GetButtonReleased(int button) {
return m_hid->GetRawButtonReleased(button);
bool DualSenseController::GetButtonReleased(Button button) {
return m_hid->GetRawButtonReleased(static_cast<int>(button));
}
BooleanEvent DualSenseController::ButtonEvent(int button,
BooleanEvent DualSenseController::ButtonEvent(Button button,
EventLoop* loop) const {
return m_hid->Button(button, loop);
return m_hid->Button(static_cast<int>(button), loop);
}
void DualSenseController::SetLeds(int r, int g, int b) {

View File

@@ -60,18 +60,18 @@ double XboxController::GetRightTrigger() const {
return GetAxis(Axis::RIGHT_TRIGGER);
}
double XboxController::GetAxis(int axis) const {
return m_hid->GetRawAxis(axis);
double XboxController::GetAxis(Axis axis) const {
return m_hid->GetRawAxis(static_cast<int>(axis));
}
BooleanEvent XboxController::AxisLessThan(int axis, double threshold,
BooleanEvent XboxController::AxisLessThan(Axis axis, double threshold,
EventLoop* loop) const {
return m_hid->AxisLessThan(axis, threshold, loop);
return m_hid->AxisLessThan(static_cast<int>(axis), threshold, loop);
}
BooleanEvent XboxController::AxisGreaterThan(
int axis, double threshold, EventLoop* loop) const {
return m_hid->AxisGreaterThan(axis, threshold, loop);
Axis axis, double threshold, EventLoop* loop) const {
return m_hid->AxisGreaterThan(static_cast<int>(axis), threshold, loop);
}
bool XboxController::GetAButton() const {
@@ -314,21 +314,21 @@ BooleanEvent XboxController::DpadRight(EventLoop* loop) const {
return ButtonEvent(Button::DPAD_RIGHT, loop);
}
bool XboxController::GetButton(int button) const {
return m_hid->GetRawButton(button);
bool XboxController::GetButton(Button button) const {
return m_hid->GetRawButton(static_cast<int>(button));
}
bool XboxController::GetButtonPressed(int button) {
return m_hid->GetRawButtonPressed(button);
bool XboxController::GetButtonPressed(Button button) {
return m_hid->GetRawButtonPressed(static_cast<int>(button));
}
bool XboxController::GetButtonReleased(int button) {
return m_hid->GetRawButtonReleased(button);
bool XboxController::GetButtonReleased(Button button) {
return m_hid->GetRawButtonReleased(static_cast<int>(button));
}
BooleanEvent XboxController::ButtonEvent(int button,
BooleanEvent XboxController::ButtonEvent(Button button,
EventLoop* loop) const {
return m_hid->Button(button, loop);
return m_hid->Button(static_cast<int>(button), loop);
}
void XboxController::SetLeds(int r, int g, int b) {

View File

@@ -28,93 +28,93 @@ DualSenseControllerSim::DualSenseControllerSim(int port) : GenericHIDSim{port} {
}
void DualSenseControllerSim::SetLeftX(double value) {
SetRawAxis(DualSenseController::Axis::LEFT_X, value);
SetRawAxis(static_cast<int>(DualSenseController::Axis::LEFT_X), value);
}
void DualSenseControllerSim::SetLeftY(double value) {
SetRawAxis(DualSenseController::Axis::LEFT_Y, value);
SetRawAxis(static_cast<int>(DualSenseController::Axis::LEFT_Y), value);
}
void DualSenseControllerSim::SetRightX(double value) {
SetRawAxis(DualSenseController::Axis::RIGHT_X, value);
SetRawAxis(static_cast<int>(DualSenseController::Axis::RIGHT_X), value);
}
void DualSenseControllerSim::SetRightY(double value) {
SetRawAxis(DualSenseController::Axis::RIGHT_Y, value);
SetRawAxis(static_cast<int>(DualSenseController::Axis::RIGHT_Y), value);
}
void DualSenseControllerSim::SetL2(double value) {
SetRawAxis(DualSenseController::Axis::L2, value);
SetRawAxis(static_cast<int>(DualSenseController::Axis::L2), value);
}
void DualSenseControllerSim::SetR2(double value) {
SetRawAxis(DualSenseController::Axis::R2, value);
SetRawAxis(static_cast<int>(DualSenseController::Axis::R2), value);
}
void DualSenseControllerSim::SetCrossButton(bool value) {
SetRawButton(DualSenseController::Button::CROSS, value);
SetRawButton(static_cast<int>(DualSenseController::Button::CROSS), value);
}
void DualSenseControllerSim::SetCircleButton(bool value) {
SetRawButton(DualSenseController::Button::CIRCLE, value);
SetRawButton(static_cast<int>(DualSenseController::Button::CIRCLE), value);
}
void DualSenseControllerSim::SetSquareButton(bool value) {
SetRawButton(DualSenseController::Button::SQUARE, value);
SetRawButton(static_cast<int>(DualSenseController::Button::SQUARE), value);
}
void DualSenseControllerSim::SetTriangleButton(bool value) {
SetRawButton(DualSenseController::Button::TRIANGLE, value);
SetRawButton(static_cast<int>(DualSenseController::Button::TRIANGLE), value);
}
void DualSenseControllerSim::SetCreateButton(bool value) {
SetRawButton(DualSenseController::Button::CREATE, value);
SetRawButton(static_cast<int>(DualSenseController::Button::CREATE), value);
}
void DualSenseControllerSim::SetPSButton(bool value) {
SetRawButton(DualSenseController::Button::PS, value);
SetRawButton(static_cast<int>(DualSenseController::Button::PS), value);
}
void DualSenseControllerSim::SetOptionsButton(bool value) {
SetRawButton(DualSenseController::Button::OPTIONS, value);
SetRawButton(static_cast<int>(DualSenseController::Button::OPTIONS), value);
}
void DualSenseControllerSim::SetL3Button(bool value) {
SetRawButton(DualSenseController::Button::L3, value);
SetRawButton(static_cast<int>(DualSenseController::Button::L3), value);
}
void DualSenseControllerSim::SetR3Button(bool value) {
SetRawButton(DualSenseController::Button::R3, value);
SetRawButton(static_cast<int>(DualSenseController::Button::R3), value);
}
void DualSenseControllerSim::SetL1Button(bool value) {
SetRawButton(DualSenseController::Button::L1, value);
SetRawButton(static_cast<int>(DualSenseController::Button::L1), value);
}
void DualSenseControllerSim::SetR1Button(bool value) {
SetRawButton(DualSenseController::Button::R1, value);
SetRawButton(static_cast<int>(DualSenseController::Button::R1), value);
}
void DualSenseControllerSim::SetDpadUpButton(bool value) {
SetRawButton(DualSenseController::Button::DPAD_UP, value);
SetRawButton(static_cast<int>(DualSenseController::Button::DPAD_UP), value);
}
void DualSenseControllerSim::SetDpadDownButton(bool value) {
SetRawButton(DualSenseController::Button::DPAD_DOWN, value);
SetRawButton(static_cast<int>(DualSenseController::Button::DPAD_DOWN), value);
}
void DualSenseControllerSim::SetDpadLeftButton(bool value) {
SetRawButton(DualSenseController::Button::DPAD_LEFT, value);
SetRawButton(static_cast<int>(DualSenseController::Button::DPAD_LEFT), value);
}
void DualSenseControllerSim::SetDpadRightButton(bool value) {
SetRawButton(DualSenseController::Button::DPAD_RIGHT, value);
SetRawButton(static_cast<int>(DualSenseController::Button::DPAD_RIGHT), value);
}
void DualSenseControllerSim::SetMicrophoneButton(bool value) {
SetRawButton(DualSenseController::Button::MICROPHONE, value);
SetRawButton(static_cast<int>(DualSenseController::Button::MICROPHONE), value);
}
void DualSenseControllerSim::SetTouchpadButton(bool value) {
SetRawButton(DualSenseController::Button::TOUCHPAD, value);
SetRawButton(static_cast<int>(DualSenseController::Button::TOUCHPAD), value);
}

View File

@@ -28,85 +28,85 @@ XboxControllerSim::XboxControllerSim(int port) : GenericHIDSim{port} {
}
void XboxControllerSim::SetLeftX(double value) {
SetRawAxis(XboxController::Axis::LEFT_X, value);
SetRawAxis(static_cast<int>(XboxController::Axis::LEFT_X), value);
}
void XboxControllerSim::SetLeftY(double value) {
SetRawAxis(XboxController::Axis::LEFT_Y, value);
SetRawAxis(static_cast<int>(XboxController::Axis::LEFT_Y), value);
}
void XboxControllerSim::SetRightX(double value) {
SetRawAxis(XboxController::Axis::RIGHT_X, value);
SetRawAxis(static_cast<int>(XboxController::Axis::RIGHT_X), value);
}
void XboxControllerSim::SetRightY(double value) {
SetRawAxis(XboxController::Axis::RIGHT_Y, value);
SetRawAxis(static_cast<int>(XboxController::Axis::RIGHT_Y), value);
}
void XboxControllerSim::SetLeftTrigger(double value) {
SetRawAxis(XboxController::Axis::LEFT_TRIGGER, value);
SetRawAxis(static_cast<int>(XboxController::Axis::LEFT_TRIGGER), value);
}
void XboxControllerSim::SetRightTrigger(double value) {
SetRawAxis(XboxController::Axis::RIGHT_TRIGGER, value);
SetRawAxis(static_cast<int>(XboxController::Axis::RIGHT_TRIGGER), value);
}
void XboxControllerSim::SetAButton(bool value) {
SetRawButton(XboxController::Button::A, value);
SetRawButton(static_cast<int>(XboxController::Button::A), value);
}
void XboxControllerSim::SetBButton(bool value) {
SetRawButton(XboxController::Button::B, value);
SetRawButton(static_cast<int>(XboxController::Button::B), value);
}
void XboxControllerSim::SetXButton(bool value) {
SetRawButton(XboxController::Button::X, value);
SetRawButton(static_cast<int>(XboxController::Button::X), value);
}
void XboxControllerSim::SetYButton(bool value) {
SetRawButton(XboxController::Button::Y, value);
SetRawButton(static_cast<int>(XboxController::Button::Y), value);
}
void XboxControllerSim::SetViewButton(bool value) {
SetRawButton(XboxController::Button::VIEW, value);
SetRawButton(static_cast<int>(XboxController::Button::VIEW), value);
}
void XboxControllerSim::SetXboxButton(bool value) {
SetRawButton(XboxController::Button::XBOX, value);
SetRawButton(static_cast<int>(XboxController::Button::XBOX), value);
}
void XboxControllerSim::SetMenuButton(bool value) {
SetRawButton(XboxController::Button::MENU, value);
SetRawButton(static_cast<int>(XboxController::Button::MENU), value);
}
void XboxControllerSim::SetLeftStickButton(bool value) {
SetRawButton(XboxController::Button::LEFT_STICK, value);
SetRawButton(static_cast<int>(XboxController::Button::LEFT_STICK), value);
}
void XboxControllerSim::SetRightStickButton(bool value) {
SetRawButton(XboxController::Button::RIGHT_STICK, value);
SetRawButton(static_cast<int>(XboxController::Button::RIGHT_STICK), value);
}
void XboxControllerSim::SetLeftBumperButton(bool value) {
SetRawButton(XboxController::Button::LEFT_BUMPER, value);
SetRawButton(static_cast<int>(XboxController::Button::LEFT_BUMPER), value);
}
void XboxControllerSim::SetRightBumperButton(bool value) {
SetRawButton(XboxController::Button::RIGHT_BUMPER, value);
SetRawButton(static_cast<int>(XboxController::Button::RIGHT_BUMPER), value);
}
void XboxControllerSim::SetDpadUpButton(bool value) {
SetRawButton(XboxController::Button::DPAD_UP, value);
SetRawButton(static_cast<int>(XboxController::Button::DPAD_UP), value);
}
void XboxControllerSim::SetDpadDownButton(bool value) {
SetRawButton(XboxController::Button::DPAD_DOWN, value);
SetRawButton(static_cast<int>(XboxController::Button::DPAD_DOWN), value);
}
void XboxControllerSim::SetDpadLeftButton(bool value) {
SetRawButton(XboxController::Button::DPAD_LEFT, value);
SetRawButton(static_cast<int>(XboxController::Button::DPAD_LEFT), value);
}
void XboxControllerSim::SetDpadRightButton(bool value) {
SetRawButton(XboxController::Button::DPAD_RIGHT, value);
SetRawButton(static_cast<int>(XboxController::Button::DPAD_RIGHT), value);
}

View File

@@ -46,6 +46,60 @@ class DualSenseController
static constexpr GenericHID::SupportedOutputs SUPPORTED_OUTPUTS =
static_cast<GenericHID::SupportedOutputs>(26);
/** Represents a digital button on a DualSenseController. */
enum class Button {
/// Cross button.
CROSS = 0,
/// Circle button.
CIRCLE = 1,
/// Square button.
SQUARE = 2,
/// Triangle button.
TRIANGLE = 3,
/// Create button.
CREATE = 4,
/// PS button.
PS = 5,
/// Options button.
OPTIONS = 6,
/// L 3 button.
L3 = 7,
/// R 3 button.
R3 = 8,
/// L 1 button.
L1 = 9,
/// R 1 button.
R1 = 10,
/// Dpad Up button.
DPAD_UP = 11,
/// Dpad Down button.
DPAD_DOWN = 12,
/// Dpad Left button.
DPAD_LEFT = 13,
/// Dpad Right button.
DPAD_RIGHT = 14,
/// Microphone button.
MICROPHONE = 15,
/// Touchpad button.
TOUCHPAD = 20,
};
/** Represents an axis on a DualSenseController. */
enum class Axis {
/// Left X.
LEFT_X = 0,
/// Left Y.
LEFT_Y = 1,
/// Right X.
RIGHT_X = 2,
/// Right Y.
RIGHT_Y = 3,
/// L 2.
L2 = 4,
/// R 2.
R2 = 5,
};
/**
* Construct an instance of a controller.
*
@@ -144,7 +198,7 @@ class DualSenseController
* @param axis The axis to read
* @return the axis value.
*/
double GetAxis(int axis) const;
double GetAxis(Axis axis) const;
/**
* Constructs an event instance that is true when the axis value is less than
@@ -156,7 +210,7 @@ class DualSenseController
* @return an event instance that is true when the axis value is less than the
* provided threshold.
*/
BooleanEvent AxisLessThan(int axis, double threshold, EventLoop* loop) const;
BooleanEvent AxisLessThan(Axis axis, double threshold, EventLoop* loop) const;
/**
* Constructs an event instance that is true when the axis value is greater
@@ -168,7 +222,7 @@ class DualSenseController
* @return an event instance that is true when the axis value is greater than
* the provided threshold.
*/
BooleanEvent AxisGreaterThan(int axis, double threshold,
BooleanEvent AxisGreaterThan(Axis axis, double threshold,
EventLoop* loop) const;
/**
@@ -704,7 +758,7 @@ class DualSenseController
* @param button The button to read
* @return The state of the button.
*/
bool GetButton(int button) const;
bool GetButton(Button button) const;
/**
* Whether the button was pressed since the last check.
@@ -712,7 +766,7 @@ class DualSenseController
* @param button The button to read
* @return Whether the button was pressed since the last check.
*/
bool GetButtonPressed(int button);
bool GetButtonPressed(Button button);
/**
* Whether the button was released since the last check.
@@ -720,7 +774,7 @@ class DualSenseController
* @param button The button to read
* @return Whether the button was released since the last check.
*/
bool GetButtonReleased(int button);
bool GetButtonReleased(Button button);
/**
* Constructs an event instance around this button's digital signal.
@@ -730,7 +784,7 @@ class DualSenseController
* @return an event instance representing the button's digital signal attached
* to the given loop.
*/
BooleanEvent ButtonEvent(int button, EventLoop* loop) const;
BooleanEvent ButtonEvent(Button button, EventLoop* loop) const;
/**
* Set leds on the controller.
@@ -762,60 +816,6 @@ class DualSenseController
*/
TouchpadFinger GetTouchpadFinger(int finger) const;
/** Represents a digital button on a DualSenseController. */
struct Button {
/// Cross button.
static constexpr int CROSS = 0;
/// Circle button.
static constexpr int CIRCLE = 1;
/// Square button.
static constexpr int SQUARE = 2;
/// Triangle button.
static constexpr int TRIANGLE = 3;
/// Create button.
static constexpr int CREATE = 4;
/// PS button.
static constexpr int PS = 5;
/// Options button.
static constexpr int OPTIONS = 6;
/// L 3 button.
static constexpr int L3 = 7;
/// R 3 button.
static constexpr int R3 = 8;
/// L 1 button.
static constexpr int L1 = 9;
/// R 1 button.
static constexpr int R1 = 10;
/// Dpad Up button.
static constexpr int DPAD_UP = 11;
/// Dpad Down button.
static constexpr int DPAD_DOWN = 12;
/// Dpad Left button.
static constexpr int DPAD_LEFT = 13;
/// Dpad Right button.
static constexpr int DPAD_RIGHT = 14;
/// Microphone button.
static constexpr int MICROPHONE = 15;
/// Touchpad button.
static constexpr int TOUCHPAD = 20;
};
/** Represents an axis on a DualSenseController. */
struct Axis {
/// Left X.
static constexpr int LEFT_X = 0;
/// Left Y.
static constexpr int LEFT_Y = 1;
/// Right X.
static constexpr int RIGHT_X = 2;
/// Right Y.
static constexpr int RIGHT_Y = 3;
/// L 2.
static constexpr int L2 = 4;
/// R 2.
static constexpr int R2 = 5;
};
void InitSendable(wpi::util::SendableBuilder& builder) override;
private:

View File

@@ -46,6 +46,56 @@ class XboxController
static constexpr GenericHID::SupportedOutputs SUPPORTED_OUTPUTS =
static_cast<GenericHID::SupportedOutputs>(24);
/** Represents a digital button on a XboxController. */
enum class Button {
/// A button.
A = 0,
/// B button.
B = 1,
/// X button.
X = 2,
/// Y button.
Y = 3,
/// View button.
VIEW = 4,
/// Xbox button.
XBOX = 5,
/// Menu button.
MENU = 6,
/// Left Stick button.
LEFT_STICK = 7,
/// Right Stick button.
RIGHT_STICK = 8,
/// Left Bumper button.
LEFT_BUMPER = 9,
/// Right Bumper button.
RIGHT_BUMPER = 10,
/// Dpad Up button.
DPAD_UP = 11,
/// Dpad Down button.
DPAD_DOWN = 12,
/// Dpad Left button.
DPAD_LEFT = 13,
/// Dpad Right button.
DPAD_RIGHT = 14,
};
/** Represents an axis on a XboxController. */
enum class Axis {
/// Left X.
LEFT_X = 0,
/// Left Y.
LEFT_Y = 1,
/// Right X.
RIGHT_X = 2,
/// Right Y.
RIGHT_Y = 3,
/// Left Trigger.
LEFT_TRIGGER = 4,
/// Right Trigger.
RIGHT_TRIGGER = 5,
};
/**
* Construct an instance of a controller.
*
@@ -144,7 +194,7 @@ class XboxController
* @param axis The axis to read
* @return the axis value.
*/
double GetAxis(int axis) const;
double GetAxis(Axis axis) const;
/**
* Constructs an event instance that is true when the axis value is less than
@@ -156,7 +206,7 @@ class XboxController
* @return an event instance that is true when the axis value is less than the
* provided threshold.
*/
BooleanEvent AxisLessThan(int axis, double threshold, EventLoop* loop) const;
BooleanEvent AxisLessThan(Axis axis, double threshold, EventLoop* loop) const;
/**
* Constructs an event instance that is true when the axis value is greater
@@ -168,7 +218,7 @@ class XboxController
* @return an event instance that is true when the axis value is greater than
* the provided threshold.
*/
BooleanEvent AxisGreaterThan(int axis, double threshold,
BooleanEvent AxisGreaterThan(Axis axis, double threshold,
EventLoop* loop) const;
/**
@@ -642,7 +692,7 @@ class XboxController
* @param button The button to read
* @return The state of the button.
*/
bool GetButton(int button) const;
bool GetButton(Button button) const;
/**
* Whether the button was pressed since the last check.
@@ -650,7 +700,7 @@ class XboxController
* @param button The button to read
* @return Whether the button was pressed since the last check.
*/
bool GetButtonPressed(int button);
bool GetButtonPressed(Button button);
/**
* Whether the button was released since the last check.
@@ -658,7 +708,7 @@ class XboxController
* @param button The button to read
* @return Whether the button was released since the last check.
*/
bool GetButtonReleased(int button);
bool GetButtonReleased(Button button);
/**
* Constructs an event instance around this button's digital signal.
@@ -668,7 +718,7 @@ class XboxController
* @return an event instance representing the button's digital signal attached
* to the given loop.
*/
BooleanEvent ButtonEvent(int button, EventLoop* loop) const;
BooleanEvent ButtonEvent(Button button, EventLoop* loop) const;
/**
* Set leds on the controller.
@@ -687,56 +737,6 @@ class XboxController
*/
void SetRumble(GenericHID::RumbleType type, double value);
/** Represents a digital button on a XboxController. */
struct Button {
/// A button.
static constexpr int A = 0;
/// B button.
static constexpr int B = 1;
/// X button.
static constexpr int X = 2;
/// Y button.
static constexpr int Y = 3;
/// View button.
static constexpr int VIEW = 4;
/// Xbox button.
static constexpr int XBOX = 5;
/// Menu button.
static constexpr int MENU = 6;
/// Left Stick button.
static constexpr int LEFT_STICK = 7;
/// Right Stick button.
static constexpr int RIGHT_STICK = 8;
/// Left Bumper button.
static constexpr int LEFT_BUMPER = 9;
/// Right Bumper button.
static constexpr int RIGHT_BUMPER = 10;
/// Dpad Up button.
static constexpr int DPAD_UP = 11;
/// Dpad Down button.
static constexpr int DPAD_DOWN = 12;
/// Dpad Left button.
static constexpr int DPAD_LEFT = 13;
/// Dpad Right button.
static constexpr int DPAD_RIGHT = 14;
};
/** Represents an axis on a XboxController. */
struct Axis {
/// Left X.
static constexpr int LEFT_X = 0;
/// Left Y.
static constexpr int LEFT_Y = 1;
/// Right X.
static constexpr int RIGHT_X = 2;
/// Right Y.
static constexpr int RIGHT_Y = 3;
/// Left Trigger.
static constexpr int LEFT_TRIGGER = 4;
/// Right Trigger.
static constexpr int RIGHT_TRIGGER = 5;
};
void InitSendable(wpi::util::SendableBuilder& builder) override;
private:

View File

@@ -8,6 +8,9 @@ classes:
force_no_trampoline: true
ignored_bases:
- wpi::util::SendableHelper<DualSenseController>
enums:
Button:
Axis:
attributes:
TOUCHPAD_COUNT:
SUPPORTS_RUMBLE:
@@ -115,30 +118,3 @@ classes:
InitSendable:
GetL2:
GetR2:
wpi::DualSenseController::Button:
attributes:
CROSS:
CIRCLE:
SQUARE:
TRIANGLE:
CREATE:
PS:
OPTIONS:
L3:
R3:
L1:
R1:
DPAD_UP:
DPAD_DOWN:
DPAD_LEFT:
DPAD_RIGHT:
MICROPHONE:
TOUCHPAD:
wpi::DualSenseController::Axis:
attributes:
LEFT_X:
LEFT_Y:
RIGHT_X:
RIGHT_Y:
L2:
R2:

View File

@@ -8,6 +8,9 @@ classes:
force_no_trampoline: true
ignored_bases:
- wpi::util::SendableHelper<XboxController>
enums:
Button:
Axis:
attributes:
TOUCHPAD_COUNT:
SUPPORTS_RUMBLE:
@@ -105,28 +108,3 @@ classes:
InitSendable:
GetLeftTrigger:
GetRightTrigger:
wpi::XboxController::Button:
attributes:
A:
B:
X:
Y:
VIEW:
XBOX:
MENU:
LEFT_STICK:
RIGHT_STICK:
LEFT_BUMPER:
RIGHT_BUMPER:
DPAD_UP:
DPAD_DOWN:
DPAD_LEFT:
DPAD_RIGHT:
wpi::XboxController::Axis:
attributes:
LEFT_X:
LEFT_Y:
RIGHT_X:
RIGHT_Y:
LEFT_TRIGGER:
RIGHT_TRIGGER: