Package edu.wpi.first.wpilibj
Class GenericHID
- java.lang.Object
-
- edu.wpi.first.wpilibj.GenericHID
-
- Direct Known Subclasses:
Joystick,XboxController
public abstract class GenericHID extends Object
GenericHID Interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGenericHID.HandWhich hand the Human Interface Device is associated with.static classGenericHID.HIDTypestatic classGenericHID.RumbleTypeRepresents a rumble output on the JoyStick.
-
Constructor Summary
Constructors Constructor Description GenericHID(int port)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intgetAxisCount()Get the number of axes for the HID.intgetAxisType(int axis)Get the axis type of a joystick axis.intgetButtonCount()For the current HID, return the number of buttons.StringgetName()Get the name of the HID.intgetPort()Get the port number of the HID.intgetPOV()intgetPOV(int pov)Get the angle in degrees of a POV on the HID.intgetPOVCount()For the current HID, return the number of POVs.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.GenericHID.HIDTypegetType()Get the type of the HID.doublegetX()Get the x position of the HID.abstract doublegetX(GenericHID.Hand hand)Get the x position of HID.doublegetY()Get the y position of the HID.abstract doublegetY(GenericHID.Hand hand)Get the y position of the HID.voidsetOutput(int outputNumber, boolean value)Set a single HID output value for the HID.voidsetOutputs(int value)Set all HID output values for the HID.voidsetRumble(GenericHID.RumbleType type, double value)Set the rumble output for the HID.
-
-
-
Method Detail
-
getX
public final double getX()
Get the x position of the HID.- Returns:
- the x position of the HID
-
getX
public abstract double getX(GenericHID.Hand hand)
Get the x position of HID.- Parameters:
hand- which hand, left or right- Returns:
- the x position
-
getY
public final double getY()
Get the y position of the HID.- Returns:
- the y position
-
getY
public abstract double getY(GenericHID.Hand hand)
Get the y position of the HID.- Parameters:
hand- which hand, left or right- Returns:
- the y position
-
getRawButton
public boolean getRawButton(int button)
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.
- Parameters:
button- The button number to be read (starting at 1)- Returns:
- The state of the button.
-
getRawButtonPressed
public boolean getRawButtonPressed(int button)
Whether the button was pressed since the last check. Button indexes begin at 1.- Parameters:
button- The button index, beginning at 1.- Returns:
- Whether the button was pressed since the last check.
-
getRawButtonReleased
public boolean getRawButtonReleased(int button)
Whether the button was released since the last check. Button indexes begin at 1.- Parameters:
button- The button index, beginning at 1.- Returns:
- Whether the button was released since the last check.
-
getRawAxis
public double getRawAxis(int axis)
Get the value of the axis.- Parameters:
axis- The axis to read, starting at 0.- Returns:
- The value of the axis.
-
getPOV
public int getPOV(int pov)
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)- Returns:
- the angle of the POV in degrees, or -1 if the POV is not pressed.
-
getPOV
public int getPOV()
-
getAxisCount
public int getAxisCount()
Get the number of axes for the HID.- Returns:
- the number of axis for the current HID
-
getPOVCount
public int getPOVCount()
For the current HID, return the number of POVs.
-
getButtonCount
public int getButtonCount()
For the current HID, return the number of buttons.
-
getType
public GenericHID.HIDType getType()
Get the type of the HID.- Returns:
- the type of the HID.
-
getName
public String getName()
Get the name of the HID.- Returns:
- the name of the HID.
-
getAxisType
public int getAxisType(int axis)
Get the axis type of a joystick axis.- Returns:
- the axis type of a joystick axis.
-
getPort
public int getPort()
Get the port number of the HID.- Returns:
- The port number of the HID.
-
setOutput
public void setOutput(int outputNumber, boolean value)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
public void setOutputs(int value)
Set all HID output values for the HID.- Parameters:
value- The 32 bit output value (1 bit for each output)
-
setRumble
public void setRumble(GenericHID.RumbleType type, double value)
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
-
-