From 59edbdd3cc409713a868827132cb4c8abafabf95 Mon Sep 17 00:00:00 2001 From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> Date: Sat, 6 Dec 2025 09:17:48 -0800 Subject: [PATCH] [halsim_gui, wpilibc/j] Fixups for joystick outputs (#8443) #8385 changed gamepad types to follow SDL_GamepadType, so 20 and 21 (previously `kHIDJoystick` and `kHIDGamepad`, respectively) are no longer valid constants. This meant that after leaving the disconnected state of the sim GUI, `GamepadType.getGamepadType()` would return null (since it didn't match any constants). Since there aren't analogous generic joystick and gamepad constants anymore, this PR changes GlfwSystemJoystick and KeyboardJoystick to both unconditionally report as kStandard. This also updates the GenericHID.SetRumble doc comment to reflect the two new types of rumble and changes some switch labeled statement groups to use switch rules instead. If we want to keep on using switch labeled statement groups (e.g. for consistency with C++, though GenericHID::SetRumble currently uses if-else), then I could drop the last change- I just made it since GenericHID.setRumble() previously used switch rules and general switch rules are nice since there's no risk of fall-through. --- .../src/main/native/cpp/DriverStationGui.cpp | 4 +-- .../include/wpi/driverstation/GenericHID.hpp | 3 ++- .../org/wpilib/driverstation/GenericHID.java | 25 +++++++------------ .../org/wpilib/simulation/GenericHIDSim.java | 24 ++++++------------ 4 files changed, 20 insertions(+), 36 deletions(-) diff --git a/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp b/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp index 207628cb2b..d37399bc94 100644 --- a/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/DriverStationGui.cpp @@ -426,7 +426,7 @@ void GlfwSystemJoystick::GetData(HALJoystickData* data, bool mapGamepad) const { // copy into HAL structures data->desc.isGamepad = m_isGamepad ? 1 : 0; - data->desc.gamepadType = m_isGamepad ? 21 : 20; + data->desc.gamepadType = 1; // Standard std::strncpy(data->desc.name, m_name, sizeof(data->desc.name) - 1); data->desc.name[sizeof(data->desc.name) - 1] = '\0'; int axesCount = (std::min)(m_axisCount, HAL_kMaxJoystickAxes); @@ -555,7 +555,7 @@ KeyboardJoystick::KeyboardJoystick(wpi::glass::Storage& storage, int index) // init desc structure m_data.desc.isGamepad = 0; - m_data.desc.gamepadType = 20; + m_data.desc.gamepadType = 1; // Standard std::strncpy(m_data.desc.name, m_name, 256); } diff --git a/wpilibc/src/main/native/include/wpi/driverstation/GenericHID.hpp b/wpilibc/src/main/native/include/wpi/driverstation/GenericHID.hpp index bd8116fd9c..6752a821f0 100644 --- a/wpilibc/src/main/native/include/wpi/driverstation/GenericHID.hpp +++ b/wpilibc/src/main/native/include/wpi/driverstation/GenericHID.hpp @@ -363,7 +363,8 @@ class GenericHID { /** * Set the rumble output for the HID. * - * The DS currently supports 2 rumble values, left rumble and right rumble. + * The DS currently supports 4 rumble values: left rumble, right rumble, left + * trigger rumble, and right trigger rumble. * * @param type Which rumble value to set * @param value The normalized value (0 to 1) to set the rumble to diff --git a/wpilibj/src/main/java/org/wpilib/driverstation/GenericHID.java b/wpilibj/src/main/java/org/wpilib/driverstation/GenericHID.java index 99fe2fcf1f..2f63a1026e 100644 --- a/wpilibj/src/main/java/org/wpilib/driverstation/GenericHID.java +++ b/wpilibj/src/main/java/org/wpilib/driverstation/GenericHID.java @@ -469,8 +469,8 @@ public class GenericHID { } /** - * Set the rumble output for the HID. The DS currently supports 2 rumble values, left rumble and - * right rumble. + * Set the rumble output for the HID. The DS currently supports 4 rumble values: left rumble, + * right rumble, left trigger rumble, and right trigger rumble. * * @param type Which rumble value to set * @param value The normalized value (0 to 1) to set the rumble to @@ -479,20 +479,13 @@ public class GenericHID { value = Math.clamp(value, 0, 1); int rumbleValue = (int) (value * 65535); switch (type) { - case kLeftRumble: - this.m_leftRumble = rumbleValue; - break; - case kRightRumble: - this.m_rightRumble = rumbleValue; - break; - case kLeftTriggerRumble: - this.m_leftTriggerRumble = rumbleValue; - break; - case kRightTriggerRumble: - this.m_rightTriggerRumble = rumbleValue; - break; - default: - break; + case kLeftRumble -> this.m_leftRumble = rumbleValue; + case kRightRumble -> this.m_rightRumble = rumbleValue; + case kLeftTriggerRumble -> this.m_leftTriggerRumble = rumbleValue; + case kRightTriggerRumble -> this.m_rightTriggerRumble = rumbleValue; + default -> { + // no-op + } } DriverStationJNI.setJoystickRumble( diff --git a/wpilibj/src/main/java/org/wpilib/simulation/GenericHIDSim.java b/wpilibj/src/main/java/org/wpilib/simulation/GenericHIDSim.java index dfd8337a04..cf39f8c9d6 100644 --- a/wpilibj/src/main/java/org/wpilib/simulation/GenericHIDSim.java +++ b/wpilibj/src/main/java/org/wpilib/simulation/GenericHIDSim.java @@ -171,23 +171,13 @@ public class GenericHIDSim { * @return the rumble value */ public double getRumble(GenericHID.RumbleType type) { - int intType = 0; - switch (type) { - case kLeftRumble: - intType = 0; - break; - case kRightRumble: - intType = 1; - break; - case kLeftTriggerRumble: - intType = 2; - break; - case kRightTriggerRumble: - intType = 3; - break; - default: - return 0.0; - } + int intType = + switch (type) { + case kLeftRumble -> 0; + case kRightRumble -> 1; + case kLeftTriggerRumble -> 2; + case kRightTriggerRumble -> 3; + }; int value = DriverStationSim.getJoystickRumble(m_port, intType); return value / 65535.0; }