[wpilib] Rename GenericHID and Gamepad enums to all caps

GenericHID.getSupportedOutputs(): Return EnumSet
Gamepad: Add Button-taking accessors
This commit is contained in:
Peter Johnson
2026-03-17 17:19:58 -07:00
parent d86a745328
commit a57d658ef1
25 changed files with 1266 additions and 745 deletions

View File

@@ -37,6 +37,29 @@ public class CommandGamepad extends CommandGenericHID {
return m_hid;
}
/**
* 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(Gamepad.Button, EventLoop)
*/
public Trigger button(Gamepad.Button button) {
return super.button(button.value);
}
/**
* 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(Gamepad.Button button, EventLoop loop) {
return button(button.value, loop);
}
/**
* Constructs a Trigger instance around the South Face button's digital signal.
*
@@ -56,7 +79,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger southFace(EventLoop loop) {
return button(Gamepad.Button.kSouthFace.value, loop);
return button(Gamepad.Button.SOUTH_FACE, loop);
}
/**
@@ -78,7 +101,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger eastFace(EventLoop loop) {
return button(Gamepad.Button.kEastFace.value, loop);
return button(Gamepad.Button.EAST_FACE, loop);
}
/**
@@ -100,7 +123,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger westFace(EventLoop loop) {
return button(Gamepad.Button.kWestFace.value, loop);
return button(Gamepad.Button.WEST_FACE, loop);
}
/**
@@ -122,7 +145,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger northFace(EventLoop loop) {
return button(Gamepad.Button.kNorthFace.value, loop);
return button(Gamepad.Button.NORTH_FACE, loop);
}
/**
@@ -144,7 +167,7 @@ public class CommandGamepad extends CommandGenericHID {
* loop.
*/
public Trigger back(EventLoop loop) {
return button(Gamepad.Button.kBack.value, loop);
return button(Gamepad.Button.BACK, loop);
}
/**
@@ -166,7 +189,7 @@ public class CommandGamepad extends CommandGenericHID {
* loop.
*/
public Trigger guide(EventLoop loop) {
return button(Gamepad.Button.kGuide.value, loop);
return button(Gamepad.Button.GUIDE, loop);
}
/**
@@ -188,7 +211,7 @@ public class CommandGamepad extends CommandGenericHID {
* loop.
*/
public Trigger start(EventLoop loop) {
return button(Gamepad.Button.kStart.value, loop);
return button(Gamepad.Button.START, loop);
}
/**
@@ -210,7 +233,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger leftStick(EventLoop loop) {
return button(Gamepad.Button.kLeftStick.value, loop);
return button(Gamepad.Button.LEFT_STICK, loop);
}
/**
@@ -232,7 +255,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger rightStick(EventLoop loop) {
return button(Gamepad.Button.kRightStick.value, loop);
return button(Gamepad.Button.RIGHT_STICK, loop);
}
/**
@@ -254,7 +277,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger leftBumper(EventLoop loop) {
return button(Gamepad.Button.kLeftBumper.value, loop);
return button(Gamepad.Button.LEFT_BUMPER, loop);
}
/**
@@ -276,7 +299,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger rightBumper(EventLoop loop) {
return button(Gamepad.Button.kRightBumper.value, loop);
return button(Gamepad.Button.RIGHT_BUMPER, loop);
}
/**
@@ -298,7 +321,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadUp(EventLoop loop) {
return button(Gamepad.Button.kDpadUp.value, loop);
return button(Gamepad.Button.DPAD_UP, loop);
}
/**
@@ -320,7 +343,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadDown(EventLoop loop) {
return button(Gamepad.Button.kDpadDown.value, loop);
return button(Gamepad.Button.DPAD_DOWN, loop);
}
/**
@@ -342,7 +365,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadLeft(EventLoop loop) {
return button(Gamepad.Button.kDpadLeft.value, loop);
return button(Gamepad.Button.DPAD_LEFT, loop);
}
/**
@@ -364,7 +387,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadRight(EventLoop loop) {
return button(Gamepad.Button.kDpadRight.value, loop);
return button(Gamepad.Button.DPAD_RIGHT, loop);
}
/**
@@ -386,7 +409,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc1(EventLoop loop) {
return button(Gamepad.Button.kMisc1.value, loop);
return button(Gamepad.Button.MISC_1, loop);
}
/**
@@ -408,7 +431,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger rightPaddle1(EventLoop loop) {
return button(Gamepad.Button.kRightPaddle1.value, loop);
return button(Gamepad.Button.RIGHT_PADDLE_1, loop);
}
/**
@@ -430,7 +453,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger leftPaddle1(EventLoop loop) {
return button(Gamepad.Button.kLeftPaddle1.value, loop);
return button(Gamepad.Button.LEFT_PADDLE_1, loop);
}
/**
@@ -452,7 +475,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger rightPaddle2(EventLoop loop) {
return button(Gamepad.Button.kRightPaddle2.value, loop);
return button(Gamepad.Button.RIGHT_PADDLE_2, loop);
}
/**
@@ -474,7 +497,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger leftPaddle2(EventLoop loop) {
return button(Gamepad.Button.kLeftPaddle2.value, loop);
return button(Gamepad.Button.LEFT_PADDLE_2, loop);
}
/**
@@ -496,7 +519,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger touchpad(EventLoop loop) {
return button(Gamepad.Button.kTouchpad.value, loop);
return button(Gamepad.Button.TOUCHPAD, loop);
}
/**
@@ -518,7 +541,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc2(EventLoop loop) {
return button(Gamepad.Button.kMisc2.value, loop);
return button(Gamepad.Button.MISC_2, loop);
}
/**
@@ -540,7 +563,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc3(EventLoop loop) {
return button(Gamepad.Button.kMisc3.value, loop);
return button(Gamepad.Button.MISC_3, loop);
}
/**
@@ -562,7 +585,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc4(EventLoop loop) {
return button(Gamepad.Button.kMisc4.value, loop);
return button(Gamepad.Button.MISC_4, loop);
}
/**
@@ -584,7 +607,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc5(EventLoop loop) {
return button(Gamepad.Button.kMisc5.value, loop);
return button(Gamepad.Button.MISC_5, loop);
}
/**
@@ -606,7 +629,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc6(EventLoop loop) {
return button(Gamepad.Button.kMisc6.value, loop);
return button(Gamepad.Button.MISC_6, loop);
}
/**
@@ -620,7 +643,7 @@ public class CommandGamepad extends CommandGenericHID {
* threshold, attached to the given event loop
*/
public Trigger leftTrigger(double threshold, EventLoop loop) {
return axisGreaterThan(Gamepad.Axis.kLeftTrigger.value, threshold, loop);
return axisGreaterThan(Gamepad.Axis.LEFT_TRIGGER, threshold, loop);
}
/**
@@ -659,7 +682,7 @@ public class CommandGamepad extends CommandGenericHID {
* threshold, attached to the given event loop
*/
public Trigger rightTrigger(double threshold, EventLoop loop) {
return axisGreaterThan(Gamepad.Axis.kRightTrigger.value, threshold, loop);
return axisGreaterThan(Gamepad.Axis.RIGHT_TRIGGER, threshold, loop);
}
/**
@@ -687,6 +710,99 @@ public class CommandGamepad extends CommandGenericHID {
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(Gamepad.Axis axis, double threshold) {
return super.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(Gamepad.Axis axis, double threshold, EventLoop loop) {
return super.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(Gamepad.Axis axis, double threshold) {
return super.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(Gamepad.Axis axis, double threshold, EventLoop loop) {
return super.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(Gamepad.Axis axis, double threshold, EventLoop loop) {
return super.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(Gamepad.Axis axis, double threshold) {
return super.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(Gamepad.Axis axis) {
return getRawAxis(axis.value);
}
/**
* Get the X axis value of left side of the controller. Right is positive.
*

View File

@@ -0,0 +1,27 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package org.wpilib.command2.button;
import static org.wpilib.util.ErrorMessages.requireNonNullParam;
import org.wpilib.driverstation.Gamepad;
/**
* A {@link Trigger} that gets its state from a {@link Gamepad}.
*
* <p>This class is provided by the NewCommands VendorDep
*/
public class GamepadButton extends Trigger {
/**
* Creates a gamepad button for triggering commands.
*
* @param gamepad The gamepad on which the button is located.
* @param button The button
*/
public GamepadButton(Gamepad gamepad, Gamepad.Button button) {
super(() -> gamepad.getButton(button));
requireNonNullParam(gamepad, "gamepad", "GamepadButton");
}
}

View File

@@ -4,6 +4,8 @@
#include "wpi/commands2/button/CommandGamepad.hpp"
#include "wpi/commands2/button/CommandGenericHID.hpp"
using namespace wpi::cmd;
CommandGamepad::CommandGamepad(int port)
@@ -13,108 +15,113 @@ wpi::Gamepad& CommandGamepad::GetHID() {
return m_hid;
}
Trigger CommandGamepad::Button(enum wpi::Gamepad::Button button,
wpi::EventLoop* loop) const {
return CommandGenericHID::Button(static_cast<int>(button), loop);
}
Trigger CommandGamepad::SouthFace(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kSouthFace, loop);
return Button(wpi::Gamepad::Button::SOUTH_FACE, loop);
}
Trigger CommandGamepad::EastFace(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kEastFace, loop);
return Button(wpi::Gamepad::Button::EAST_FACE, loop);
}
Trigger CommandGamepad::WestFace(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kWestFace, loop);
return Button(wpi::Gamepad::Button::WEST_FACE, loop);
}
Trigger CommandGamepad::NorthFace(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kNorthFace, loop);
return Button(wpi::Gamepad::Button::NORTH_FACE, loop);
}
Trigger CommandGamepad::Back(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kBack, loop);
return Button(wpi::Gamepad::Button::BACK, loop);
}
Trigger CommandGamepad::Guide(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kGuide, loop);
return Button(wpi::Gamepad::Button::GUIDE, loop);
}
Trigger CommandGamepad::Start(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kStart, loop);
return Button(wpi::Gamepad::Button::START, loop);
}
Trigger CommandGamepad::LeftStick(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kLeftStick, loop);
return Button(wpi::Gamepad::Button::LEFT_STICK, loop);
}
Trigger CommandGamepad::RightStick(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kRightStick, loop);
return Button(wpi::Gamepad::Button::RIGHT_STICK, loop);
}
Trigger CommandGamepad::LeftBumper(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kLeftBumper, loop);
return Button(wpi::Gamepad::Button::LEFT_BUMPER, loop);
}
Trigger CommandGamepad::RightBumper(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kRightBumper, loop);
return Button(wpi::Gamepad::Button::RIGHT_BUMPER, loop);
}
Trigger CommandGamepad::DpadUp(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kDpadUp, loop);
return Button(wpi::Gamepad::Button::DPAD_UP, loop);
}
Trigger CommandGamepad::DpadDown(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kDpadDown, loop);
return Button(wpi::Gamepad::Button::DPAD_DOWN, loop);
}
Trigger CommandGamepad::DpadLeft(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kDpadLeft, loop);
return Button(wpi::Gamepad::Button::DPAD_LEFT, loop);
}
Trigger CommandGamepad::DpadRight(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kDpadRight, loop);
return Button(wpi::Gamepad::Button::DPAD_RIGHT, loop);
}
Trigger CommandGamepad::Misc1(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kMisc1, loop);
return Button(wpi::Gamepad::Button::MISC_1, loop);
}
Trigger CommandGamepad::RightPaddle1(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kRightPaddle1, loop);
return Button(wpi::Gamepad::Button::RIGHT_PADDLE_1, loop);
}
Trigger CommandGamepad::LeftPaddle1(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kLeftPaddle1, loop);
return Button(wpi::Gamepad::Button::LEFT_PADDLE_1, loop);
}
Trigger CommandGamepad::RightPaddle2(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kRightPaddle2, loop);
return Button(wpi::Gamepad::Button::RIGHT_PADDLE_2, loop);
}
Trigger CommandGamepad::LeftPaddle2(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kLeftPaddle2, loop);
return Button(wpi::Gamepad::Button::LEFT_PADDLE_2, loop);
}
Trigger CommandGamepad::Touchpad(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kTouchpad, loop);
return Button(wpi::Gamepad::Button::TOUCHPAD, loop);
}
Trigger CommandGamepad::Misc2(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kMisc2, loop);
return Button(wpi::Gamepad::Button::MISC_2, loop);
}
Trigger CommandGamepad::Misc3(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kMisc3, loop);
return Button(wpi::Gamepad::Button::MISC_3, loop);
}
Trigger CommandGamepad::Misc4(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kMisc4, loop);
return Button(wpi::Gamepad::Button::MISC_4, loop);
}
Trigger CommandGamepad::Misc5(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kMisc5, loop);
return Button(wpi::Gamepad::Button::MISC_5, loop);
}
Trigger CommandGamepad::Misc6(wpi::EventLoop* loop) const {
return Button(wpi::Gamepad::Button::kMisc6, loop);
return Button(wpi::Gamepad::Button::MISC_6, loop);
}
Trigger CommandGamepad::LeftTrigger(double threshold,
@@ -131,6 +138,26 @@ Trigger CommandGamepad::RightTrigger(double threshold,
});
}
Trigger CommandGamepad::AxisLessThan(wpi::Gamepad::Axis axis, double threshold,
wpi::EventLoop* loop) const {
return CommandGenericHID::AxisLessThan(static_cast<int>(axis), threshold,
loop);
}
Trigger CommandGamepad::AxisGreaterThan(wpi::Gamepad::Axis axis,
double threshold,
wpi::EventLoop* loop) const {
return CommandGenericHID::AxisGreaterThan(static_cast<int>(axis), threshold,
loop);
}
Trigger CommandGamepad::AxisMagnitudeGreaterThan(wpi::Gamepad::Axis axis,
double threshold,
wpi::EventLoop* loop) const {
return CommandGenericHID::AxisMagnitudeGreaterThan(static_cast<int>(axis),
threshold, loop);
}
double CommandGamepad::GetLeftX() const {
return m_hid.GetLeftX();
}

