[hal,wpilib] Add support for joystick outputs (#8385)

Support joystick outputs, including Rumble and LEDs.

Also requires an update to Joystick descriptors, as that has also
changed in mrccomm to support showing what outputs are supported.
This commit is contained in:
Thad House
2025-11-17 14:36:14 -08:00
committed by GitHub
parent 5db6d2f500
commit ce6fd225a6
54 changed files with 1607 additions and 854 deletions

View File

@@ -245,10 +245,21 @@ class DriverStation final {
/**
* Returns the type of joystick at a given port.
*
* This maps to SDL_GamepadType
*
* @param stick The joystick port number
* @return The HID type of joystick at the given port
*/
static int GetJoystickType(int stick);
static int GetJoystickGamepadType(int stick);
/**
* Returns the number of outputs supported by the joystick at the given
* port.
*
* @param stick The joystick port number
* @return The number of outputs supported by the joystick at the given port
*/
static int GetJoystickSupportedOutputs(int stick);
/**
* Returns the name of the joystick at the given port.

View File

@@ -33,8 +33,28 @@ class GenericHID {
kLeftRumble,
/// Right rumble motor.
kRightRumble,
/// Both left and right rumble motors.
kBothRumble
/// Left trigger rumble motor.
kLeftTriggerRumble,
/// Right trigger rumble motor.
kRightTriggerRumble,
};
/**
* Represents the various outputs that a HID may support.
*/
enum SupportedOutputs {
/// No outputs supported.
kNone = 0x0,
/// Mono LED support.
kMonoLed = 0x1,
/// RGB LED support.
kRgbLed = 0x2,
/// Player LED support.
kPlayerLed = 0x4,
/// Rumble support.
kRumble = 0x8,
/// Trigger rumble support.
kTriggerRumble = 0x10,
};
/**
@@ -42,39 +62,27 @@ class GenericHID {
*/
enum HIDType {
/// Unknown.
kUnknown = -1,
/// XInputUnknown.
kXInputUnknown = 0,
/// XInputGamepad.
kXInputGamepad = 1,
/// XInputWheel.
kXInputWheel = 2,
/// XInputArcadeStick.
kXInputArcadeStick = 3,
/// XInputFlightStick.
kXInputFlightStick = 4,
/// XInputDancePad.
kXInputDancePad = 5,
/// XInputGuitar.
kXInputGuitar = 6,
/// XInputGuitar2.
kXInputGuitar2 = 7,
/// XInputDrumKit.
kXInputDrumKit = 8,
/// XInputGuitar3.
kXInputGuitar3 = 11,
/// XInputArcadePad.
kXInputArcadePad = 19,
/// HIDJoystick.
kHIDJoystick = 20,
/// HIDGamepad.
kHIDGamepad = 21,
/// HIDDriving.
kHIDDriving = 22,
/// HIDFlight.
kHIDFlight = 23,
/// HID1stPerson.
kHID1stPerson = 24
kUnknown = 0,
/// Standard HID device.
kStandard,
/// Xbox 360 controller.
kXbox360,
/// Xbox One controller.
kXboxOne,
/// PS3 controller.
kPS3,
/// PS4 controller.
kPS4,
/// PS5 controller.
kPS5,
/// Nintendo Switch Pro controller.
kSwitchPro,
/// Nintendo Switch Joycon Left controller.
kSwitchJoyconLeft,
/// Nintendo Switch Joycon Right controller.
kSwitchJoyconRight,
/// Nintendo Switch Joycon controller pair.
kSwitchJoyconPair
};
explicit GenericHID(int port);
@@ -319,7 +327,14 @@ class GenericHID {
*
* @return the type of the HID.
*/
GenericHID::HIDType GetType() const;
GenericHID::HIDType GetGamepadType() const;
/**
* Get the supported outputs of the HID.
*
* @return the supported outputs of the HID.
*/
GenericHID::SupportedOutputs GetSupportedOutputs() const;
/**
* Get the name of the HID.
@@ -336,19 +351,14 @@ class GenericHID {
int GetPort() const;
/**
* Set a single HID output value for the HID.
* Set leds on the controller. If only mono is supported, the system will use
* the highest value passed in.
*
* @param outputNumber The index of the output to set (1-32)
* @param value The value to set the output to
* @param r Red value from 0-255
* @param g Green value from 0-255
* @param b Blue value from 0-255
*/
void SetOutput(int outputNumber, bool value);
/**
* Set all output values for the HID.
*
* @param value The 32 bit output value (1 bit for each output)
*/
void SetOutputs(int value);
void SetLeds(int r, int g, int b);
/**
* Set the rumble output for the HID.
@@ -362,9 +372,10 @@ class GenericHID {
private:
int m_port;
int m_outputs = 0;
uint16_t m_leftRumble = 0;
uint16_t m_rightRumble = 0;
uint16_t m_leftTriggerRumble = 0;
uint16_t m_rightTriggerRumble = 0;
};
} // namespace wpi

View File

@@ -251,13 +251,14 @@ class DriverStationSim {
* @param stick The joystick number
* @return The joystick outputs
*/
static int64_t GetJoystickOutputs(int stick);
static int32_t GetJoystickLeds(int stick);
/**
* Gets the joystick rumble.
*
* @param stick The joystick number
* @param rumbleNum Rumble to get (0=left, 1=right)
* @param rumbleNum Rumble to get (0=left, 1=right, 2=left trigger, 3=right
* trigger)
* @return The joystick rumble value
*/
static int GetJoystickRumble(int stick, int rumbleNum);
@@ -346,7 +347,7 @@ class DriverStationSim {
* @param stick The joystick number
* @param type The value of type
*/
static void SetJoystickType(int stick, int type);
static void SetJoystickGamepadType(int stick, int type);
/**
* Sets the name of a joystick.
@@ -356,6 +357,14 @@ class DriverStationSim {
*/
static void SetJoystickName(int stick, std::string_view name);
/**
* Sets the supported outputs for a joystick.
*
* @param stick The joystick number
* @param supportedOutputs The supported outputs for the joystick
*/
static void SetJoystickSupportedOutputs(int stick, int supportedOutputs);
/**
* Sets the game specific message.
*

View File

@@ -102,7 +102,9 @@ class GenericHIDSim {
*
* @param type the new device type
*/
void SetType(GenericHID::HIDType type);
void SetGamepadType(GenericHID::HIDType type);
void SetSupportedOutputs(GenericHID::SupportedOutputs supportedOutputs);
/**
* Set the name of this device.
@@ -112,19 +114,11 @@ class GenericHIDSim {
void SetName(const char* name);
/**
* Read the output of a button.
* Get the value of set LEDs.
*
* @param outputNumber the button number
* @return the value of the button (true = pressed)
* @return the led color
*/
bool GetOutput(int outputNumber);
/**
* Get the encoded 16-bit integer that passes button values.
*
* @return the button values
*/
int64_t GetOutputs();
int32_t GetLeds();
/**
* Get the joystick rumble.