123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #pragma once
- #include <inttypes.h>
- #include <AP_HAL/AP_HAL.h>
- #define MENU_COMMANDLINE_MAX 32
- #define MENU_ARGS_MAX 3
- #define MENU_COMMAND_MAX 14
- class Menu {
- public:
-
-
-
-
-
-
-
-
-
- struct arg {
- const char *str;
- long i;
- float f;
- };
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- FUNCTOR_TYPEDEF(func, int8_t, uint8_t, const struct arg *);
- static void set_port(AP_HAL::BetterStream *port) {
- _port = port;
- }
-
-
-
-
-
-
-
- FUNCTOR_TYPEDEF(preprompt, bool);
-
-
- struct command {
-
-
-
- const char command[MENU_COMMAND_MAX];
-
-
-
-
-
-
-
-
-
-
-
- FUNCTOR_DECLARE(func, int8_t, uint8_t, const struct arg *);
- };
-
-
-
-
-
-
-
-
-
- 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);
-
- void run(void);
-
-
-
- bool check_input(void);
- private:
-
-
- void _help(void);
-
-
-
-
-
- int8_t _call(uint8_t n, uint8_t argc);
- const char * _prompt;
- const command * _commands;
- const uint8_t _entries;
- const preprompt _ppfunc;
- static char *_inbuf;
- static arg *_argv;
- uint8_t _commandline_max;
- uint8_t _args_max;
-
- void _allocate_buffers(void);
-
- uint8_t _input_len;
-
- bool _check_for_input(void);
-
-
- bool _run_command(bool prompt_on_enter);
- void _display_prompt();
-
-
- static AP_HAL::BetterStream *_port;
- };
- #define MENU(name, prompt, commands) \
- static const char __menu_name__ ## name[] = prompt; \
- static Menu name(__menu_name__ ## name, commands, ARRAY_SIZE(commands))
- #define MENU2(name, prompt, commands, preprompt) \
- static const char __menu_name__ ## name[] = prompt; \
- static Menu name(__menu_name__ ## name, commands, ARRAY_SIZE(commands), preprompt)
|