APM:Libraries
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Menu Class Reference

Class defining and handling one menu tree. More...

#include <AP_Menu.h>

Collaboration diagram for Menu:
[legend]

Classes

struct  arg
 
struct  command
 

Public Member Functions

 FUNCTOR_TYPEDEF (func, int8_t, uint8_t, const struct arg *)
 
 FUNCTOR_TYPEDEF (preprompt, bool)
 
 Menu (const char *prompt, const struct command *commands, uint8_t entries, preprompt ppfunc=0)
 
void set_limits (uint8_t commandline_max, uint8_t args_max)
 set command line length limit More...
 
void run (void)
 menu runner More...
 
bool check_input (void)
 

Static Public Member Functions

static void set_port (AP_HAL::BetterStream *port)
 

Private Member Functions

void _help (void)
 implements the 'help' command More...
 
int8_t _call (uint8_t n, uint8_t argc)
 
void _allocate_buffers (void)
 
bool _check_for_input (void)
 
bool _run_command (bool prompt_on_enter)
 
void _display_prompt ()
 

Private Attributes

const char * _prompt
 prompt to display More...
 
const command_commands
 array of commands More...
 
const uint8_t _entries
 size of the menu More...
 
const preprompt _ppfunc
 optional pre-prompt action More...
 
uint8_t _commandline_max
 
uint8_t _args_max
 
uint8_t _input_len
 

Static Private Attributes

static char * _inbuf
 input buffer More...
 
static arg_argv
 arguments More...
 
static AP_HAL::BetterStream_port
 

Detailed Description

Class defining and handling one menu tree.

Definition at line 23 of file AP_Menu.h.

Constructor & Destructor Documentation

◆ Menu()

Menu::Menu ( const char *  prompt,
const struct command commands,
uint8_t  entries,
preprompt  ppfunc = 0 
)

constructor

Note that you should normally not call the constructor directly. Use the MENU and MENU2 macros defined below.

Parameters
promptThe prompt to be displayed with this menu.
commandsAn array of ::command structures in program memory.
entriesThe number of entries in the menu.

Definition at line 21 of file AP_Menu.cpp.

Member Function Documentation

◆ _allocate_buffers()

void Menu::_allocate_buffers ( void  )
private

Definition at line 260 of file AP_Menu.cpp.

Referenced by check_input(), and run().

Here is the caller graph for this function:

◆ _call()

int8_t Menu::_call ( uint8_t  n,
uint8_t  argc 
)
private

calls the function for the n'th menu item

Parameters
nIndex for the menu item to call
argcNumber of arguments prepared for the menu item

Definition at line 235 of file AP_Menu.cpp.

Referenced by _run_command().

Here is the caller graph for this function:

◆ _check_for_input()

bool Menu::_check_for_input ( void  )
private

check for another input byte on the port and accumulate return true if we have a full line ready to process

Definition at line 40 of file AP_Menu.cpp.

Referenced by check_input(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _display_prompt()

void Menu::_display_prompt ( void  )
private

Definition at line 80 of file AP_Menu.cpp.

Referenced by _run_command(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _help()

void Menu::_help ( void  )
private

implements the 'help' command

Implements the default 'help' command.

Definition at line 222 of file AP_Menu.cpp.

Referenced by _run_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _run_command()

bool Menu::_run_command ( bool  prompt_on_enter)
private

Definition at line 87 of file AP_Menu.cpp.

Referenced by check_input(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_input()

bool Menu::check_input ( void  )

check for new input on the port. Can be used to allow for the menu to operate asynchronously this will return true if the user asked to exit the menu

Definition at line 204 of file AP_Menu.cpp.

Here is the call graph for this function:

◆ FUNCTOR_TYPEDEF() [1/2]

Menu::FUNCTOR_TYPEDEF ( func  ,
int8_t  ,
uint8_t  ,
const struct arg  
)

menu command function

Functions called by menu array entries are expected to be of this type.

Parameters
argcThe number of valid arguments, including the name of the command in argv[0]. Will never be more than MENU_ARGS_MAX.
argvPointer to an array of Menu::arg structures detailing any optional arguments given to the command. argv[0] is always the name of the command, so that the same function can be used to handle more than one command.

Referenced by set_port().

Here is the caller graph for this function:

◆ FUNCTOR_TYPEDEF() [2/2]

Menu::FUNCTOR_TYPEDEF ( preprompt  ,
bool   
)

menu pre-prompt function

Called immediately before waiting for the user to type a command; can be used to display help text or status, for example.

If this function returns false, the menu exits.

◆ run()

void Menu::run ( void  )

menu runner

Definition at line 164 of file AP_Menu.cpp.

Here is the call graph for this function:

◆ set_limits()

void Menu::set_limits ( uint8_t  commandline_max,
uint8_t  args_max 
)

set command line length limit

set limits on max args and command line length

Definition at line 244 of file AP_Menu.cpp.

◆ set_port()

static void Menu::set_port ( AP_HAL::BetterStream port)
inlinestatic

Definition at line 56 of file AP_Menu.h.

Referenced by setup().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _args_max

uint8_t Menu::_args_max
private

Definition at line 134 of file AP_Menu.h.

Referenced by _allocate_buffers(), _run_command(), and set_limits().

◆ _argv

Menu::arg * Menu::_argv
staticprivate

arguments

Definition at line 131 of file AP_Menu.h.

Referenced by _allocate_buffers(), _call(), _run_command(), Menu(), and set_limits().

◆ _commandline_max

uint8_t Menu::_commandline_max
private

Definition at line 133 of file AP_Menu.h.

Referenced by _allocate_buffers(), _check_for_input(), and set_limits().

◆ _commands

const command* Menu::_commands
private

array of commands

Definition at line 126 of file AP_Menu.h.

Referenced by _call(), _help(), and _run_command().

◆ _entries

const uint8_t Menu::_entries
private

size of the menu

Definition at line 127 of file AP_Menu.h.

Referenced by _help(), and _run_command().

◆ _inbuf

char * Menu::_inbuf
staticprivate

input buffer

Definition at line 130 of file AP_Menu.h.

Referenced by _allocate_buffers(), _check_for_input(), _run_command(), Menu(), and set_limits().

◆ _input_len

uint8_t Menu::_input_len
private

Definition at line 140 of file AP_Menu.h.

Referenced by _check_for_input(), _run_command(), and run().

◆ _port

AP_HAL::BetterStream * Menu::_port
staticprivate

◆ _ppfunc

const preprompt Menu::_ppfunc
private

optional pre-prompt action

Definition at line 128 of file AP_Menu.h.

Referenced by run().

◆ _prompt

const char* Menu::_prompt
private

prompt to display

Definition at line 125 of file AP_Menu.h.

Referenced by _display_prompt().


The documentation for this class was generated from the following files: