Class GenericHID
- Direct Known Subclasses:
Gamepad, Joystick, NiDsPS4Controller, NiDsPS5Controller, NiDsStadiaController, NiDsXboxController
This class handles standard input that comes from the Driver Station. Each time a value is requested the most recent value is returned. There is a single class instance for each device and the mapping of ports to hardware buttons depends on the code in the Driver Station.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumUSB HID interface type.static enumRepresents a rumble output on the Joystick. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaxisGreaterThan(int axis, double threshold, EventLoop loop) Constructs an event instance that is true when the axis value is greater thanthreshold, attached to the given loop.axisLessThan(int axis, double threshold, EventLoop loop) Constructs an event instance that is true when the axis value is less thanthreshold, attached to the given loop.Constructs an event instance around this button's digital signal.intGet the number of axes for the HID.intGet the maximum axis index for the joystick.longFor the current HID, return the number of buttons.intGet the maximum button index for the joystick.Get the type of the HID.getName()Get the name of the HID.intgetPort()Get the port number of the HID.getPOV()Get the angle of the default POV (index 0) on the HID.getPOV(int pov) Get the angle of a POV on the HID.intFor the current HID, return the number of POVs.intGet the maximum POV index for the joystick.doublegetRawAxis(int axis) Get the value of the axis.booleangetRawButton(int button) Get the button value (starting at button 1).booleangetRawButtonPressed(int button) Whether the button was pressed since the last check.booleangetRawButtonReleased(int button) Whether the button was released since the last check.intGet the supported outputs for the HID.getTouchpadFinger(int touchpad, int finger) Get the touchpad finger data.booleangetTouchpadFingerAvailable(int touchpad, int finger) Check if a touchpad finger is available.booleanGet if the HID is connected.pov(int pov, DriverStation.POVDirection angle, EventLoop loop) Constructs a BooleanEvent instance based around this angle of a POV on the HID.pov(DriverStation.POVDirection angle, EventLoop loop) Constructs a BooleanEvent instance based around this angle of a POV on the HID.Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID.Constructs a BooleanEvent instance based around the down direction of the default (index 0) POV on the HID.povDownLeft(EventLoop loop) Constructs a BooleanEvent instance based around the down left direction of the default (index 0) POV on the HID.povDownRight(EventLoop loop) Constructs a BooleanEvent instance based around the down right direction of the default (index 0) POV on the HID.Constructs a BooleanEvent instance based around the left direction of the default (index 0) POV on the HID.Constructs a BooleanEvent instance based around the right direction of the default (index 0) POV on the HID.Constructs a BooleanEvent instance based around the up direction of the default (index 0) POV on the HID.Constructs a BooleanEvent instance based around the up left direction of the default (index 0) POV on the HID.povUpRight(EventLoop loop) Constructs a BooleanEvent instance based around the up right direction of the default (index 0) POV on the HID.voidsetLeds(int r, int g, int b) Set leds on the controller.voidsetRumble(GenericHID.RumbleType type, double value) Set the rumble output for the HID.
-
Constructor Details
-
GenericHID
Construct an instance of a device.- Parameters:
port- The port index on the Driver Station that the device is plugged into.
-
-
Method Details
-
getRawButton
Get the button value (starting at button 1).The buttons are returned in a single 16 bit value with one bit representing the state of each button. The appropriate button is returned as a boolean value.
This method returns true if the button is being held down at the time that this method is being called.
- Parameters:
button- The button number to be read (starting at 1)- Returns:
- The state of the button.
-
getRawButtonPressed
Whether the button was pressed since the last check. Button indexes begin at 1.This method returns true if the button went from not pressed to held down since the last time this method was called. This is useful if you only want to call a function once when you press the button.
- Parameters:
button- The button index, beginning at 0.- Returns:
- Whether the button was pressed since the last check.
-
getRawButtonReleased
Whether the button was released since the last check. Button indexes begin at 1.This method returns true if the button went from held down to not pressed since the last time this method was called. This is useful if you only want to call a function once when you release the button.
- Parameters:
button- The button index, beginning at 0.- Returns:
- Whether the button was released since the last check.
-
button
Constructs an event instance around this button's digital signal.- Parameters:
button- the button indexloop- the event loop instance to attach the event to.- Returns:
- an event instance representing the button's digital signal attached to the given loop.
-
getRawAxis
Get the value of the axis.- Parameters:
axis- The axis to read, starting at 0.- Returns:
- The value of the axis.
-
getPOV
Get the angle of a POV on the HID.- Parameters:
pov- The index of the POV to read (starting at 0). Defaults to 0.- Returns:
- the angle of the POV.
-
getPOV
Get the angle of the default POV (index 0) on the HID.- Returns:
- the angle of the POV.
-
pov
Constructs a BooleanEvent instance based around this angle of a POV on the HID.- Parameters:
angle- POV angle.loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around this angle of a POV on the HID.
-
pov
Constructs a BooleanEvent instance based around this angle of a POV on the HID.- Parameters:
pov- index of the POV to read (starting at 0). Defaults to 0.angle- POV angle.loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around this angle of a POV on the HID.
-
povUp
Constructs a BooleanEvent instance based around the up direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the up direction a POV on the HID.
-
povUpRight
Constructs a BooleanEvent instance based around the up right direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the up right direction of a POV on the HID.
-
povRight
Constructs a BooleanEvent instance based around the right direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the right direction of a POV on the HID.
-
povDownRight
Constructs a BooleanEvent instance based around the down right direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the down right direction of a POV on the HID.
-
povDown
Constructs a BooleanEvent instance based around the down direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the down direction of a POV on the HID.
-
povDownLeft
Constructs a BooleanEvent instance based around the down left direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the down left direction of a POV on the HID.
-
povLeft
Constructs a BooleanEvent instance based around the left direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the left direction of a POV on the HID.
-
povUpLeft
Constructs a BooleanEvent instance based around the up left direction of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the up left direction of a POV on the HID.
-
povCenter
Constructs a BooleanEvent instance based around the center (not pressed) of the default (index 0) POV on the HID.- Parameters:
loop- the event loop instance to attach the event to.- Returns:
- a BooleanEvent instance based around the center of a POV on the HID.
-
axisLessThan
Constructs an event instance that is true when the axis value is less thanthreshold, attached to the given loop.- Parameters:
axis- The axis to read, starting at 0threshold- The value below which this event should return true.loop- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the axis value is less than the provided threshold.
-
axisGreaterThan
Constructs an event instance that is true when the axis value is greater thanthreshold, attached to the given loop.- Parameters:
axis- The axis to read, starting at 0threshold- The value above which this event should return true.loop- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the axis value is greater than the provided threshold.
-
getAxesMaximumIndex
Get the maximum axis index for the joystick.- Returns:
- the maximum axis index for the joystick
-
getAxesAvailable
Get the number of axes for the HID.- Returns:
- the number of axis for the current HID
-
getPOVsMaximumIndex
Get the maximum POV index for the joystick.- Returns:
- the maximum POV index for the joystick
-
getPOVsAvailable
For the current HID, return the number of POVs.- Returns:
- the number of POVs for the current HID
-
getButtonsMaximumIndex
Get the maximum button index for the joystick.- Returns:
- the maximum button index for the joystick
-
getButtonsAvailable
For the current HID, return the number of buttons.- Returns:
- the number of buttons for the current HID
-
isConnected
-
getGamepadType
-
getSupportedOutputs
Get the supported outputs for the HID.- Returns:
- the supported outputs for the HID.
-
getName
-
getPort
-
setLeds
Set leds on the controller. If only mono is supported, the system will use the highest value passed in.- Parameters:
r- Red value from 0-255g- Green value from 0-255b- Blue value from 0-255
-
setRumble
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.- Parameters:
type- Which rumble value to setvalue- The normalized value (0 to 1) to set the rumble to
-
getTouchpadFingerAvailable
Check if a touchpad finger is available.- Parameters:
touchpad- The touchpad to check.finger- The finger to check.- Returns:
- true if the touchpad finger is available.
-
getTouchpadFinger
Get the touchpad finger data.- Parameters:
touchpad- The touchpad to read.finger- The finger to read.- Returns:
- The touchpad finger data.
-