Class GenericHID

  • Direct Known Subclasses:
    Joystick, PS4Controller, XboxController

    public class GenericHID
    extends Object
    Handle input from standard HID devices connected to the Driver Station.

    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.

    • Constructor Detail

      • GenericHID

        public GenericHID​(int port)
        Construct an instance of a device.
        Parameters:
        port - The port index on the Driver Station that the device is plugged into.
    • Method Detail

      • 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.

        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

        public boolean getRawButtonPressed​(int button)
        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

        public boolean getRawButtonReleased​(int button)
        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

        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). Defaults to 0.
        Returns:
        the angle of the POV in degrees, or -1 if the POV is not pressed.
      • getPOV

        public int 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

        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.
        Returns:
        the number of POVs for the current HID
      • getButtonCount

        public int getButtonCount()
        For the current HID, return the number of buttons.
        Returns:
        the number of buttons for the current HID
      • isConnected

        public boolean isConnected()
        Get if the HID is connected.
        Returns:
        true if the HID is connected
      • 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.
        Parameters:
        axis - The axis to read, starting at 0.
        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 set
        value - The normalized value (0 to 1) to set the rumble to