View File

@@ -32,6 +32,19 @@ class CommandGamepad : public CommandGenericHID {
*/
wpi::Gamepad& GetHID();
/**
* 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::Gamepad::Button button,
wpi::EventLoop* loop = CommandScheduler::GetInstance()
.GetDefaultButtonLoop()) const;
/**
* Constructs a Trigger instance around the South Face button's
* digital signal.
@@ -381,6 +394,57 @@ class CommandGamepad : public CommandGenericHID {
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::Gamepad::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::Gamepad::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::Gamepad::Axis axis, double threshold,
wpi::EventLoop* loop =
CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
/**
* Get the X axis value of left side of the controller. Right is positive.
*

View File

@@ -0,0 +1,30 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include "wpi/commands2/button/Trigger.hpp"
#include "wpi/driverstation/Gamepad.hpp"
namespace wpi::cmd {
/**
* A class used to bind command scheduling to gamepad button presses. Can be
* composed with other buttons with the operators in Trigger.
*
* This class is provided by the NewCommands VendorDep
*
* @see Trigger
*/
class GamepadButton : public Trigger {
public:
/**
* Creates a GamepadButton that commands can be bound to.
*
* @param gamepad The gamepad on which the button is located.
* @param button The button
*/
explicit GamepadButton(wpi::Gamepad* gamepad,
enum wpi::Gamepad::Button button)
: Trigger([gamepad, button] { return gamepad->GetButton(button); }) {}
};
} // namespace wpi::cmd

View File

