Class ButtonNames

java.lang.Object
com.crossbotics.ftchelper.gamepad.ButtonNames

public final class ButtonNames extends Object
The names printed on the driver's own controller, for the Driver Station screen: A, B, X, Y on a Logitech or Xbox controller, and ×, ○, □, △ on a PlayStation-style one (PS4, PS5, Etpark).

WHY: a student holding a PS controller has no button called "A". And "START" on the screen can mean the Driver Hub's ▶ (start the OpMode) or the START button on the gamepad. So the library's screens write buttons as short marks, and this class turns them into the right name just before the screen is sent:

  • {A} {B} {X} {Y} {LB} {RB} {LT} {RT} {BACK} {START} {GUIDE}: gamepad 1's button ({START} is OPTIONS on a PS controller, {GUIDE} the PS button).
  • {2:A} and the like: gamepad 2's button (its own controller may be the other kind).
  • {PLAY}: the Driver Hub's ▶ start button (never a gamepad button).
  • Generated lines such as "G2 RT: intake in" need no marks: "G1 " or "G2 " before a button name is changed too.

Which kind: the FTC SDK tells it (gamepad.type) once the controller is linked (START + A, or OPTIONS + ×). Before that, and for every other kind, the letters are used. The library's OpModes call watch(com.qualcomm.robotcore.hardware.Gamepad, com.qualcomm.robotcore.hardware.Gamepad) at INIT; RobotTelemetry calls say(java.lang.String) on every line it sends.


 ButtonNames.watch(gamepad1, gamepad2);
 telemetry.addLine(ButtonNames.say("{A} = start, {B} = stop"));   // "× = start, ○ = stop" on a PS controller
 
Docs: docs/modules/gamepad.md
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The kind of names a controller has printed on it.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The Driver Hub's start button (the ▶ that starts the OpMode after INIT).
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    force(int pad, ButtonNames.Style style)
    For tests and the simulator: names as if gamepad pad were this kind (null = ask the gamepad).
    static String
    mark(int pad, String button)
    The mark for one button, for a line that say(java.lang.String) turns into its name later: mark(2, "RT") is "{2:RT}".
    static String
    name(int pad, String button)
    One button's name on gamepad 1 or 2: "A" or "×", "START" or "OPTIONS".
    static String
    One button's name on a controller of this kind.
    static String
    say(String text)
    A screen line with its marks turned into this robot's button names ({A}, {2:RT}, {PLAY}, and "G1 A" / "G2 RT").
    style(int pad)
    The kind of gamepad 1 or 2.
    styleOf(com.qualcomm.robotcore.hardware.Gamepad g)
    The kind of names on this gamepad.
    static void
    watch(com.qualcomm.robotcore.hardware.Gamepad gamepad1, com.qualcomm.robotcore.hardware.Gamepad gamepad2)
    Uses these gamepads' kinds for the screen names from now on.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PLAY

      public static final String PLAY
      The Driver Hub's start button (the ▶ that starts the OpMode after INIT).
      See Also:
  • Method Details

    • watch

      public static void watch(com.qualcomm.robotcore.hardware.Gamepad gamepad1, com.qualcomm.robotcore.hardware.Gamepad gamepad2)
      Uses these gamepads' kinds for the screen names from now on. The library's OpModes call it at INIT; call it in your own OpMode to get the same names.
      Parameters:
      gamepad1 - the driver's gamepad (may be null)
      gamepad2 - the operator's gamepad (may be null)
    • force

      public static void force(int pad, ButtonNames.Style style)
      For tests and the simulator: names as if gamepad pad were this kind (null = ask the gamepad).
      Parameters:
      pad - 1 or 2
      style - the kind, or null
    • style

      public static ButtonNames.Style style(int pad)
      The kind of gamepad 1 or 2.
      Parameters:
      pad - 1 or 2
      Returns:
      PLAYSTATION for a PS-style controller, else LETTERS (also before it is linked)
    • styleOf

      public static ButtonNames.Style styleOf(com.qualcomm.robotcore.hardware.Gamepad g)
      The kind of names on this gamepad.
      Parameters:
      g - a gamepad
      Returns:
      PLAYSTATION when the SDK says it is a Sony (or Sony-style) controller, else LETTERS
    • name

      public static String name(int pad, String button)
      One button's name on gamepad 1 or 2: "A" or "×", "START" or "OPTIONS".
      Parameters:
      pad - 1 or 2
      button - A, B, X, Y, LB, RB, LT, RT, BACK, START or GUIDE (as the SDK names it)
      Returns:
      the name on that controller (the button itself when it is not one of these)
    • nameIn

      public static String nameIn(ButtonNames.Style style, String button)
      One button's name on a controller of this kind.
      Parameters:
      style - the controller's kind
      button - A, B, X, Y, LB, RB, LT, RT, BACK, START or GUIDE
      Returns:
      its printed name (the button itself when it is not one of these)
    • mark

      public static String mark(int pad, String button)
      The mark for one button, for a line that say(java.lang.String) turns into its name later: mark(2, "RT") is "{2:RT}". A name that is not one of the buttons with a mark (a D-pad, a stick) comes back as it is.
      Parameters:
      pad - 1 or 2
      button - A, B, X, Y, LB, RB, LT, RT, BACK, START or GUIDE
      Returns:
      the mark, or the name itself
    • say

      public static String say(String text)
      A screen line with its marks turned into this robot's button names ({A}, {2:RT}, {PLAY}, and "G1 A" / "G2 RT"). Text with no marks comes back as it was.
      Parameters:
      text - a line for the screen (null stays null)
      Returns:
      the line with the names on the controllers in use