mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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.
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user