Class GenericHID
- Direct Known Subclasses:
Joystick
,PS4Controller
,XboxController
public class GenericHID extends Object
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 Classes Modifier and Type Class Description static class
GenericHID.HIDType
static class
GenericHID.RumbleType
Represents a rumble output on the JoyStick. -
Constructor Summary
Constructors Constructor Description GenericHID(int port)
Construct an instance of a device. -
Method Summary
Modifier and Type Method Description int
getAxisCount()
Get the number of axes for the HID.int
getAxisType(int axis)
Get the axis type of a joystick axis.int
getButtonCount()
For the current HID, return the number of buttons.String
getName()
Get the name of the HID.int
getPort()
Get the port number of the HID.int
getPOV()
Get the angle in degrees of the default POV (index 0) on the HID.int
getPOV(int pov)
Get the angle in degrees of a POV on the HID.int
getPOVCount()
For the current HID, return the number of POVs.double
getRawAxis(int axis)
Get the value of the axis.boolean
getRawButton(int button)
Get the button value (starting at button 1).boolean
getRawButtonPressed(int button)
Whether the button was pressed since the last check.boolean
getRawButtonReleased(int button)
Whether the button was released since the last check.GenericHID.HIDType
getType()
Get the type of the HID.boolean
isConnected()
Get if the HID is connected.void
setOutput(int outputNumber, boolean value)
Set a single HID output value for the HID.void
setOutputs(int value)
Set all HID output values for the HID.void
setRumble(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 1.- 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 1.- Returns:
- Whether the button was released since the last check.
-
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 in degrees of a POV on the HID.The POV angles start at 0 in the up direction, and increase clockwise (eg right is 90, upper-left is 315).
- Parameters:
pov
- The index of the POV to read (starting at 0). Defaults to 0.- Returns:
- the angle of the POV in degrees, or -1 if the POV is not pressed.
-
getPOV
Get the angle in degrees of the default POV (index 0) on the HID.The POV angles start at 0 in the up direction, and increase clockwise (eg right is 90, upper-left is 315).
- Returns:
- the angle of the POV in degrees, or -1 if the POV is not pressed.
-
getAxisCount
Get the number of axes for the HID.- Returns:
- the number of axis for the current HID
-
getPOVCount
For the current HID, return the number of POVs.- Returns:
- the number of POVs for the current HID
-
getButtonCount
For the current HID, return the number of buttons.- Returns:
- the number of buttons for the current HID
-
isConnected
Get if the HID is connected.- Returns:
- true if the HID is connected
-
getType
Get the type of the HID.- Returns:
- the type of the HID.
-
getName
Get the name of the HID.- Returns:
- the name of the HID.
-
getAxisType
Get the axis type of a joystick axis.- Parameters:
axis
- The axis to read, starting at 0.- Returns:
- the axis type of a joystick axis.
-
getPort
Get the port number of the HID.- Returns:
- The port number of the HID.
-
setOutput
Set a single HID output value for the HID.- Parameters:
outputNumber
- The index of the output to set (1-32)value
- The value to set the output to
-
setOutputs
Set all HID output values for the HID.- Parameters:
value
- The 32 bit output value (1 bit for each output)
-
setRumble
Set the rumble output for the HID. The DS currently supports 2 rumble values, left rumble and right rumble.- Parameters:
type
- Which rumble value to setvalue
- The normalized value (0 to 1) to set the rumble to
-