5package org.wpilib.driverstation;
7import java.util.EnumSet;
8import java.util.Objects;
9import org.wpilib.driverstation.GenericHID.HIDType;
10import org.wpilib.driverstation.GenericHID.RumbleType;
11import org.wpilib.driverstation.GenericHID.SupportedOutput;
12import org.wpilib.driverstation.internal.DriverStationBackend;
13import org.wpilib.event.BooleanEvent;
14import org.wpilib.event.EventLoop;
15import org.wpilib.math.util.MathUtil;
16import org.wpilib.telemetry.TelemetryLoggable;
17import org.wpilib.telemetry.TelemetryTable;
18import org.wpilib.util.UsageReporting;
28 private static final double MAX_DEADBAND = Math.nextDown(1.0);
88 private final String m_name;
90 Button(
int value, String name) {
126 private final String m_name;
128 Axis(
int value, String name) {
146 private double m_leftXDeadband = 0.1;
147 private double m_leftYDeadband = 0.1;
148 private double m_rightXDeadband = 0.1;
149 private double m_rightYDeadband = 0.1;
150 private double m_leftTriggerDeadband = 0.01;
151 private double m_rightTriggerDeadband = 0.01;
153 private static double clampDeadband(
double deadband) {
154 if (Double.isNaN(deadband)) {
157 return Math.clamp(deadband, 0.0, MAX_DEADBAND);
160 private final GenericHID m_hid;
187 m_hid = Objects.requireNonNull(hid,
"Provided HID object cannot be null");
199 m_leftXDeadband = clampDeadband(deadband);
210 m_leftYDeadband = clampDeadband(deadband);
221 m_rightXDeadband = clampDeadband(deadband);
232 m_rightYDeadband = clampDeadband(deadband);
243 m_leftTriggerDeadband = clampDeadband(deadband);
254 m_rightTriggerDeadband = clampDeadband(deadband);
1424 return m_hid.getRawAxis(axis.
value);
1437 return m_hid.axisLessThan(axis.
value, threshold, loop);
1451 return m_hid.axisGreaterThan(axis.
value, threshold, loop);
1460 return m_hid.getAxesAvailable();
1469 return m_hid.getButtonsAvailable();
1478 return m_hid.isConnected();
1487 return m_hid.getGamepadType();
1496 return m_hid.getSupportedOutputs();
1505 return m_hid.getName();
1517 m_hid.setLeds(r, g, b);
1528 m_hid.setRumble(type, value);
1539 return m_hid.getTouchpadFingerAvailable(
touchpad, finger);
1550 return m_hid.getTouchpadFinger(
touchpad, finger);
1553 private double getAxisForTelemetry(Axis axis) {
1561 table.log(
"LeftX", getAxisForTelemetry(
Axis.
LEFT_X));
1562 table.log(
"LeftY", getAxisForTelemetry(
Axis.
LEFT_Y));
1563 table.log(
"RightX", getAxisForTelemetry(
Axis.
RIGHT_X));
1564 table.log(
"RightY", getAxisForTelemetry(
Axis.
RIGHT_Y));
1567 table.log(
"FaceDown", (buttons & (1L <<
Button.
FACE_DOWN.value)) != 0);
1569 table.log(
"FaceLeft", (buttons & (1L <<
Button.
FACE_LEFT.value)) != 0);
1570 table.log(
"FaceUp", (buttons & (1L <<
Button.
FACE_UP.value)) != 0);
1571 table.log(
"Back", (buttons & (1L <<
Button.
BACK.value)) != 0);
1572 table.log(
"Guide", (buttons & (1L <<
Button.
GUIDE.value)) != 0);
1573 table.log(
"Start", (buttons & (1L <<
Button.
START.value)) != 0);
1578 table.log(
"DpadUp", (buttons & (1L <<
Button.
DPAD_UP.value)) != 0);
1579 table.log(
"DpadDown", (buttons & (1L <<
Button.
DPAD_DOWN.value)) != 0);
1580 table.log(
"DpadLeft", (buttons & (1L <<
Button.
DPAD_LEFT.value)) != 0);
1582 table.log(
"Misc1", (buttons & (1L <<
Button.
MISC_1.value)) != 0);
1587 table.log(
"Touchpad", (buttons & (1L <<
Button.
TOUCHPAD.value)) != 0);
1588 table.log(
"Misc2", (buttons & (1L <<
Button.
MISC_2.value)) != 0);
1589 table.log(
"Misc3", (buttons & (1L <<
Button.
MISC_3.value)) != 0);
1590 table.log(
"Misc4", (buttons & (1L <<
Button.
MISC_4.value)) != 0);
1591 table.log(
"Misc5", (buttons & (1L <<
Button.
MISC_5.value)) != 0);
1592 table.log(
"Misc6", (buttons & (1L <<
Button.
MISC_6.value)) != 0);
1597 return "HID:Gamepad";
static GenericHID getGenericHID(int port)
boolean getRightStickButton()
boolean getFaceLeftButton()
BooleanEvent rightBumper(EventLoop loop)
TouchpadFinger getTouchpadFinger(int touchpad, int finger)
boolean getDpadUpButtonPressed()
boolean getDpadLeftButton()
BooleanEvent dpadDown(EventLoop loop)
boolean getLeftPaddle2ButtonPressed()
boolean getRightPaddle2ButtonPressed()
boolean getRightStickButtonReleased()
BooleanEvent leftStick(EventLoop loop)
boolean getFaceDownButtonReleased()
void setLeds(int r, int g, int b)
boolean getLeftStickButtonPressed()
String getTelemetryType()
Gamepad(final GenericHID hid)
BooleanEvent leftTrigger(double threshold, EventLoop loop)
BooleanEvent faceDown(EventLoop loop)
boolean getLeftBumperButtonPressed()
boolean getDpadRightButton()
BooleanEvent dpadRight(EventLoop loop)
boolean getFaceLeftButtonReleased()
BooleanEvent rightPaddle2(EventLoop loop)
boolean getTouchpadButtonPressed()
BooleanEvent leftPaddle1(EventLoop loop)
boolean getButtonPressed(Button button)
boolean getFaceDownButtonPressed()
BooleanEvent misc2(EventLoop loop)
boolean getStartButtonPressed()
boolean getFaceRightButtonPressed()
boolean getLeftBumperButton()
boolean getTouchpadFingerAvailable(int touchpad, int finger)
boolean getGuideButtonReleased()
boolean getRightStickButtonPressed()
void setLeftXDeadband(double deadband)
boolean getMisc4ButtonPressed()
boolean getBackButtonPressed()
BooleanEvent guide(EventLoop loop)
boolean getMisc3ButtonPressed()
boolean getDpadDownButton()
BooleanEvent misc5(EventLoop loop)
boolean getDpadRightButtonReleased()
BooleanEvent misc1(EventLoop loop)
void setRightYDeadband(double deadband)
boolean getRightPaddle1ButtonPressed()
boolean getFaceRightButton()
BooleanEvent rightTrigger(EventLoop loop)
BooleanEvent faceRight(EventLoop loop)
boolean getRightBumperButtonReleased()
boolean getButton(Button button)
boolean getMisc1ButtonReleased()
BooleanEvent axisLessThan(Axis axis, double threshold, EventLoop loop)
BooleanEvent leftBumper(EventLoop loop)
boolean getStartButtonReleased()
boolean getMisc6ButtonPressed()
BooleanEvent rightStick(EventLoop loop)
boolean getMisc4ButtonReleased()
boolean getFaceUpButtonPressed()
void logTo(TelemetryTable table)
BooleanEvent misc3(EventLoop loop)
boolean getLeftPaddle2Button()
boolean getLeftBumperButtonReleased()
boolean getLeftPaddle2ButtonReleased()
BooleanEvent misc6(EventLoop loop)
boolean getLeftPaddle1ButtonReleased()
BooleanEvent start(EventLoop loop)
BooleanEvent dpadUp(EventLoop loop)
boolean getMisc1ButtonPressed()
boolean getRightPaddle2Button()
boolean getLeftStickButtonReleased()
boolean getFaceUpButtonReleased()
BooleanEvent leftTrigger(EventLoop loop)
long getButtonsAvailable()
boolean getMisc5ButtonPressed()
boolean getMisc2ButtonReleased()
boolean getRightPaddle1ButtonReleased()
boolean getDpadDownButtonPressed()
BooleanEvent rightPaddle1(EventLoop loop)
BooleanEvent touchpad(EventLoop loop)
EnumSet< SupportedOutput > getSupportedOutputs()
boolean getTouchpadButton()
boolean getRightBumperButtonPressed()
double getAxis(Axis axis)
boolean getDpadLeftButtonReleased()
boolean getLeftPaddle1Button()
boolean getLeftPaddle1ButtonPressed()
boolean getMisc2ButtonPressed()
BooleanEvent rightTrigger(double threshold, EventLoop loop)
boolean getButtonReleased(Button button)
boolean getMisc3ButtonReleased()
boolean getRightBumperButton()
BooleanEvent faceUp(EventLoop loop)
boolean getTouchpadButtonReleased()
void setLeftYDeadband(double deadband)
boolean getMisc5ButtonReleased()
void setLeftTriggerDeadband(double deadband)
BooleanEvent faceLeft(EventLoop loop)
BooleanEvent button(Button button, EventLoop loop)
boolean getGuideButtonPressed()
boolean getRightPaddle2ButtonReleased()
boolean getBackButtonReleased()
boolean getFaceRightButtonReleased()
BooleanEvent dpadLeft(EventLoop loop)
BooleanEvent axisGreaterThan(Axis axis, double threshold, EventLoop loop)
boolean getDpadRightButtonPressed()
boolean getFaceLeftButtonPressed()
boolean getRightPaddle1Button()
boolean getDpadUpButton()
boolean getLeftStickButton()
boolean getMisc6ButtonReleased()
BooleanEvent leftPaddle2(EventLoop loop)
boolean getDpadLeftButtonPressed()
void setRightTriggerDeadband(double deadband)
void setRumble(RumbleType type, double value)
boolean getDpadDownButtonReleased()
BooleanEvent back(EventLoop loop)
void setRightXDeadband(double deadband)
boolean getDpadUpButtonReleased()
boolean getFaceUpButton()
boolean getFaceDownButton()
BooleanEvent misc4(EventLoop loop)
static OptionalDouble getStickAxisIfAvailable(int stick, int axis)
static long getStickButtons(final int stick)
static double applyDeadband(double value, double deadband, double maxMagnitude)
static void reportUsage(String resource, String data)