@@ -70,7 +70,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger southFace(EventLoop loop) {
return button(Gamepad.Button.kSouthFace.value, loop);
return button(Gamepad.Button.SOUTH_FACE.value, loop);
}
/**
@@ -94,7 +94,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger eastFace(EventLoop loop) {
return button(Gamepad.Button.kEastFace.value, loop);
return button(Gamepad.Button.EAST_FACE.value, loop);
}
/**
@@ -118,7 +118,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger westFace(EventLoop loop) {
return button(Gamepad.Button.kWestFace.value, loop);
return button(Gamepad.Button.WEST_FACE.value, loop);
}
/**
@@ -142,7 +142,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger northFace(EventLoop loop) {
return button(Gamepad.Button.kNorthFace.value, loop);
return button(Gamepad.Button.NORTH_FACE.value, loop);
}
/**
@@ -166,7 +166,7 @@ public class CommandGamepad extends CommandGenericHID {
* loop.
*/
public Trigger back(EventLoop loop) {
return button(Gamepad.Button.kBack.value, loop);
return button(Gamepad.Button.BACK.value, loop);
}
/**
@@ -190,7 +190,7 @@ public class CommandGamepad extends CommandGenericHID {
* loop.
*/
public Trigger guide(EventLoop loop) {
return button(Gamepad.Button.kGuide.value, loop);
return button(Gamepad.Button.GUIDE.value, loop);
}
/**
@@ -214,7 +214,7 @@ public class CommandGamepad extends CommandGenericHID {
* loop.
*/
public Trigger start(EventLoop loop) {
return button(Gamepad.Button.kStart.value, loop);
return button(Gamepad.Button.START.value, loop);
}
/**
@@ -238,7 +238,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger leftStick(EventLoop loop) {
return button(Gamepad.Button.kLeftStick.value, loop);
return button(Gamepad.Button.LEFT_STICK.value, loop);
}
/**
@@ -262,7 +262,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger rightStick(EventLoop loop) {
return button(Gamepad.Button.kRightStick.value, loop);
return button(Gamepad.Button.RIGHT_STICK.value, loop);
}
/**
@@ -286,7 +286,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger leftBumper(EventLoop loop) {
return button(Gamepad.Button.kLeftBumper.value, loop);
return button(Gamepad.Button.LEFT_BUMPER.value, loop);
}
/**
@@ -310,7 +310,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger rightBumper(EventLoop loop) {
return button(Gamepad.Button.kRightBumper.value, loop);
return button(Gamepad.Button.RIGHT_BUMPER.value, loop);
}
/**
@@ -334,7 +334,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadUp(EventLoop loop) {
return button(Gamepad.Button.kDpadUp.value, loop);
return button(Gamepad.Button.DPAD_UP.value, loop);
}
/**
@@ -358,7 +358,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadDown(EventLoop loop) {
return button(Gamepad.Button.kDpadDown.value, loop);
return button(Gamepad.Button.DPAD_DOWN.value, loop);
}
/**
@@ -382,7 +382,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadLeft(EventLoop loop) {
return button(Gamepad.Button.kDpadLeft.value, loop);
return button(Gamepad.Button.DPAD_LEFT.value, loop);
}
/**
@@ -406,7 +406,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger dpadRight(EventLoop loop) {
return button(Gamepad.Button.kDpadRight.value, loop);
return button(Gamepad.Button.DPAD_RIGHT.value, loop);
}
/**
@@ -430,7 +430,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc1(EventLoop loop) {
return button(Gamepad.Button.kMisc1.value, loop);
return button(Gamepad.Button.MISC_1.value, loop);
}
/**
@@ -454,7 +454,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger rightPaddle1(EventLoop loop) {
return button(Gamepad.Button.kRightPaddle1.value, loop);
return button(Gamepad.Button.RIGHT_PADDLE_1.value, loop);
}
/**
@@ -478,7 +478,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger leftPaddle1(EventLoop loop) {
return button(Gamepad.Button.kLeftPaddle1.value, loop);
return button(Gamepad.Button.LEFT_PADDLE_1.value, loop);
}
/**
@@ -502,7 +502,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger rightPaddle2(EventLoop loop) {
return button(Gamepad.Button.kRightPaddle2.value, loop);
return button(Gamepad.Button.RIGHT_PADDLE_2.value, loop);
}
/**
@@ -526,7 +526,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger leftPaddle2(EventLoop loop) {
return button(Gamepad.Button.kLeftPaddle2.value, loop);
return button(Gamepad.Button.LEFT_PADDLE_2.value, loop);
}
/**
@@ -550,7 +550,7 @@ public class CommandGamepad extends CommandGenericHID {
* given loop.
*/
public Trigger touchpad(EventLoop loop) {
return button(Gamepad.Button.kTouchpad.value, loop);
return button(Gamepad.Button.TOUCHPAD.value, loop);
}
/**
@@ -574,7 +574,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc2(EventLoop loop) {
return button(Gamepad.Button.kMisc2.value, loop);
return button(Gamepad.Button.MISC_2.value, loop);
}
/**
@@ -598,7 +598,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc3(EventLoop loop) {
return button(Gamepad.Button.kMisc3.value, loop);
return button(Gamepad.Button.MISC_3.value, loop);
}
/**
@@ -622,7 +622,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc4(EventLoop loop) {
return button(Gamepad.Button.kMisc4.value, loop);
return button(Gamepad.Button.MISC_4.value, loop);
}
/**
@@ -646,7 +646,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc5(EventLoop loop) {
return button(Gamepad.Button.kMisc5.value, loop);
return button(Gamepad.Button.MISC_5.value, loop);
}
/**
@@ -670,7 +670,7 @@ public class CommandGamepad extends CommandGenericHID {
* the given loop.
*/
public Trigger misc6(EventLoop loop) {
return button(Gamepad.Button.kMisc6.value, loop);
return button(Gamepad.Button.MISC_6.value, loop);
}
/**
@@ -684,7 +684,7 @@ public class CommandGamepad extends CommandGenericHID {
* threshold, attached to the given event loop
*/
public Trigger leftTrigger(double threshold, EventLoop loop) {
return axisGreaterThan(Gamepad.Axis.kLeftTrigger.value, threshold, loop);
return axisGreaterThan(Gamepad.Axis.LEFT_TRIGGER.value, threshold, loop);
}
/**
@@ -725,7 +725,7 @@ public class CommandGamepad extends CommandGenericHID {
* threshold, attached to the given event loop
*/
public Trigger rightTrigger(double threshold, EventLoop loop) {
return axisGreaterThan(Gamepad.Axis.kRightTrigger.value, threshold, loop);
return axisGreaterThan(Gamepad.Axis.RIGHT_TRIGGER.value, threshold, loop);
}
/**

View File

@@ -125,8 +125,6 @@ def wpilib_extension(srcs = [], header_to_dat_deps = [], extra_hdrs = [], includ
tmpl_class_names = [],
trampolines = [
("wpi::Gamepad", "wpi__Gamepad.hpp"),
("wpi::Gamepad::Button", "wpi__Gamepad__Button.hpp"),
("wpi::Gamepad::Axis", "wpi__Gamepad__Axis.hpp"),
],
),
struct(

View File

@@ -15,23 +15,23 @@ Gamepad::Gamepad(int port) : GenericHID(port) {
}
double Gamepad::GetLeftX() const {
return GetRawAxis(Axis::kLeftX);
return GetAxis(Axis::LEFT_X);
}
double Gamepad::GetLeftY() const {
return GetRawAxis(Axis::kLeftY);
return GetAxis(Axis::LEFT_Y);
}
double Gamepad::GetRightX() const {
return GetRawAxis(Axis::kRightX);
return GetAxis(Axis::RIGHT_X);
}
double Gamepad::GetRightY() const {
return GetRawAxis(Axis::kRightY);
return GetAxis(Axis::RIGHT_Y);
}
double Gamepad::GetLeftTriggerAxis() const {
return GetRawAxis(Axis::kLeftTrigger);
return GetAxis(Axis::LEFT_TRIGGER);
}
BooleanEvent Gamepad::LeftTrigger(double threshold, EventLoop* loop) const {
@@ -45,7 +45,7 @@ BooleanEvent Gamepad::LeftTrigger(EventLoop* loop) const {
}
double Gamepad::GetRightTriggerAxis() const {
return GetRawAxis(Axis::kRightTrigger);
return GetAxis(Axis::RIGHT_TRIGGER);
}
BooleanEvent Gamepad::RightTrigger(double threshold, EventLoop* loop) const {
@@ -59,15 +59,15 @@ BooleanEvent Gamepad::RightTrigger(EventLoop* loop) const {
}
bool Gamepad::GetSouthFaceButton() const {
return GetRawButton(Button::kSouthFace);
return GetButton(Button::SOUTH_FACE);
}
bool Gamepad::GetSouthFaceButtonPressed() {
return GetRawButtonPressed(Button::kSouthFace);
return GetButtonPressed(Button::SOUTH_FACE);
}
bool Gamepad::GetSouthFaceButtonReleased() {
return GetRawButtonReleased(Button::kSouthFace);
return GetButtonReleased(Button::SOUTH_FACE);
}
BooleanEvent Gamepad::SouthFace(EventLoop* loop) const {
@@ -75,15 +75,15 @@ BooleanEvent Gamepad::SouthFace(EventLoop* loop) const {
}
bool Gamepad::GetEastFaceButton() const {
return GetRawButton(Button::kEastFace);
return GetButton(Button::EAST_FACE);
}
bool Gamepad::GetEastFaceButtonPressed() {
return GetRawButtonPressed(Button::kEastFace);
return GetButtonPressed(Button::EAST_FACE);
}
bool Gamepad::GetEastFaceButtonReleased() {
return GetRawButtonReleased(Button::kEastFace);
return GetButtonReleased(Button::EAST_FACE);
}
BooleanEvent Gamepad::EastFace(EventLoop* loop) const {
@@ -91,15 +91,15 @@ BooleanEvent Gamepad::EastFace(EventLoop* loop) const {
}
bool Gamepad::GetWestFaceButton() const {
return GetRawButton(Button::kWestFace);
return GetButton(Button::WEST_FACE);
}
bool Gamepad::GetWestFaceButtonPressed() {
return GetRawButtonPressed(Button::kWestFace);
return GetButtonPressed(Button::WEST_FACE);
}
bool Gamepad::GetWestFaceButtonReleased() {
return GetRawButtonReleased(Button::kWestFace);
return GetButtonReleased(Button::WEST_FACE);
}
BooleanEvent Gamepad::WestFace(EventLoop* loop) const {
@@ -107,15 +107,15 @@ BooleanEvent Gamepad::WestFace(EventLoop* loop) const {
}
bool Gamepad::GetNorthFaceButton() const {
return GetRawButton(Button::kNorthFace);
return GetButton(Button::NORTH_FACE);
}
bool Gamepad::GetNorthFaceButtonPressed() {
return GetRawButtonPressed(Button::kNorthFace);
return GetButtonPressed(Button::NORTH_FACE);
}
bool Gamepad::GetNorthFaceButtonReleased() {
return GetRawButtonReleased(Button::kNorthFace);
return GetButtonReleased(Button::NORTH_FACE);
}
BooleanEvent Gamepad::NorthFace(EventLoop* loop) const {
@@ -123,15 +123,15 @@ BooleanEvent Gamepad::NorthFace(EventLoop* loop) const {
}
bool Gamepad::GetBackButton() const {
return GetRawButton(Button::kBack);
return GetButton(Button::BACK);
}
bool Gamepad::GetBackButtonPressed() {
return GetRawButtonPressed(Button::kBack);
return GetButtonPressed(Button::BACK);
}
bool Gamepad::GetBackButtonReleased() {
return GetRawButtonReleased(Button::kBack);
return GetButtonReleased(Button::BACK);
}
BooleanEvent Gamepad::Back(EventLoop* loop) const {
@@ -139,15 +139,15 @@ BooleanEvent Gamepad::Back(EventLoop* loop) const {
}
bool Gamepad::GetGuideButton() const {
return GetRawButton(Button::kGuide);
return GetButton(Button::GUIDE);
}
bool Gamepad::GetGuideButtonPressed() {
return GetRawButtonPressed(Button::kGuide);
return GetButtonPressed(Button::GUIDE);
}
bool Gamepad::GetGuideButtonReleased() {
return GetRawButtonReleased(Button::kGuide);
return GetButtonReleased(Button::GUIDE);
}
BooleanEvent Gamepad::Guide(EventLoop* loop) const {
@@ -155,15 +155,15 @@ BooleanEvent Gamepad::Guide(EventLoop* loop) const {
}
bool Gamepad::GetStartButton() const {
return GetRawButton(Button::kStart);
return GetButton(Button::START);
}
bool Gamepad::GetStartButtonPressed() {
return GetRawButtonPressed(Button::kStart);
return GetButtonPressed(Button::START);
}
bool Gamepad::GetStartButtonReleased() {
return GetRawButtonReleased(Button::kStart);
return GetButtonReleased(Button::START);
}
BooleanEvent Gamepad::Start(EventLoop* loop) const {
@@ -171,15 +171,15 @@ BooleanEvent Gamepad::Start(EventLoop* loop) const {
}
bool Gamepad::GetLeftStickButton() const {
return GetRawButton(Button::kLeftStick);
return GetButton(Button::LEFT_STICK);
}
bool Gamepad::GetLeftStickButtonPressed() {
return GetRawButtonPressed(Button::kLeftStick);
return GetButtonPressed(Button::LEFT_STICK);
}
bool Gamepad::GetLeftStickButtonReleased() {
return GetRawButtonReleased(Button::kLeftStick);
return GetButtonReleased(Button::LEFT_STICK);
}
BooleanEvent Gamepad::LeftStick(EventLoop* loop) const {
@@ -187,15 +187,15 @@ BooleanEvent Gamepad::LeftStick(EventLoop* loop) const {
}
bool Gamepad::GetRightStickButton() const {
return GetRawButton(Button::kRightStick);
return GetButton(Button::RIGHT_STICK);
}
bool Gamepad::GetRightStickButtonPressed() {
return GetRawButtonPressed(Button::kRightStick);
return GetButtonPressed(Button::RIGHT_STICK);
}
bool Gamepad::GetRightStickButtonReleased() {
return GetRawButtonReleased(Button::kRightStick);
return GetButtonReleased(Button::RIGHT_STICK);
}
BooleanEvent Gamepad::RightStick(EventLoop* loop) const {
@@ -203,15 +203,15 @@ BooleanEvent Gamepad::RightStick(EventLoop* loop) const {
}
bool Gamepad::GetLeftBumperButton() const {
return GetRawButton(Button::kLeftBumper);
return GetButton(Button::LEFT_BUMPER);
}
bool Gamepad::GetLeftBumperButtonPressed() {
return GetRawButtonPressed(Button::kLeftBumper);
return GetButtonPressed(Button::LEFT_BUMPER);
}
bool Gamepad::GetLeftBumperButtonReleased() {
return GetRawButtonReleased(Button::kLeftBumper);
return GetButtonReleased(Button::LEFT_BUMPER);
}
BooleanEvent Gamepad::LeftBumper(EventLoop* loop) const {
@@ -219,15 +219,15 @@ BooleanEvent Gamepad::LeftBumper(EventLoop* loop) const {
}
bool Gamepad::GetRightBumperButton() const {
return GetRawButton(Button::kRightBumper);
return GetButton(Button::RIGHT_BUMPER);
}
bool Gamepad::GetRightBumperButtonPressed() {
return GetRawButtonPressed(Button::kRightBumper);
return GetButtonPressed(Button::RIGHT_BUMPER);
}
bool Gamepad::GetRightBumperButtonReleased() {
return GetRawButtonReleased(Button::kRightBumper);
return GetButtonReleased(Button::RIGHT_BUMPER);
}
BooleanEvent Gamepad::RightBumper(EventLoop* loop) const {
@@ -235,15 +235,15 @@ BooleanEvent Gamepad::RightBumper(EventLoop* loop) const {
}
bool Gamepad::GetDpadUpButton() const {
return GetRawButton(Button::kDpadUp);
return GetButton(Button::DPAD_UP);
}
bool Gamepad::GetDpadUpButtonPressed() {
return GetRawButtonPressed(Button::kDpadUp);
return GetButtonPressed(Button::DPAD_UP);
}
bool Gamepad::GetDpadUpButtonReleased() {
return GetRawButtonReleased(Button::kDpadUp);
return GetButtonReleased(Button::DPAD_UP);
}
BooleanEvent Gamepad::DpadUp(EventLoop* loop) const {
@@ -251,15 +251,15 @@ BooleanEvent Gamepad::DpadUp(EventLoop* loop) const {
}
bool Gamepad::GetDpadDownButton() const {
return GetRawButton(Button::kDpadDown);
return GetButton(Button::DPAD_DOWN);
}
bool Gamepad::GetDpadDownButtonPressed() {
return GetRawButtonPressed(Button::kDpadDown);
return GetButtonPressed(Button::DPAD_DOWN);
}
bool Gamepad::GetDpadDownButtonReleased() {
return GetRawButtonReleased(Button::kDpadDown);
return GetButtonReleased(Button::DPAD_DOWN);
}
BooleanEvent Gamepad::DpadDown(EventLoop* loop) const {
@@ -267,15 +267,15 @@ BooleanEvent Gamepad::DpadDown(EventLoop* loop) const {
}
bool Gamepad::GetDpadLeftButton() const {
return GetRawButton(Button::kDpadLeft);
return GetButton(Button::DPAD_LEFT);
}
bool Gamepad::GetDpadLeftButtonPressed() {
return GetRawButtonPressed(Button::kDpadLeft);
return GetButtonPressed(Button::DPAD_LEFT);
}
bool Gamepad::GetDpadLeftButtonReleased() {
return GetRawButtonReleased(Button::kDpadLeft);
return GetButtonReleased(Button::DPAD_LEFT);
}
BooleanEvent Gamepad::DpadLeft(EventLoop* loop) const {
@@ -283,15 +283,15 @@ BooleanEvent Gamepad::DpadLeft(EventLoop* loop) const {
}
bool Gamepad::GetDpadRightButton() const {
return GetRawButton(Button::kDpadRight);
return GetButton(Button::DPAD_RIGHT);
}
bool Gamepad::GetDpadRightButtonPressed() {
return GetRawButtonPressed(Button::kDpadRight);
return GetButtonPressed(Button::DPAD_RIGHT);
}
bool Gamepad::GetDpadRightButtonReleased() {
return GetRawButtonReleased(Button::kDpadRight);
return GetButtonReleased(Button::DPAD_RIGHT);
}
BooleanEvent Gamepad::DpadRight(EventLoop* loop) const {
@@ -299,15 +299,15 @@ BooleanEvent Gamepad::DpadRight(EventLoop* loop) const {
}
bool Gamepad::GetMisc1Button() const {
return GetRawButton(Button::kMisc1);
return GetButton(Button::MISC_1);
}
bool Gamepad::GetMisc1ButtonPressed() {
return GetRawButtonPressed(Button::kMisc1);
return GetButtonPressed(Button::MISC_1);
}
bool Gamepad::GetMisc1ButtonReleased() {
return GetRawButtonReleased(Button::kMisc1);
return GetButtonReleased(Button::MISC_1);
}
BooleanEvent Gamepad::Misc1(EventLoop* loop) const {
@@ -315,15 +315,15 @@ BooleanEvent Gamepad::Misc1(EventLoop* loop) const {
}
bool Gamepad::GetRightPaddle1Button() const {
return GetRawButton(Button::kRightPaddle1);
return GetButton(Button::RIGHT_PADDLE_1);
}
bool Gamepad::GetRightPaddle1ButtonPressed() {
return GetRawButtonPressed(Button::kRightPaddle1);
return GetButtonPressed(Button::RIGHT_PADDLE_1);
}
bool Gamepad::GetRightPaddle1ButtonReleased() {
return GetRawButtonReleased(Button::kRightPaddle1);
return GetButtonReleased(Button::RIGHT_PADDLE_1);
}
BooleanEvent Gamepad::RightPaddle1(EventLoop* loop) const {
@@ -331,15 +331,15 @@ BooleanEvent Gamepad::RightPaddle1(EventLoop* loop) const {
}
bool Gamepad::GetLeftPaddle1Button() const {
return GetRawButton(Button::kLeftPaddle1);
return GetButton(Button::LEFT_PADDLE_1);
}
bool Gamepad::GetLeftPaddle1ButtonPressed() {
return GetRawButtonPressed(Button::kLeftPaddle1);
return GetButtonPressed(Button::LEFT_PADDLE_1);
}
bool Gamepad::GetLeftPaddle1ButtonReleased() {
return GetRawButtonReleased(Button::kLeftPaddle1);
return GetButtonReleased(Button::LEFT_PADDLE_1);
}
BooleanEvent Gamepad::LeftPaddle1(EventLoop* loop) const {
@@ -347,15 +347,15 @@ BooleanEvent Gamepad::LeftPaddle1(EventLoop* loop) const {
}
bool Gamepad::GetRightPaddle2Button() const {
return GetRawButton(Button::kRightPaddle2);
return GetButton(Button::RIGHT_PADDLE_2);
}
bool Gamepad::GetRightPaddle2ButtonPressed() {
return GetRawButtonPressed(Button::kRightPaddle2);
return GetButtonPressed(Button::RIGHT_PADDLE_2);
}
bool Gamepad::GetRightPaddle2ButtonReleased() {
return GetRawButtonReleased(Button::kRightPaddle2);
return GetButtonReleased(Button::RIGHT_PADDLE_2);
}
BooleanEvent Gamepad::RightPaddle2(EventLoop* loop) const {
@@ -363,15 +363,15 @@ BooleanEvent Gamepad::RightPaddle2(EventLoop* loop) const {
}
bool Gamepad::GetLeftPaddle2Button() const {
return GetRawButton(Button::kLeftPaddle2);
return GetButton(Button::LEFT_PADDLE_2);
}
bool Gamepad::GetLeftPaddle2ButtonPressed() {
return GetRawButtonPressed(Button::kLeftPaddle2);
return GetButtonPressed(Button::LEFT_PADDLE_2);
}
bool Gamepad::GetLeftPaddle2ButtonReleased() {
return GetRawButtonReleased(Button::kLeftPaddle2);
return GetButtonReleased(Button::LEFT_PADDLE_2);
}
BooleanEvent Gamepad::LeftPaddle2(EventLoop* loop) const {
@@ -379,15 +379,15 @@ BooleanEvent Gamepad::LeftPaddle2(EventLoop* loop) const {
}
bool Gamepad::GetTouchpadButton() const {
return GetRawButton(Button::kTouchpad);
return GetButton(Button::TOUCHPAD);
}
bool Gamepad::GetTouchpadButtonPressed() {
return GetRawButtonPressed(Button::kTouchpad);
return GetButtonPressed(Button::TOUCHPAD);
}
bool Gamepad::GetTouchpadButtonReleased() {
return GetRawButtonReleased(Button::kTouchpad);
return GetButtonReleased(Button::TOUCHPAD);
}
BooleanEvent Gamepad::Touchpad(EventLoop* loop) const {
@@ -395,15 +395,15 @@ BooleanEvent Gamepad::Touchpad(EventLoop* loop) const {
}
bool Gamepad::GetMisc2Button() const {
return GetRawButton(Button::kMisc2);
return GetButton(Button::MISC_2);
}
bool Gamepad::GetMisc2ButtonPressed() {
return GetRawButtonPressed(Button::kMisc2);
return GetButtonPressed(Button::MISC_2);
}
bool Gamepad::GetMisc2ButtonReleased() {
return GetRawButtonReleased(Button::kMisc2);
return GetButtonReleased(Button::MISC_2);
}
BooleanEvent Gamepad::Misc2(EventLoop* loop) const {
@@ -411,15 +411,15 @@ BooleanEvent Gamepad::Misc2(EventLoop* loop) const {
}
bool Gamepad::GetMisc3Button() const {
return GetRawButton(Button::kMisc3);
return GetButton(Button::MISC_3);
}
bool Gamepad::GetMisc3ButtonPressed() {
return GetRawButtonPressed(Button::kMisc3);
return GetButtonPressed(Button::MISC_3);
}
bool Gamepad::GetMisc3ButtonReleased() {
return GetRawButtonReleased(Button::kMisc3);
return GetButtonReleased(Button::MISC_3);
}
BooleanEvent Gamepad::Misc3(EventLoop* loop) const {
@@ -427,15 +427,15 @@ BooleanEvent Gamepad::Misc3(EventLoop* loop) const {
}
bool Gamepad::GetMisc4Button() const {
return GetRawButton(Button::kMisc4);
return GetButton(Button::MISC_4);
}
bool Gamepad::GetMisc4ButtonPressed() {
return GetRawButtonPressed(Button::kMisc4);
return GetButtonPressed(Button::MISC_4);
}
bool Gamepad::GetMisc4ButtonReleased() {
return GetRawButtonReleased(Button::kMisc4);
return GetButtonReleased(Button::MISC_4);
}
BooleanEvent Gamepad::Misc4(EventLoop* loop) const {
@@ -443,15 +443,15 @@ BooleanEvent Gamepad::Misc4(EventLoop* loop) const {
}
bool Gamepad::GetMisc5Button() const {
return GetRawButton(Button::kMisc5);
return GetButton(Button::MISC_5);
}
bool Gamepad::GetMisc5ButtonPressed() {
return GetRawButtonPressed(Button::kMisc5);
return GetButtonPressed(Button::MISC_5);
}
bool Gamepad::GetMisc5ButtonReleased() {
return GetRawButtonReleased(Button::kMisc5);
return GetButtonReleased(Button::MISC_5);
}
BooleanEvent Gamepad::Misc5(EventLoop* loop) const {
@@ -459,27 +459,60 @@ BooleanEvent Gamepad::Misc5(EventLoop* loop) const {
}
bool Gamepad::GetMisc6Button() const {
return GetRawButton(Button::kMisc6);
return GetButton(Button::MISC_6);
}
bool Gamepad::GetMisc6ButtonPressed() {
return GetRawButtonPressed(Button::kMisc6);
return GetButtonPressed(Button::MISC_6);
}
bool Gamepad::GetMisc6ButtonReleased() {
return GetRawButtonReleased(Button::kMisc6);
return GetButtonReleased(Button::MISC_6);
}
BooleanEvent Gamepad::Misc6(EventLoop* loop) const {
return BooleanEvent(loop, [this]() { return this->GetMisc6Button(); });
}
double Gamepad::GetAxisForSendable(int axis) const {
return DriverStation::GetStickAxisIfAvailable(GetPort(), axis).value_or(0.0);
bool Gamepad::GetButton(Button button) const {
return GetRawButton(static_cast<int>(button));
}
bool Gamepad::GetButtonForSendable(int button) const {
return DriverStation::GetStickButtonIfAvailable(GetPort(), button)
bool Gamepad::GetButtonPressed(Button button) {
return GetRawButtonPressed(static_cast<int>(button));
}
bool Gamepad::GetButtonReleased(Button button) {
return GetRawButtonReleased(static_cast<int>(button));
}
BooleanEvent Gamepad::ButtonEvent(Button button, EventLoop* loop) const {
return GenericHID::Button(static_cast<int>(button), loop);
}
double Gamepad::GetAxis(Axis axis) const {
return GetRawAxis(static_cast<int>(axis));
}
BooleanEvent Gamepad::AxisLessThan(Axis axis, double threshold,
EventLoop* loop) const {
return GenericHID::AxisLessThan(static_cast<int>(axis), threshold, loop);
}
BooleanEvent Gamepad::AxisGreaterThan(Axis axis, double threshold,
EventLoop* loop) const {
return GenericHID::AxisGreaterThan(static_cast<int>(axis), threshold, loop);
}
double Gamepad::GetAxisForSendable(Axis axis) const {
return DriverStation::GetStickAxisIfAvailable(GetPort(),
static_cast<int>(axis))
.value_or(0.0);
}
bool Gamepad::GetButtonForSendable(Button button) const {
return DriverStation::GetStickButtonIfAvailable(GetPort(),
static_cast<int>(button))
.value_or(false);
}
@@ -488,93 +521,91 @@ void Gamepad::InitSendable(wpi::util::SendableBuilder& builder) {
builder.PublishConstString("ControllerType", "Gamepad");
builder.AddDoubleProperty(
"LeftTrigger Axis",
[this] { return GetAxisForSendable(Axis::kLeftTrigger); }, nullptr);
[this] { return GetAxisForSendable(Axis::LEFT_TRIGGER); }, nullptr);
builder.AddDoubleProperty(
"RightTrigger Axis",
[this] { return GetAxisForSendable(Axis::kRightTrigger); }, nullptr);
[this] { return GetAxisForSendable(Axis::RIGHT_TRIGGER); }, nullptr);
builder.AddDoubleProperty(
"LeftX", [this] { return GetAxisForSendable(Axis::kLeftX); }, nullptr);
"LeftX", [this] { return GetAxisForSendable(Axis::LEFT_X); }, nullptr);
builder.AddDoubleProperty(
"LeftY", [this] { return GetAxisForSendable(Axis::kLeftY); }, nullptr);
"LeftY", [this] { return GetAxisForSendable(Axis::LEFT_Y); }, nullptr);
builder.AddDoubleProperty(
"RightX", [this] { return GetAxisForSendable(Axis::kRightX); }, nullptr);
"RightX", [this] { return GetAxisForSendable(Axis::RIGHT_X); }, nullptr);
builder.AddDoubleProperty(
"RightY", [this] { return GetAxisForSendable(Axis::kRightY); }, nullptr);
"RightY", [this] { return GetAxisForSendable(Axis::RIGHT_Y); }, nullptr);
builder.AddBooleanProperty(
"SouthFace", [this] { return GetButtonForSendable(Button::kSouthFace); },
"SouthFace", [this] { return GetButtonForSendable(Button::SOUTH_FACE); },
nullptr);
builder.AddBooleanProperty(
"EastFace", [this] { return GetButtonForSendable(Button::kEastFace); },
"EastFace", [this] { return GetButtonForSendable(Button::EAST_FACE); },
nullptr);
builder.AddBooleanProperty(
"WestFace", [this] { return GetButtonForSendable(Button::kWestFace); },
"WestFace", [this] { return GetButtonForSendable(Button::WEST_FACE); },
nullptr);
builder.AddBooleanProperty(
"NorthFace", [this] { return GetButtonForSendable(Button::kNorthFace); },
"NorthFace", [this] { return GetButtonForSendable(Button::NORTH_FACE); },
nullptr);
builder.AddBooleanProperty(
"Back", [this] { return GetButtonForSendable(Button::kBack); }, nullptr);
"Back", [this] { return GetButtonForSendable(Button::BACK); }, nullptr);
builder.AddBooleanProperty(
"Guide", [this] { return GetButtonForSendable(Button::kGuide); },
nullptr);
"Guide", [this] { return GetButtonForSendable(Button::GUIDE); }, nullptr);
builder.AddBooleanProperty(
"Start", [this] { return GetButtonForSendable(Button::kStart); },
nullptr);
"Start", [this] { return GetButtonForSendable(Button::START); }, nullptr);
builder.AddBooleanProperty(
"LeftStick", [this] { return GetButtonForSendable(Button::kLeftStick); },
"LeftStick", [this] { return GetButtonForSendable(Button::LEFT_STICK); },
nullptr);
builder.AddBooleanProperty(
"RightStick",
[this] { return GetButtonForSendable(Button::kRightStick); }, nullptr);
[this] { return GetButtonForSendable(Button::RIGHT_STICK); }, nullptr);
builder.AddBooleanProperty(
"LeftBumper",
[this] { return GetButtonForSendable(Button::kLeftBumper); }, nullptr);
[this] { return GetButtonForSendable(Button::LEFT_BUMPER); }, nullptr);
builder.AddBooleanProperty(
"RightBumper",
[this] { return GetButtonForSendable(Button::kRightBumper); }, nullptr);
[this] { return GetButtonForSendable(Button::RIGHT_BUMPER); }, nullptr);
builder.AddBooleanProperty(
"DpadUp", [this] { return GetButtonForSendable(Button::kDpadUp); },
"DpadUp", [this] { return GetButtonForSendable(Button::DPAD_UP); },
nullptr);
builder.AddBooleanProperty(
"DpadDown", [this] { return GetButtonForSendable(Button::kDpadDown); },
"DpadDown", [this] { return GetButtonForSendable(Button::DPAD_DOWN); },
nullptr);
builder.AddBooleanProperty(
"DpadLeft", [this] { return GetButtonForSendable(Button::kDpadLeft); },
"DpadLeft", [this] { return GetButtonForSendable(Button::DPAD_LEFT); },
nullptr);
builder.AddBooleanProperty(
"DpadRight", [this] { return GetButtonForSendable(Button::kDpadRight); },
"DpadRight", [this] { return GetButtonForSendable(Button::DPAD_RIGHT); },
nullptr);
builder.AddBooleanProperty(
"Misc1", [this] { return GetButtonForSendable(Button::kMisc1); },
"Misc1", [this] { return GetButtonForSendable(Button::MISC_1); },
nullptr);
builder.AddBooleanProperty(
"RightPaddle1",
[this] { return GetButtonForSendable(Button::kRightPaddle1); }, nullptr);
[this] { return GetButtonForSendable(Button::RIGHT_PADDLE_1); }, nullptr);
builder.AddBooleanProperty(
"LeftPaddle1",
[this] { return GetButtonForSendable(Button::kLeftPaddle1); }, nullptr);
[this] { return GetButtonForSendable(Button::LEFT_PADDLE_1); }, nullptr);
builder.AddBooleanProperty(
"RightPaddle2",
[this] { return GetButtonForSendable(Button::kRightPaddle2); }, nullptr);
[this] { return GetButtonForSendable(Button::RIGHT_PADDLE_2); }, nullptr);
builder.AddBooleanProperty(
"LeftPaddle2",
[this] { return GetButtonForSendable(Button::kLeftPaddle2); }, nullptr);
[this] { return GetButtonForSendable(Button::LEFT_PADDLE_2); }, nullptr);
builder.AddBooleanProperty(
"Touchpad", [this] { return GetButtonForSendable(Button::kTouchpad); },
"Touchpad", [this] { return GetButtonForSendable(Button::TOUCHPAD); },
nullptr);
builder.AddBooleanProperty(
"Misc2", [this] { return GetButtonForSendable(Button::kMisc2); },
"Misc2", [this] { return GetButtonForSendable(Button::MISC_2); },
nullptr);
builder.AddBooleanProperty(
"Misc3", [this] { return GetButtonForSendable(Button::kMisc3); },
"Misc3", [this] { return GetButtonForSendable(Button::MISC_3); },
nullptr);
builder.AddBooleanProperty(
"Misc4", [this] { return GetButtonForSendable(Button::kMisc4); },
"Misc4", [this] { return GetButtonForSendable(Button::MISC_4); },
nullptr);
builder.AddBooleanProperty(
"Misc5", [this] { return GetButtonForSendable(Button::kMisc5); },
"Misc5", [this] { return GetButtonForSendable(Button::MISC_5); },
nullptr);
builder.AddBooleanProperty(
"Misc6", [this] { return GetButtonForSendable(Button::kMisc6); },
"Misc6", [this] { return GetButtonForSendable(Button::MISC_6); },
nullptr);
}

View File

@@ -163,13 +163,13 @@ void GenericHID::SetRumble(RumbleType type, double value) {
value = std::clamp(value, 0.0, 1.0);
double rumbleValue = value * 65535;
if (type == kLeftRumble) {
if (type == RumbleType::LEFT_RUMBLE) {
m_leftRumble = rumbleValue;
} else if (type == kRightRumble) {
} else if (type == RumbleType::RIGHT_RUMBLE) {
m_rightRumble = rumbleValue;
} else if (type == kLeftTriggerRumble) {
} else if (type == RumbleType::LEFT_TRIGGER_RUMBLE) {
m_leftTriggerRumble = rumbleValue;
} else if (type == kRightTriggerRumble) {
} else if (type == RumbleType::RIGHT_TRIGGER_RUMBLE) {
m_rightTriggerRumble = rumbleValue;
}

View File

@@ -9,7 +9,7 @@
using namespace wpi;
using namespace wpi::sim;
GamepadSim::GamepadSim(const Gamepad& joystick) : GenericHIDSim{joystick} {
GamepadSim::GamepadSim(const wpi::Gamepad& joystick) : GenericHIDSim{joystick} {
SetAxesMaximumIndex(6);
SetButtonsMaximumIndex(26);
SetPOVsMaximumIndex(1);
@@ -21,130 +21,138 @@ GamepadSim::GamepadSim(int port) : GenericHIDSim{port} {
SetPOVsMaximumIndex(1);
}
void GamepadSim::SetButton(wpi::Gamepad::Button button, bool value) {
SetRawButton(static_cast<int>(button), value);
}
void GamepadSim::SetAxis(wpi::Gamepad::Axis axis, double value) {
SetRawAxis(static_cast<int>(axis), value);
}
void GamepadSim::SetLeftX(double value) {
SetRawAxis(Gamepad::Axis::kLeftX, value);
SetAxis(Gamepad::Axis::LEFT_X, value);
}
void GamepadSim::SetLeftY(double value) {
SetRawAxis(Gamepad::Axis::kLeftY, value);
SetAxis(Gamepad::Axis::LEFT_Y, value);
}
void GamepadSim::SetRightX(double value) {
SetRawAxis(Gamepad::Axis::kRightX, value);
SetAxis(Gamepad::Axis::RIGHT_X, value);
}
void GamepadSim::SetRightY(double value) {
SetRawAxis(Gamepad::Axis::kRightY, value);
SetAxis(Gamepad::Axis::RIGHT_Y, value);
}
void GamepadSim::SetLeftTriggerAxis(double value) {
SetRawAxis(Gamepad::Axis::kLeftTrigger, value);
SetAxis(Gamepad::Axis::LEFT_TRIGGER, value);
}
void GamepadSim::SetRightTriggerAxis(double value) {
SetRawAxis(Gamepad::Axis::kRightTrigger, value);
SetAxis(Gamepad::Axis::RIGHT_TRIGGER, value);
}
void GamepadSim::SetSouthFaceButton(bool value) {
SetRawButton(Gamepad::Button::kSouthFace, value);
SetButton(Gamepad::Button::SOUTH_FACE, value);
}
void GamepadSim::SetEastFaceButton(bool value) {
SetRawButton(Gamepad::Button::kEastFace, value);
SetButton(Gamepad::Button::EAST_FACE, value);
}
void GamepadSim::SetWestFaceButton(bool value) {
SetRawButton(Gamepad::Button::kWestFace, value);
SetButton(Gamepad::Button::WEST_FACE, value);
}
void GamepadSim::SetNorthFaceButton(bool value) {
SetRawButton(Gamepad::Button::kNorthFace, value);
SetButton(Gamepad::Button::NORTH_FACE, value);
}
void GamepadSim::SetBackButton(bool value) {
SetRawButton(Gamepad::Button::kBack, value);
SetButton(Gamepad::Button::BACK, value);
}
void GamepadSim::SetGuideButton(bool value) {
SetRawButton(Gamepad::Button::kGuide, value);
SetButton(Gamepad::Button::GUIDE, value);
}
void GamepadSim::SetStartButton(bool value) {
SetRawButton(Gamepad::Button::kStart, value);
SetButton(Gamepad::Button::START, value);
}
void GamepadSim::SetLeftStickButton(bool value) {
SetRawButton(Gamepad::Button::kLeftStick, value);
SetButton(Gamepad::Button::LEFT_STICK, value);
}
void GamepadSim::SetRightStickButton(bool value) {
SetRawButton(Gamepad::Button::kRightStick, value);
SetButton(Gamepad::Button::RIGHT_STICK, value);
}
void GamepadSim::SetLeftBumperButton(bool value) {
SetRawButton(Gamepad::Button::kLeftBumper, value);
SetButton(Gamepad::Button::LEFT_BUMPER, value);
}
void GamepadSim::SetRightBumperButton(bool value) {
SetRawButton(Gamepad::Button::kRightBumper, value);
SetButton(Gamepad::Button::RIGHT_BUMPER, value);
}
void GamepadSim::SetDpadUpButton(bool value) {
SetRawButton(Gamepad::Button::kDpadUp, value);
SetButton(Gamepad::Button::DPAD_UP, value);
}
void GamepadSim::SetDpadDownButton(bool value) {
SetRawButton(Gamepad::Button::kDpadDown, value);
SetButton(Gamepad::Button::DPAD_DOWN, value);
}
void GamepadSim::SetDpadLeftButton(bool value) {
SetRawButton(Gamepad::Button::kDpadLeft, value);
SetButton(Gamepad::Button::DPAD_LEFT, value);
}
void GamepadSim::SetDpadRightButton(bool value) {
SetRawButton(Gamepad::Button::kDpadRight, value);
SetButton(Gamepad::Button::DPAD_RIGHT, value);
}
void GamepadSim::SetMisc1Button(bool value) {
SetRawButton(Gamepad::Button::kMisc1, value);
SetButton(Gamepad::Button::MISC_1, value);
}
void GamepadSim::SetRightPaddle1Button(bool value) {
SetRawButton(Gamepad::Button::kRightPaddle1, value);
SetButton(Gamepad::Button::RIGHT_PADDLE_1, value);
}
void GamepadSim::SetLeftPaddle1Button(bool value) {
SetRawButton(Gamepad::Button::kLeftPaddle1, value);
SetButton(Gamepad::Button::LEFT_PADDLE_1, value);
}
void GamepadSim::SetRightPaddle2Button(bool value) {
SetRawButton(Gamepad::Button::kRightPaddle2, value);
SetButton(Gamepad::Button::RIGHT_PADDLE_2, value);
}
void GamepadSim::SetLeftPaddle2Button(bool value) {
SetRawButton(Gamepad::Button::kLeftPaddle2, value);
SetButton(Gamepad::Button::LEFT_PADDLE_2, value);
}
void GamepadSim::SetTouchpadButton(bool value) {
SetRawButton(Gamepad::Button::kTouchpad, value);
SetButton(Gamepad::Button::TOUCHPAD, value);
}
void GamepadSim::SetMisc2Button(bool value) {
SetRawButton(Gamepad::Button::kMisc2, value);
SetButton(Gamepad::Button::MISC_2, value);
}
void GamepadSim::SetMisc3Button(bool value) {
SetRawButton(Gamepad::Button::kMisc3, value);
SetButton(Gamepad::Button::MISC_3, value);
}
void GamepadSim::SetMisc4Button(bool value) {
SetRawButton(Gamepad::Button::kMisc4, value);
SetButton(Gamepad::Button::MISC_4, value);
}
void GamepadSim::SetMisc5Button(bool value) {
SetRawButton(Gamepad::Button::kMisc5, value);
SetButton(Gamepad::Button::MISC_5, value);
}
void GamepadSim::SetMisc6Button(bool value) {
SetRawButton(Gamepad::Button::kMisc6, value);
SetButton(Gamepad::Button::MISC_6, value);
}

View File

@@ -61,12 +61,13 @@ void GenericHIDSim::SetButtonsAvailable(uint64_t count) {
}
void GenericHIDSim::SetGamepadType(GenericHID::HIDType type) {
DriverStationSim::SetJoystickGamepadType(m_port, type);
DriverStationSim::SetJoystickGamepadType(m_port, static_cast<int>(type));
}
void GenericHIDSim::SetSupportedOutputs(
GenericHID::SupportedOutputs supportedOutputs) {
DriverStationSim::SetJoystickSupportedOutputs(m_port, supportedOutputs);
DriverStationSim::SetJoystickSupportedOutputs(
m_port, static_cast<int>(supportedOutputs));
}
void GenericHIDSim::SetName(const char* name) {
@@ -80,16 +81,16 @@ int32_t GenericHIDSim::GetLeds() {
double GenericHIDSim::GetRumble(GenericHID::RumbleType type) {
int intType = 0;
switch (type) {
case GenericHID::kLeftRumble:
case GenericHID::RumbleType::LEFT_RUMBLE:
intType = 0;
break;
case GenericHID::kRightRumble:
case GenericHID::RumbleType::RIGHT_RUMBLE:
intType = 1;
break;
case GenericHID::kLeftTriggerRumble:
case GenericHID::RumbleType::LEFT_TRIGGER_RUMBLE:
intType = 2;
break;
case GenericHID::kRightTriggerRumble:
case GenericHID::RumbleType::RIGHT_TRIGGER_RUMBLE:
intType = 3;
break;
default:

View File

@@ -26,6 +26,78 @@ class Gamepad : public GenericHID,
public wpi::util::Sendable,
public wpi::util::SendableHelper<Gamepad> {
public:
/** Represents a digital button on an Gamepad. */
enum class Button {
/// South Face button.
SOUTH_FACE = 0,
/// East Face button.
EAST_FACE = 1,
/// West Face button.
WEST_FACE = 2,
/// North Face button.
NORTH_FACE = 3,
/// Back button.
BACK = 4,
/// Guide button.
GUIDE = 5,
/// Start button.
START = 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,
/// D-pad up button.
DPAD_UP = 11,
/// D-pad down button.
DPAD_DOWN = 12,
/// D-pad left button.
DPAD_LEFT = 13,
/// D-pad right button.
DPAD_RIGHT = 14,
/// Miscellaneous 1 button.
MISC_1 = 15,
/// Right Paddle 1 button.
RIGHT_PADDLE_1 = 16,
/// Left Paddle 1 button.
LEFT_PADDLE_1 = 17,
/// Right Paddle 2 button.
RIGHT_PADDLE_2 = 18,
/// Left Paddle 2 button.
LEFT_PADDLE_2 = 19,
/// Touchpad button.
TOUCHPAD = 20,
/// Miscellaneous 2 button.
MISC_2 = 21,
/// Miscellaneous 3 button.
MISC_3 = 22,
/// Miscellaneous 4 button.
MISC_4 = 23,
/// Miscellaneous 5 button.
MISC_5 = 24,
/// Miscellaneous 6 button.
MISC_6 = 25,
};
/** Represents an axis on an Gamepad. */
enum class Axis {
/// Left X axis.
LEFT_X = 0,
/// Left Y axis.
LEFT_Y = 1,
/// Right X axis.
RIGHT_X = 2,
/// Right Y axis.
RIGHT_Y = 3,
/// Left trigger.
LEFT_TRIGGER = 4,
/// Right trigger.
RIGHT_TRIGGER = 5,
};
/**
* Construct an instance of a controller.
*
@@ -935,83 +1007,89 @@ class Gamepad : public GenericHID,
*/
BooleanEvent Misc6(EventLoop* loop) const;
/** Represents a digital button on an Gamepad. */
struct Button {
/// South Face button.
static constexpr int kSouthFace = 0;
/// East Face button.
static constexpr int kEastFace = 1;
/// West Face button.
static constexpr int kWestFace = 2;
/// North Face button.
static constexpr int kNorthFace = 3;
/// Back button.
static constexpr int kBack = 4;
/// Guide button.
static constexpr int kGuide = 5;
/// Start button.
static constexpr int kStart = 6;
/// Left stick button.
static constexpr int kLeftStick = 7;
/// Right stick button.
static constexpr int kRightStick = 8;
/// right bumper button.
static constexpr int kLeftBumper = 9;
/// right bumper button.
static constexpr int kRightBumper = 10;
/// D-pad up button.
static constexpr int kDpadUp = 11;
/// D-pad down button.
static constexpr int kDpadDown = 12;
/// D-pad left button.
static constexpr int kDpadLeft = 13;
/// D-pad right button.
static constexpr int kDpadRight = 14;
/// Miscellaneous 1 button.
static constexpr int kMisc1 = 15;
/// Right Paddle 1 button.
static constexpr int kRightPaddle1 = 16;
/// Left Paddle 1 button.
static constexpr int kLeftPaddle1 = 17;
/// Right Paddle 2 button.
static constexpr int kRightPaddle2 = 18;
/// Left Paddle 2 button.
static constexpr int kLeftPaddle2 = 19;
/// Touchpad button.
static constexpr int kTouchpad = 20;
/// Miscellaneous 2 button.
static constexpr int kMisc2 = 21;
/// Miscellaneous 3 button.
static constexpr int kMisc3 = 22;
/// Miscellaneous 4 button.
static constexpr int kMisc4 = 23;
/// Miscellaneous 5 button.
static constexpr int kMisc5 = 24;
/// Miscellaneous 6 button.
static constexpr int kMisc6 = 25;
};
/**
* Get the button value.
*
* This method returns true if the button is being held down at the time
* that this method is being called.
*
* @param button The button
* @return The state of the button.
*/
bool GetButton(Button button) const;
/** Represents an axis on an Gamepad. */
struct Axis {
/// Left X axis.
static constexpr int kLeftX = 0;
/// Left Y axis.
static constexpr int kLeftY = 1;
/// Right X axis.
static constexpr int kRightX = 2;
/// Right Y axis.
static constexpr int kRightY = 3;
/// Left trigger.
static constexpr int kLeftTrigger = 4;
/// Right trigger.
static constexpr int kRightTrigger = 5;
};
/**
* Whether the button was pressed since the last check.
*
* This method returns true if the button went from not pressed to held down
* since the last time this method was called. This is useful if you only
* want to call a function once when you press the button.
*
* @param button The button
* @return Whether the button was pressed since the last check.
*/
bool GetButtonPressed(Button button);
/**
* Whether the button was released since the last check.
*
* This method returns true if the button went from held down to not pressed
* since the last time this method was called. This is useful if you only
* want to call a function once when you release the button.
*
* @param button The button
* @return Whether the button was released since the last check.
*/
bool GetButtonReleased(Button button);
/**
* 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.
*/
BooleanEvent ButtonEvent(Button button, EventLoop* loop) const;
/**
* Get the value of the axis.
*
* @param axis The axis to read
* @return The value of the axis.
*/
double GetAxis(Axis axis) const;
/**
* Constructs an event instance that is true when the axis value is less than
* threshold
*
* @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.
* @return an event instance that is true when the axis value is less than the
* provided threshold.
*/
BooleanEvent AxisLessThan(Axis axis, double threshold, EventLoop* loop) const;
/**
* Constructs an event instance that is true when the axis value is greater
* than threshold
*
* @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 event to.
* @return an event instance that is true when the axis value is greater than
* the provided threshold.
*/
BooleanEvent AxisGreaterThan(Axis axis, double threshold,
EventLoop* loop) const;
void InitSendable(wpi::util::SendableBuilder& builder) override;
private:
double GetAxisForSendable(int axis) const;
bool GetButtonForSendable(int button) const;
double GetAxisForSendable(Axis axis) const;
bool GetButtonForSendable(Button button) const;
};
} // namespace wpi

