Package ftclib.driverio
Class FtcMenu
java.lang.Object
ftclib.driverio.FtcMenu
- Direct Known Subclasses:
FtcChoiceMenu
,FtcValueMenu
This class is intended to be inherited by a specific menu class such as FtcChoiceMenu or FtcValueMenu. Therefore,
this class cannot be instantiated by itself. It implements a display menu system. It allows you to construct a
menu tree structure where a menu is displayed on the Driver Station using the Dashboard class. On a choice menu,
the user can press the up and down buttons to change the highlighted choice on the menu and then press enter to
select the highlighted choice. On a value menu, the user can press the up and down button to increase or decrease
the value and then press enter to select the current value. If the value has a huge range and the user wants to
go to a value far away from the current value, it may take a lot of button presses to get to the desired value.
In this situation, the user can press the alt-up or alt-down button to increase or decrease the significant digit
of the value. For example, pressing up or down buttons will increase or decrease the 1's digit initially. If the
user presses the alt-up button once, the significant digit becomes 10's, so pressing up or down buttons will now
increase or decrease the 10's digit and so forth. After the enter button is pressed, it will move on to the next
menu in the menu tree. Or if the user presses the back button to cancel the menu, it will go back to the previous
menu in the menu tree. This is very useful in autonomous allowing the user to select from different autonomous
strategies and also select the options for each autonomous strategy. For example, one could have a menu to select
between being in the RED alliance or the BLUE alliance. A menu to select the robot starting position. A menu to
select the autonomous strategy. A menu to select the delay for starting the strategy etc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The user of this class is required to implement the MenuButtons interface. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static FtcMenu
protected final FtcDashboard
private static final long
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private final FtcMenu.MenuButtons
private final String
private final FtcOpMode
private final FtcMenu
private static int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
FtcMenu
(String menuTitle, FtcMenu parent, FtcMenu.MenuButtons menuButtons) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
This method allows this class to displays the menu on the Driver Station.abstract FtcMenu
This method allows this class to get the child menu.private int
This method checks all the menu button states and combine them into an integer, one bit for each button.This method returns the parent menu of this menu.getTitle()
This method returns the title text of this menu.abstract void
This method allows this class to signal to the subclass that a menu Alt-down button has been pressed so it will perform the necessary operation on it.abstract void
This method allows this class to signal to the subclass that a menu Alt-up button has been pressed so it will perform the necessary operation on it.abstract void
menuDown()
This method allows this class to signal to the subclass that a menu DOWN button has been pressed so it will perform the necessary operation on it.abstract void
menuUp()
This method allows this class to signal to the subclass that a menu UP button has been pressed so it will perform the necessary operation on it.static boolean
runMenus()
This method walks the menu tree in a non-blocking environment.static void
setRootMenu
(FtcMenu rootMenu) This method sets the current menu to the specified root menu.static void
walkMenuTree
(FtcMenu rootMenu) This method traverses the menu tree from the given root menu displaying each menu and waiting for the user to respond to a menu.
-
Field Details
-
LOOP_INTERVAL_MSEC
private static final long LOOP_INTERVAL_MSEC- See Also:
-
MENUBUTTON_BACK
private static final int MENUBUTTON_BACK- See Also:
-
MENUBUTTON_ENTER
private static final int MENUBUTTON_ENTER- See Also:
-
MENUBUTTON_UP
private static final int MENUBUTTON_UP- See Also:
-
MENUBUTTON_DOWN
private static final int MENUBUTTON_DOWN- See Also:
-
MENUBUTTON_ALT_UP
private static final int MENUBUTTON_ALT_UP- See Also:
-
MENUBUTTON_ALT_DOWN
private static final int MENUBUTTON_ALT_DOWN- See Also:
-
dashboard
-
opMode
-
parent
-
prevButtonStates
private static int prevButtonStates -
currMenu
-
-
Constructor Details
-
FtcMenu
Constructor: Creates an instance of the object.- Parameters:
menuTitle
- specifies the title of the menu. The title will be displayed as the first line in the menu.parent
- specifies the parent menu to go back to if the BACK button is pressed. If this is the root menu, it can be set to null.menuButtons
- specifies the object that implements the MenuButtons interface.
-
-
Method Details
-
displayMenu
public abstract void displayMenu()This method allows this class to displays the menu on the Driver Station. -
getChildMenu
This method allows this class to get the child menu.- Returns:
- child menu.
-
getParentMenu
This method returns the parent menu of this menu.- Returns:
- parent menu (can be null if this menu is the root menu).
-
getTitle
This method returns the title text of this menu.- Returns:
- title text.
-
setRootMenu
This method sets the current menu to the specified root menu. Typically, this is called in conjunction with the runMenus() method to use the FtcMenu module in a non-blocking environment.- Parameters:
rootMenu
- specifies the root menu.
-
walkMenuTree
This method traverses the menu tree from the given root menu displaying each menu and waiting for the user to respond to a menu. After the user responded to a menu, it will go to the next menu in the tree. If the user cancels the menu, it will go back to the parent menu where it came from. If there is no next menu, the traversal is ended. Note: this is a static method, meaning you can call it without a menu instance. Also note that this is a blocking call so this should not be called in a multitasking robot loop such as in the execution of a state machine. To use the menus in a multitasking environment, you must use the runMenus() method instead.- Parameters:
rootMenu
- specifies the root of the menu tree.
-
runMenus
public static boolean runMenus()This method walks the menu tree in a non-blocking environment. It means this method must be called periodically, so that the caller can perform other tasks if necessary.- Returns:
- true if the user traverses to the leave node of the menu tree, false if the caller must call this again in a loop.
-
getMenuButtons
private int getMenuButtons()This method checks all the menu button states and combine them into an integer, one bit for each button.- Returns:
- an integer representing the states of all the menu buttons.
-