mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +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:
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user