Class ButtonNames
java.lang.Object
com.crossbotics.ftchelper.gamepad.ButtonNames
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 ClassesModifier and TypeClassDescriptionstatic enumThe kind of names a controller has printed on it. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidforce(int pad, ButtonNames.Style style) For tests and the simulator: names as if gamepadpadwere this kind (null = ask the gamepad).static StringThe mark for one button, for a line thatsay(java.lang.String)turns into its name later:mark(2, "RT")is"{2:RT}".static StringOne button's name on gamepad 1 or 2: "A" or "×", "START" or "OPTIONS".static StringnameIn(ButtonNames.Style style, String button) One button's name on a controller of this kind.static StringA screen line with its marks turned into this robot's button names ({A},{2:RT},{PLAY}, and "G1 A" / "G2 RT").static ButtonNames.Stylestyle(int pad) The kind of gamepad 1 or 2.static ButtonNames.StylestyleOf(com.qualcomm.robotcore.hardware.Gamepad g) The kind of names on this gamepad.static voidwatch(com.qualcomm.robotcore.hardware.Gamepad gamepad1, com.qualcomm.robotcore.hardware.Gamepad gamepad2) Uses these gamepads' kinds for the screen names from now on.
-
Field Details
-
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
For tests and the simulator: names as if gamepadpadwere this kind (null = ask the gamepad).- Parameters:
pad- 1 or 2style- the kind, or null
-
style
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
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
One button's name on gamepad 1 or 2: "A" or "×", "START" or "OPTIONS".- Parameters:
pad- 1 or 2button- 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
One button's name on a controller of this kind.- Parameters:
style- the controller's kindbutton- 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
The mark for one button, for a line thatsay(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 2button- A, B, X, Y, LB, RB, LT, RT, BACK, START or GUIDE- Returns:
- the mark, or the name itself
-
say
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
-