mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
[wpilib] Rename GenericHID and Gamepad enums to all caps
GenericHID.getSupportedOutputs(): Return EnumSet Gamepad: Add Button-taking accessors
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user