Go to the documentation of this file.00001
00002
00015
00016 #ifndef __AP_COMMON_MENU_H
00017 #define __AP_COMMON_MENU_H
00018
00019 #define MENU_COMMANDLINE_MAX 32 ///< maximum input line length
00020 #define MENU_ARGS_MAX 4 ///< maximum number of arguments
00021 #define MENU_COMMAND_MAX 14 ///< maximum size of a command name
00022
00024 class Menu {
00025 public:
00035 struct arg {
00036 const char *str;
00037 long i;
00038 float f;
00039 };
00040
00055 typedef int8_t (*func)(uint8_t argc, const struct arg *argv);
00056
00064 typedef bool (*preprompt)(void);
00065
00068 struct command {
00072 const char command[MENU_COMMAND_MAX];
00073
00085 int8_t (*func)(uint8_t argc, const struct arg *argv);
00086 };
00087
00097 Menu(const char *prompt, const struct command *commands, uint8_t entries, preprompt ppfunc = 0);
00098
00100 void run(void);
00101
00102 private:
00105 void _help(void);
00106
00112 int8_t _call(uint8_t n, uint8_t argc);
00113
00114 const char *_prompt;
00115 const command *_commands;
00116 const uint8_t _entries;
00117 const preprompt _ppfunc;
00118
00119 static char _inbuf[MENU_COMMANDLINE_MAX];
00120 static arg _argv[MENU_ARGS_MAX + 1];
00121 };
00122
00133 #define MENU(name, prompt, commands) \
00134 static const char __menu_name__ ##name[] PROGMEM = prompt; \
00135 static Menu name(__menu_name__ ##name, commands, sizeof(commands) / sizeof(commands[0]))
00136
00137 #define MENU2(name, prompt, commands, preprompt) \
00138 static const char __menu_name__ ##name[] PROGMEM = prompt; \
00139 static Menu name(__menu_name__ ##name, commands, sizeof(commands) / sizeof(commands[0]), preprompt)
00140
00141 #endif