Interface Gamepad

  • All Known Implementing Classes:
    AbstractController, LogitechAttack3, LogitechDualAction

    public interface Gamepad
    An interface defining a Gamepad controller. All Gamepads are expected to have two thumbsticks, a directional pad, and some clickable buttons. Not all Gamepads will have variable triggers, and not all raw button or axis mappings are the same. These details are left to specific Gamepad implementations.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  Gamepad.Axis
      An axis for a control, eg horizontal, vertical.
      static class  Gamepad.Binding
      A (Button, PressType) tuple for identifying button bindings.
      static interface  Gamepad.Button
      A physical button on a gamepad.
      static interface  Gamepad.Control
      A physical control on a Gamepad, eg a thumbstick or directional pad.
      static class  Gamepad.Mapping
      A (Control, Axis) tuple for identifying mode mappings.
      static class  Gamepad.PressType
      Types of button press actions.
    • Method Detail

      • getBackingHID

        edu.wpi.first.wpilibj.GenericHID getBackingHID()
        Get the backing input device of this Gamepad.
        Returns:
        the backing input device, eg Joystick
      • getPort

        int getPort()
        Get the USB port (as numbered in the Driver Station) that this Gamepad is plugged into.
        Returns:
        the USB port number
      • getValue

        double getValue​(Gamepad.Mapping mapping)
        Get the value of an axis on a control. Generally between -1.0 and 1.0. Controls and Axes should be provided by Gamepad implementations supplying their own valid possible values. Controls and Axes defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        mapping - the mapping to check
        Returns:
        the value of the axis on the control
      • getButton

        boolean getButton​(Gamepad.Button button)
        Get the value of a button on the controller. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        button - which button to check. The mapping from values here to actual buttons will depend on the specific Gamepad implementation
        Returns:
        whether the specified button is currently pressed or not
      • setMode

        default void setMode​(Gamepad.Control control,
                             Gamepad.Axis axis,
                             JoystickMode joystickMode)
        Set a mode to adjust input on one of the controls of this Gamepad. Controls should be provided by Gamepad implementations supplying their own valid possible values. Controls defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations. Likewise for axes.
        Parameters:
        control - the control on which to set a mode
        axis - the axis of the control on which to set a mode
        joystickMode - the mode to set
      • setMode

        default void setMode​(Gamepad.Control control,
                             Gamepad.Axis axis,
                             java.util.function.Function<java.lang.Double,​java.lang.Double> function)
        Set a function to adjust input on one of the controls of this Gamepad. Controls should be provided by Gamepad implementations supplying their own valid possible values. Controls defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations. Likewise for axes.
        Parameters:
        control - the control on which to set a mode
        axis - the axis of the control on which to set a mode
        function - the function to apply
      • setMode

        void setMode​(Gamepad.Mapping mapping,
                     java.util.function.Function<java.lang.Double,​java.lang.Double> function)
        Set a function to adjust input on one of the controls of this Gamepad. Controls should be provided by Gamepad implementations supplying their own valid possible values. Controls defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations. Likewise for axes.
        Parameters:
        mapping - the mapping for which to set a mode
        function - the function to apply
      • setMode

        void setMode​(java.util.function.Function<java.lang.Double,​java.lang.Double> function)
        Set a function to adjust input on one of the controls of this Gamepad. Controls should be provided by Gamepad implementations supplying their own valid possible values. Controls defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations. Likewise for axes.
        Parameters:
        function - the function to apply to all controls and all axes of this Gamepad
      • map

        void map​(Gamepad.Mapping mapping,
                 java.util.function.Consumer<java.lang.Double> consumer)
        Map a control/axis pair to a function.

        The given function will be periodically called and given the then-current value of the control/axis pair specified. This is similar to binding button presses to methods, on a continuous-valued input (eg thumbstick) instead, to a method which requires a double value, for example tank drive.

        Parameters:
        mapping - the control mapping to use
        consumer - the function to be called
      • bind

        default void bind​(Gamepad.Button button,
                          java.lang.Runnable binding)
        Bind a button press on this gamepad to an action to be performed when the button is pressed. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        button - the button on which to bind an action
        binding - the action to be bound
      • bind

        default void bind​(Gamepad.Button button,
                          java.util.function.Consumer<java.lang.Boolean> binding)
      • bind

        default void bind​(Gamepad.Button button,
                          Gamepad.PressType pressType,
                          java.lang.Runnable binding)
        Bind a button press on this gamepad to an action to be performed when the button is pressed, released, or periodically while the button is held. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        button - the button on which to bind an action
        pressType - the type of button press which should trigger the action
        binding - the action to be bound
      • bind

        default void bind​(java.util.Set<Gamepad.Button> buttons,
                          Gamepad.PressType pressType,
                          java.lang.Runnable binding)
        Bind a button combination press on this gamepad to an action to be performed when the button is pressed, released, or periodically while the button is held. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        buttons - the button combination on which to bind an action
        pressType - the type of button press which should trigger the action
        binding - the action to be bound
      • bind

        void bind​(Gamepad.Binding binding,
                  java.lang.Runnable action)
        Bind a button press on this gamepad to an action to be performed when the button is pressed, released, or periodically while the button is held. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        binding - the binding on which to bind an action
        action - the action to be bound
      • unbind

        default void unbind​(Gamepad.Button button)
        Remove all bindings for the given button. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        button - the button for which to unbind all actions
      • unbind

        default void unbind​(Gamepad.Button button,
                            Gamepad.PressType pressType)
        Remove a binding for the given button. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        button - the button for which to unbind an action
        pressType - the type of button press for which to unbind an action
      • unbind

        default void unbind​(java.util.Set<Gamepad.Button> buttons,
                            Gamepad.PressType pressType)
        Remove a binding for the given button combination. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        buttons - the button combination for which to unbind an action
        pressType - the type of button press for which to unbind an action
      • unbind

        void unbind​(Gamepad.Binding binding)
        Remove a binding for the given binding.
        Parameters:
        binding - the binding for which to unbind an action
      • hasBinding

        default boolean hasBinding​(Gamepad.Button button)
        Check if a given button has a bound action. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        button - the button to check for any bindings
        Returns:
        if the button has any bindings
      • hasBinding

        default boolean hasBinding​(Gamepad.Button button,
                                   Gamepad.PressType pressType)
        Check if a given button has a bound action for a specific button press type. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.
        Parameters:
        button - the button to check for bindings
        pressType - the type of button press to check for bindings
        Returns:
        if the button has any bindings for the given press type
      • enableBindings

        void enableBindings()
        Enable button bindings. If bindings are not enabled, then no bound actions will be executed. By default, bindings are not enabled.
      • disableBindings

        void disableBindings()
        Disable button bindings. If bindings are not enabled, then no bound actions will be executed. By default, bindings are not enabled.