View File

@@ -28,61 +28,61 @@ class GenericHID {
/**
* Represents a rumble output on the Joystick.
*/
enum RumbleType {
enum class RumbleType {
/// Left rumble motor.
kLeftRumble,
LEFT_RUMBLE,
/// Right rumble motor.
kRightRumble,
RIGHT_RUMBLE,
/// Left trigger rumble motor.
kLeftTriggerRumble,
LEFT_TRIGGER_RUMBLE,
/// Right trigger rumble motor.
kRightTriggerRumble,
RIGHT_TRIGGER_RUMBLE,
};
/**
* Represents the various outputs that a HID may support.
*/
enum SupportedOutputs {
enum class SupportedOutputs : int {
/// No outputs supported.
kNone = 0x0,
NONE = 0x0,
/// Mono LED support.
kMonoLed = 0x1,
MONO_LED = 0x1,
/// RGB LED support.
kRgbLed = 0x2,
RGB_LED = 0x2,
/// Player LED support.
kPlayerLed = 0x4,
PLAYER_LED = 0x4,
/// Rumble support.
kRumble = 0x8,
RUMBLE = 0x8,
/// Trigger rumble support.
kTriggerRumble = 0x10,
TRIGGER_RUMBLE = 0x10,
};
/**
* USB HID interface type.
*/
enum HIDType {
enum class HIDType {
/// Unknown.
kUnknown = 0,
UNKNOWN = 0,
/// Standard HID device.
kStandard,
STANDARD,
/// Xbox 360 controller.
kXbox360,
XBOX_360,
/// Xbox One controller.
kXboxOne,
XBOX_ONE,
/// PS3 controller.
kPS3,
PS3,
/// PS4 controller.
kPS4,
PS4,
/// PS5 controller.
kPS5,
PS5,
/// Nintendo Switch Pro controller.
kSwitchPro,
SWITCH_PRO,
/// Nintendo Switch Joycon Left controller.
kSwitchJoyconLeft,
SWITCH_JOYCON_LEFT,
/// Nintendo Switch Joycon Right controller.
kSwitchJoyconRight,
SWITCH_JOYCON_RIGHT,
/// Nintendo Switch Joycon controller pair.
kSwitchJoyconPair
SWITCH_JOYCON_PAIR
};
explicit GenericHID(int port);
@@ -334,7 +334,7 @@ class GenericHID {
*
* @return the supported outputs of the HID.
*/
GenericHID::SupportedOutputs GetSupportedOutputs() const;
SupportedOutputs GetSupportedOutputs() const;
/**
* Get the name of the HID.
@@ -396,4 +396,16 @@ class GenericHID {
uint16_t m_rightTriggerRumble = 0;
};
inline GenericHID::SupportedOutputs operator|(GenericHID::SupportedOutputs A,
GenericHID::SupportedOutputs B) {
return static_cast<GenericHID::SupportedOutputs>(static_cast<int>(A) |
static_cast<int>(B));
}
inline GenericHID::SupportedOutputs& operator|=(
GenericHID::SupportedOutputs& A, GenericHID::SupportedOutputs B) {
A = A | B;
return A;
}
} // namespace wpi

View File

@@ -4,13 +4,10 @@
#pragma once
#include "wpi/driverstation/Gamepad.hpp"
#include "wpi/simulation/GenericHIDSim.hpp"
namespace wpi {
class Gamepad;
namespace sim {
namespace wpi::sim {
/**
* Class to control a simulated Gamepad controller.
@@ -22,7 +19,7 @@ class GamepadSim : public GenericHIDSim {
*
* @param joystick controller to simulate
*/
explicit GamepadSim(const Gamepad& joystick);
explicit GamepadSim(const wpi::Gamepad& joystick);
/**
* Constructs from a joystick port number.
@@ -31,6 +28,22 @@ class GamepadSim : public GenericHIDSim {
*/
explicit GamepadSim(int port);
/**
* Set the value of a given button.
*
* @param button the button to set
* @param value the new value
*/
void SetButton(wpi::Gamepad::Button button, bool value);
/**
* Set the value of a given axis.
*
* @param axis the axis to set
* @param value the new value
*/
void SetAxis(wpi::Gamepad::Axis axis, double value);
/**
* Change the left X value of the controller's joystick.
*
@@ -256,5 +269,4 @@ class GamepadSim : public GenericHIDSim {
void SetMisc6Button(bool value);
};
} // namespace sim
} // namespace wpi
} // namespace wpi::sim

View File

@@ -2,6 +2,9 @@ classes:
wpi::Gamepad:
ignored_bases:
- wpi::util::SendableHelper<Gamepad>
enums:
Button:
Axis:
methods:
Gamepad:
GetLeftX:
@@ -122,40 +125,12 @@ classes:
GetMisc6ButtonPressed:
GetMisc6ButtonReleased:
Misc6:
GetButton:
GetButtonPressed:
GetButtonReleased:
ButtonEvent:
rename: button
GetAxis:
AxisLessThan:
AxisGreaterThan:
InitSendable:
wpi::Gamepad::Button:
attributes:
kSouthFace:
kEastFace:
kWestFace:
kNorthFace:
kBack:
kGuide:
kStart:
kLeftStick:
kRightStick:
kLeftBumper:
kRightBumper:
kDpadUp:
kDpadDown:
kDpadLeft:
kDpadRight:
kMisc1:
kRightPaddle1:
kLeftPaddle1:
kRightPaddle2:
kLeftPaddle2:
kTouchpad:
kMisc2:
kMisc3:
kMisc4:
kMisc5:
kMisc6:
wpi::Gamepad::Axis:
attributes:
kLeftX:
kLeftY:
kRightX:
kRightY:
kLeftTrigger:
kRightTrigger:

View File

@@ -7,6 +7,7 @@ classes:
enums:
RumbleType:
SupportedOutputs:
arithmetic: true
HIDType:
methods:
GenericHID:
@@ -46,7 +47,6 @@ classes:
GetButtonsAvailable:
GetTouchpadFingerAvailable:
GetTouchpadFinger:
inline_code: |
cls_GenericHID
.def("__repr__", [](py::handle self) {

View File

@@ -7,8 +7,10 @@ classes:
methods:
GamepadSim:
overloads:
const Gamepad&:
const wpi::Gamepad&:
int:
SetButton:
SetAxis:
SetLeftX:
SetLeftY:
SetRightX:

View File

@@ -17,18 +17,18 @@ TEST(GenericHIDTest, RumbleRange) {
for (int i = 0; i <= 100; i++) {
double rumbleValue = i / 100.0;
hid.SetRumble(RumbleType::kLeftRumble, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::kLeftRumble), kEpsilon);
hid.SetRumble(RumbleType::LEFT_RUMBLE, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::LEFT_RUMBLE), kEpsilon);
hid.SetRumble(RumbleType::kRightRumble, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::kRightRumble), kEpsilon);
hid.SetRumble(RumbleType::RIGHT_RUMBLE, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::RIGHT_RUMBLE), kEpsilon);
hid.SetRumble(RumbleType::kLeftTriggerRumble, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::kLeftTriggerRumble),
hid.SetRumble(RumbleType::LEFT_TRIGGER_RUMBLE, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::LEFT_TRIGGER_RUMBLE),
kEpsilon);
hid.SetRumble(RumbleType::kRightTriggerRumble, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::kRightTriggerRumble),
hid.SetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE, rumbleValue);
EXPECT_NEAR(rumbleValue, sim.GetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE),
kEpsilon);
}
}
@@ -38,44 +38,44 @@ TEST(GenericHIDTest, RumbleTypes) {
sim::GenericHIDSim sim{0};
// Make sure all are off
hid.SetRumble(RumbleType::kLeftRumble, 0);
hid.SetRumble(RumbleType::kLeftTriggerRumble, 0);
hid.SetRumble(RumbleType::kRightRumble, 0);
hid.SetRumble(RumbleType::kRightTriggerRumble, 0);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftTriggerRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightTriggerRumble), kEpsilon);
hid.SetRumble(RumbleType::LEFT_RUMBLE, 0);
hid.SetRumble(RumbleType::LEFT_TRIGGER_RUMBLE, 0);
hid.SetRumble(RumbleType::RIGHT_RUMBLE, 0);
hid.SetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE, 0);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_TRIGGER_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE), kEpsilon);
// test left only
hid.SetRumble(RumbleType::kLeftRumble, 1);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::kLeftRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftTriggerRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightTriggerRumble), kEpsilon);
hid.SetRumble(RumbleType::kLeftRumble, 0);
hid.SetRumble(RumbleType::LEFT_RUMBLE, 1);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::LEFT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_TRIGGER_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.SetRumble(RumbleType::LEFT_RUMBLE, 0);
// test right only
hid.SetRumble(RumbleType::kRightRumble, 1);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftRumble), kEpsilon);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::kRightRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftTriggerRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightTriggerRumble), kEpsilon);
hid.SetRumble(RumbleType::kRightRumble, 0);
hid.SetRumble(RumbleType::RIGHT_RUMBLE, 1);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_RUMBLE), kEpsilon);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::RIGHT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_TRIGGER_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.SetRumble(RumbleType::RIGHT_RUMBLE, 0);
// test left trigger only
hid.SetRumble(RumbleType::kLeftTriggerRumble, 1);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightRumble), kEpsilon);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::kLeftTriggerRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightTriggerRumble), kEpsilon);
hid.SetRumble(RumbleType::kLeftTriggerRumble, 0);
hid.SetRumble(RumbleType::LEFT_TRIGGER_RUMBLE, 1);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_RUMBLE), kEpsilon);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::LEFT_TRIGGER_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.SetRumble(RumbleType::LEFT_TRIGGER_RUMBLE, 0);
// test right trigger only
hid.SetRumble(RumbleType::kRightTriggerRumble, 1);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kRightRumble), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::kLeftTriggerRumble), kEpsilon);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::kRightTriggerRumble), kEpsilon);
hid.SetRumble(RumbleType::kRightTriggerRumble, 0);
hid.SetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE, 1);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::RIGHT_RUMBLE), kEpsilon);
EXPECT_NEAR(0, sim.GetRumble(RumbleType::LEFT_TRIGGER_RUMBLE), kEpsilon);
EXPECT_NEAR(1, sim.GetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.SetRumble(RumbleType::RIGHT_TRIGGER_RUMBLE, 0);
}

View File

@@ -8,7 +8,7 @@
#include "commands/GrabHatch.hpp"
#include "commands/HalveDriveVelocity.hpp"
#include "commands/ReleaseHatch.hpp"
#include "wpi/commands2/button/JoystickButton.hpp"
#include "wpi/commands2/button/GamepadButton.hpp"
#include "wpi/smartdashboard/SmartDashboard.hpp"
RobotContainer::RobotContainer() {
@@ -40,15 +40,14 @@ void RobotContainer::ConfigureButtonBindings() {
// the scheduler thus, no memory leaks!
// Grab the hatch when the 'South Face' button is pressed.
wpi::cmd::JoystickButton(&m_driverController,
wpi::Gamepad::Button::kSouthFace)
wpi::cmd::GamepadButton(&m_driverController, wpi::Gamepad::Button::SOUTH_FACE)
.OnTrue(GrabHatch(&m_hatch).ToPtr());
// Release the hatch when the 'East Face' button is pressed.
wpi::cmd::JoystickButton(&m_driverController, wpi::Gamepad::Button::kEastFace)
wpi::cmd::GamepadButton(&m_driverController, wpi::Gamepad::Button::EAST_FACE)
.OnTrue(ReleaseHatch(&m_hatch).ToPtr());
// While holding the bumper button, drive at half velocity
wpi::cmd::JoystickButton(&m_driverController,
wpi::Gamepad::Button::kRightBumper)
wpi::cmd::GamepadButton(&m_driverController,
wpi::Gamepad::Button::RIGHT_BUMPER)
.WhileTrue(HalveDriveVelocity(&m_drive).ToPtr());
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
package org.wpilib.driverstation;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import org.wpilib.driverstation.DriverStation.POVDirection;
@@ -24,39 +25,70 @@ public class GenericHID {
/** Represents a rumble output on the Joystick. */
public enum RumbleType {
/** Left rumble motor. */
kLeftRumble,
LEFT_RUMBLE,
/** Right rumble motor. */
kRightRumble,
RIGHT_RUMBLE,
/** Left trigger rumble motor. */
kLeftTriggerRumble,
LEFT_TRIGGER_RUMBLE,
/** Right trigger rumble motor. */
kRightTriggerRumble,
RIGHT_TRIGGER_RUMBLE,
}
/** Represents the various outputs that a HID may support. */
public enum SupportedOutput {
/// No outputs supported.
NONE(0x0),
/// Mono LED support.
MONO_LED(0x1),
/// RGB LED support.
RGB_LED(0x2),
/// Player LED support.
PLAYER_LED(0x4),
/// Rumble support.
RUMBLE(0x8),
/// Trigger rumble support.
TRIGGER_RUMBLE(0x10);
private final int value;
SupportedOutput(int value) {
this.value = value;
}
/**
* Get the bitfield value of this SupportedOutput.
*
* @return the bitfield value of this SupportedOutput.
*/
public int getValue() {
return value;
}
}
/** USB HID interface type. */
public enum HIDType {
/** Unknown. */
kUnknown(0),
UNKNOWN(0),
/** Standard. */
kStandard(1),
STANDARD(1),
/** Xbox 360. */
kXbox360(2),
XBOX_360(2),
/** Xbox One. */
kXboxOne(3),
XBOX_ONE(3),
/** PS3. */
kPS3(4),
PS3(4),
/** PS4. */
kPS4(5),
PS4(5),
/** PS5. */
kPS5(6),
PS5(6),
/** Switch Pro. */
kSwitchPro(7),
SWITCH_PRO(7),
/** Switch Joycon Left. */
kSwitchJoyconLeft(8),
SWITCH_JOYCON_LEFT(8),
/** Switch Joycon Right. */
kSwitchJoyconRight(9),
SWITCH_JOYCON_RIGHT(9),
/** Switch Joycon Pair. */
kSwitchJoyconPair(10);
SWITCH_JOYCON_PAIR(10);
/** HIDType value. */
public final int value;
@@ -433,8 +465,15 @@ public class GenericHID {
*
* @return the supported outputs for the HID.
*/
public int getSupportedOutputs() {
return DriverStation.getJoystickSupportedOutputs(m_port);
public EnumSet<SupportedOutput> getSupportedOutputs() {
int supported = DriverStation.getJoystickSupportedOutputs(m_port);
EnumSet<SupportedOutput> outputs = EnumSet.noneOf(SupportedOutput.class);
for (SupportedOutput output : SupportedOutput.values()) {
if ((supported & output.getValue()) != 0) {
outputs.add(output);
}
}
return outputs;
}
/**
@@ -479,10 +518,10 @@ public class GenericHID {
value = Math.clamp(value, 0, 1);
int rumbleValue = (int) (value * 65535);
switch (type) {
case kLeftRumble -> this.m_leftRumble = rumbleValue;
case kRightRumble -> this.m_rightRumble = rumbleValue;
case kLeftTriggerRumble -> this.m_leftTriggerRumble = rumbleValue;
case kRightTriggerRumble -> this.m_rightTriggerRumble = rumbleValue;
case LEFT_RUMBLE -> this.m_leftRumble = rumbleValue;
case RIGHT_RUMBLE -> this.m_rightRumble = rumbleValue;
case LEFT_TRIGGER_RUMBLE -> this.m_leftTriggerRumble = rumbleValue;
case RIGHT_TRIGGER_RUMBLE -> this.m_rightTriggerRumble = rumbleValue;
default -> {
// no-op
}

View File

@@ -34,13 +34,33 @@ public class GamepadSim extends GenericHIDSim {
setPOVsMaximumIndex(1);
}
/**
* Set the value of a given button.
*
* @param button the button to set
* @param value the new value
*/
public void setButton(Gamepad.Button button, boolean value) {
setRawButton(button.value, value);
}
/**
* Set the value of a given axis.
*
* @param axis the axis to set
* @param value the new value
*/
public void setAxis(Gamepad.Axis axis, double value) {
setRawAxis(axis.value, value);
}
/**
* Change the left X value of the controller's joystick.
*
* @param value the new value
*/
public void setLeftX(double value) {
setRawAxis(Gamepad.Axis.kLeftX.value, value);
setAxis(Gamepad.Axis.LEFT_X, value);
}
/**
@@ -49,7 +69,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setLeftY(double value) {
setRawAxis(Gamepad.Axis.kLeftY.value, value);
setAxis(Gamepad.Axis.LEFT_Y, value);
}
/**
@@ -58,7 +78,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setRightX(double value) {
setRawAxis(Gamepad.Axis.kRightX.value, value);
setAxis(Gamepad.Axis.RIGHT_X, value);
}
/**
@@ -67,7 +87,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setRightY(double value) {
setRawAxis(Gamepad.Axis.kRightY.value, value);
setAxis(Gamepad.Axis.RIGHT_Y, value);
}
/**
@@ -76,7 +96,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setLeftTriggerAxis(double value) {
setRawAxis(Gamepad.Axis.kLeftTrigger.value, value);
setAxis(Gamepad.Axis.LEFT_TRIGGER, value);
}
/**
@@ -85,7 +105,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setRightTriggerAxis(double value) {
setRawAxis(Gamepad.Axis.kRightTrigger.value, value);
setAxis(Gamepad.Axis.RIGHT_TRIGGER, value);
}
/**
@@ -94,7 +114,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setSouthFaceButton(boolean value) {
setRawButton(Gamepad.Button.kSouthFace.value, value);
setButton(Gamepad.Button.SOUTH_FACE, value);
}
/**
@@ -103,7 +123,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setEastFaceButton(boolean value) {
setRawButton(Gamepad.Button.kEastFace.value, value);
setButton(Gamepad.Button.EAST_FACE, value);
}
/**
@@ -112,7 +132,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setWestFaceButton(boolean value) {
setRawButton(Gamepad.Button.kWestFace.value, value);
setButton(Gamepad.Button.WEST_FACE, value);
}
/**
@@ -121,7 +141,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setNorthFaceButton(boolean value) {
setRawButton(Gamepad.Button.kNorthFace.value, value);
setButton(Gamepad.Button.NORTH_FACE, value);
}
/**
@@ -130,7 +150,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setBackButton(boolean value) {
setRawButton(Gamepad.Button.kBack.value, value);
setButton(Gamepad.Button.BACK, value);
}
/**
@@ -139,7 +159,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setGuideButton(boolean value) {
setRawButton(Gamepad.Button.kGuide.value, value);
setButton(Gamepad.Button.GUIDE, value);
}
/**
@@ -148,7 +168,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setStartButton(boolean value) {
setRawButton(Gamepad.Button.kStart.value, value);
setButton(Gamepad.Button.START, value);
}
/**
@@ -157,7 +177,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setLeftStickButton(boolean value) {
setRawButton(Gamepad.Button.kLeftStick.value, value);
setButton(Gamepad.Button.LEFT_STICK, value);
}
/**
@@ -166,7 +186,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setRightStickButton(boolean value) {
setRawButton(Gamepad.Button.kRightStick.value, value);
setButton(Gamepad.Button.RIGHT_STICK, value);
}
/**
@@ -175,7 +195,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setLeftBumperButton(boolean value) {
setRawButton(Gamepad.Button.kLeftBumper.value, value);
setButton(Gamepad.Button.LEFT_BUMPER, value);
}
/**
@@ -184,7 +204,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setRightBumperButton(boolean value) {
setRawButton(Gamepad.Button.kRightBumper.value, value);
setButton(Gamepad.Button.RIGHT_BUMPER, value);
}
/**
@@ -193,7 +213,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setDpadUpButton(boolean value) {
setRawButton(Gamepad.Button.kDpadUp.value, value);
setButton(Gamepad.Button.DPAD_UP, value);
}
/**
@@ -202,7 +222,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setDpadDownButton(boolean value) {
setRawButton(Gamepad.Button.kDpadDown.value, value);
setButton(Gamepad.Button.DPAD_DOWN, value);
}
/**
@@ -211,7 +231,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setDpadLeftButton(boolean value) {
setRawButton(Gamepad.Button.kDpadLeft.value, value);
setButton(Gamepad.Button.DPAD_LEFT, value);
}
/**
@@ -220,7 +240,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setDpadRightButton(boolean value) {
setRawButton(Gamepad.Button.kDpadRight.value, value);
setButton(Gamepad.Button.DPAD_RIGHT, value);
}
/**
@@ -229,7 +249,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setMisc1Button(boolean value) {
setRawButton(Gamepad.Button.kMisc1.value, value);
setButton(Gamepad.Button.MISC_1, value);
}
/**
@@ -238,7 +258,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setRightPaddle1Button(boolean value) {
setRawButton(Gamepad.Button.kRightPaddle1.value, value);
setButton(Gamepad.Button.RIGHT_PADDLE_1, value);
}
/**
@@ -247,7 +267,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setLeftPaddle1Button(boolean value) {
setRawButton(Gamepad.Button.kLeftPaddle1.value, value);
setButton(Gamepad.Button.LEFT_PADDLE_1, value);
}
/**
@@ -256,7 +276,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setRightPaddle2Button(boolean value) {
setRawButton(Gamepad.Button.kRightPaddle2.value, value);
setButton(Gamepad.Button.RIGHT_PADDLE_2, value);
}
/**
@@ -265,7 +285,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setLeftPaddle2Button(boolean value) {
setRawButton(Gamepad.Button.kLeftPaddle2.value, value);
setButton(Gamepad.Button.LEFT_PADDLE_2, value);
}
/**
@@ -274,7 +294,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setTouchpadButton(boolean value) {
setRawButton(Gamepad.Button.kTouchpad.value, value);
setButton(Gamepad.Button.TOUCHPAD, value);
}
/**
@@ -283,7 +303,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setMisc2Button(boolean value) {
setRawButton(Gamepad.Button.kMisc2.value, value);
setButton(Gamepad.Button.MISC_2, value);
}
/**
@@ -292,7 +312,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setMisc3Button(boolean value) {
setRawButton(Gamepad.Button.kMisc3.value, value);
setButton(Gamepad.Button.MISC_3, value);
}
/**
@@ -301,7 +321,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setMisc4Button(boolean value) {
setRawButton(Gamepad.Button.kMisc4.value, value);
setButton(Gamepad.Button.MISC_4, value);
}
/**
@@ -310,7 +330,7 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setMisc5Button(boolean value) {
setRawButton(Gamepad.Button.kMisc5.value, value);
setButton(Gamepad.Button.MISC_5, value);
}
/**
@@ -319,6 +339,6 @@ public class GamepadSim extends GenericHIDSim {
* @param value the new value
*/
public void setMisc6Button(boolean value) {
setRawButton(Gamepad.Button.kMisc6.value, value);
setButton(Gamepad.Button.MISC_6, value);
}
}

View File

@@ -4,6 +4,7 @@
package org.wpilib.simulation;
import java.util.EnumSet;
import org.wpilib.driverstation.DriverStation;
import org.wpilib.driverstation.GenericHID;
@@ -142,8 +143,12 @@ public class GenericHIDSim {
*
* @param supportedOutputs the new supported outputs
*/
public void setSupportedOutputs(int supportedOutputs) {
DriverStationSim.setJoystickSupportedOutputs(m_port, supportedOutputs);
public void setSupportedOutputs(EnumSet<GenericHID.SupportedOutput> supportedOutputs) {
int supportedOutputsInt = 0;
for (GenericHID.SupportedOutput output : supportedOutputs) {
supportedOutputsInt |= output.getValue();
}
DriverStationSim.setJoystickSupportedOutputs(m_port, supportedOutputsInt);
}
/**
@@ -173,10 +178,10 @@ public class GenericHIDSim {
public double getRumble(GenericHID.RumbleType type) {
int intType =
switch (type) {
case kLeftRumble -> 0;
case kRightRumble -> 1;
case kLeftTriggerRumble -> 2;
case kRightTriggerRumble -> 3;
case LEFT_RUMBLE -> 0;
case RIGHT_RUMBLE -> 1;
case LEFT_TRIGGER_RUMBLE -> 2;
case RIGHT_TRIGGER_RUMBLE -> 3;
};
int value = DriverStationSim.getJoystickRumble(m_port, intType);
return value / 65535.0;

View File

@@ -20,17 +20,17 @@ class GenericHIDTest {
for (int i = 0; i <= 100; i++) {
double rumbleValue = i / 100.0;
hid.setRumble(RumbleType.kLeftRumble, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
hid.setRumble(RumbleType.LEFT_RUMBLE, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.LEFT_RUMBLE), kEpsilon);
hid.setRumble(RumbleType.kRightRumble, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
hid.setRumble(RumbleType.RIGHT_RUMBLE, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.RIGHT_RUMBLE), kEpsilon);
hid.setRumble(RumbleType.kLeftTriggerRumble, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.kLeftTriggerRumble), kEpsilon);
hid.setRumble(RumbleType.LEFT_TRIGGER_RUMBLE, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.LEFT_TRIGGER_RUMBLE), kEpsilon);
hid.setRumble(RumbleType.kRightTriggerRumble, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.kRightTriggerRumble), kEpsilon);
hid.setRumble(RumbleType.RIGHT_TRIGGER_RUMBLE, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.RIGHT_TRIGGER_RUMBLE), kEpsilon);
}
}
@@ -40,45 +40,45 @@ class GenericHIDTest {
final GenericHIDSim sim = new GenericHIDSim(0);
// Make sure all are off
hid.setRumble(RumbleType.kLeftRumble, 0);
hid.setRumble(RumbleType.kRightRumble, 0);
hid.setRumble(RumbleType.kLeftTriggerRumble, 0);
hid.setRumble(RumbleType.kRightTriggerRumble, 0);
assertEquals(0, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kLeftTriggerRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightTriggerRumble), kEpsilon);
hid.setRumble(RumbleType.LEFT_RUMBLE, 0);
hid.setRumble(RumbleType.RIGHT_RUMBLE, 0);
hid.setRumble(RumbleType.LEFT_TRIGGER_RUMBLE, 0);
hid.setRumble(RumbleType.RIGHT_TRIGGER_RUMBLE, 0);
assertEquals(0, sim.getRumble(RumbleType.LEFT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.LEFT_TRIGGER_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_TRIGGER_RUMBLE), kEpsilon);
// test left only
hid.setRumble(RumbleType.kLeftRumble, 1);
assertEquals(1, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kLeftTriggerRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightTriggerRumble), kEpsilon);
hid.setRumble(RumbleType.kLeftRumble, 0);
hid.setRumble(RumbleType.LEFT_RUMBLE, 1);
assertEquals(1, sim.getRumble(RumbleType.LEFT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.LEFT_TRIGGER_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.setRumble(RumbleType.LEFT_RUMBLE, 0);
// test right only
hid.setRumble(RumbleType.kRightRumble, 1);
assertEquals(0, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kLeftTriggerRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightTriggerRumble), kEpsilon);
hid.setRumble(RumbleType.kRightRumble, 0);
hid.setRumble(RumbleType.RIGHT_RUMBLE, 1);
assertEquals(0, sim.getRumble(RumbleType.LEFT_RUMBLE), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.RIGHT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.LEFT_TRIGGER_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.setRumble(RumbleType.RIGHT_RUMBLE, 0);
// test left trigger only
hid.setRumble(RumbleType.kLeftTriggerRumble, 1);
assertEquals(0, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.kLeftTriggerRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightTriggerRumble), kEpsilon);
hid.setRumble(RumbleType.kLeftTriggerRumble, 0);
hid.setRumble(RumbleType.LEFT_TRIGGER_RUMBLE, 1);
assertEquals(0, sim.getRumble(RumbleType.LEFT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_RUMBLE), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.LEFT_TRIGGER_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.setRumble(RumbleType.LEFT_TRIGGER_RUMBLE, 0);
// test right trigger only
hid.setRumble(RumbleType.kRightTriggerRumble, 1);
assertEquals(0, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kLeftTriggerRumble), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.kRightTriggerRumble), kEpsilon);
hid.setRumble(RumbleType.kRightTriggerRumble, 0);
hid.setRumble(RumbleType.RIGHT_TRIGGER_RUMBLE, 1);
assertEquals(0, sim.getRumble(RumbleType.LEFT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.RIGHT_RUMBLE), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.LEFT_TRIGGER_RUMBLE), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.RIGHT_TRIGGER_RUMBLE), kEpsilon);
hid.setRumble(RumbleType.RIGHT_TRIGGER_RUMBLE, 0);
}
}

View File

@@ -7,7 +7,7 @@ package org.wpilib.examples.hatchbottraditional;
import static org.wpilib.driverstation.Gamepad.Button;
import org.wpilib.command2.Command;
import org.wpilib.command2.button.JoystickButton;
import org.wpilib.command2.button.GamepadButton;
import org.wpilib.driverstation.Gamepad;
import org.wpilib.examples.hatchbottraditional.Constants.AutoConstants;
import org.wpilib.examples.hatchbottraditional.Constants.OIConstants;
@@ -83,13 +83,13 @@ public class RobotContainer {
*/
private void configureButtonBindings() {
// Grab the hatch when the 'South Face' button is pressed.
new JoystickButton(m_driverController, Button.kSouthFace.value)
new GamepadButton(m_driverController, Button.SOUTH_FACE)
.onTrue(new GrabHatch(m_hatchSubsystem));
// Release the hatch when the 'East Face' button is pressed.
new JoystickButton(m_driverController, Button.kEastFace.value)
new GamepadButton(m_driverController, Button.EAST_FACE)
.onTrue(new ReleaseHatch(m_hatchSubsystem));
// While holding the bumper button, drive at half velocity
new JoystickButton(m_driverController, Button.kRightBumper.value)
new GamepadButton(m_driverController, Button.RIGHT_BUMPER)
.whileTrue(new HalveDriveVelocity(m_robotDrive));
}