Displays user interactions with menus displayed on a console or a serial terminal.
Dependents: EVAL-AD568x-AD569x EVAL-AD7124 EVAL-AD5592R EVAL-AD717x-AD411x ... more
Diff: adi_console_menu.h
- Revision:
- 5:052b9936f41f
- Parent:
- 4:ced4fa6875ed
- Child:
- 6:34034065d24b
--- a/adi_console_menu.h Sun May 09 22:59:54 2021 +0530 +++ b/adi_console_menu.h Fri Dec 03 18:07:28 2021 +0000 @@ -14,16 +14,22 @@ Analog Devices Software License Agreement. *****************************************************************************/ - #ifndef ADI_CONSOLE_MENU_H_ #define ADI_CONSOLE_MENU_H_ +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ #include <stdbool.h> #include <stdint.h> +#include <limits.h> -#define MENU_ESCAPED -1 -#define MENU_CONTINUE 0 -#define MENU_DONE 1 +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ +#define MENU_ESCAPED INT_MAX +#define MENU_CONTINUE INT_MAX-1 +#define MENU_DONE INT_MAX-2 #define ESCAPE_KEY_CODE (char)0x1B @@ -35,11 +41,33 @@ #define VT100_CLEAR_CURRENT_LINE "\x1B[J" #define VT100_CLEAR_CONSOLE "\x1B[2J" #define VT100_MOVE_TO_HOME "\x1B[H" +#define VT100_COLORED_TEXT "\x1B[%dm" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) ((sizeof (x)) / (sizeof ((x)[0]))) #endif +/* ANSI VT100 color codes */ +enum vt100_colors { + VT_FG_DEFAULT = 0, + VT_FG_RED = 31, + VT_FG_GREEN = 32, + VT_FG_YELLOW = 33, + VT_FG_BLUE = 34, + VT_FG_MAGENTA = 35, + VT_FG_CYAN = 36, + VT_FG_WHITE = 37 +}; + +/******************************************************************************/ +/********************** Variables and User Defined Data Types *****************/ +/******************************************************************************/ +/* This define the state of the console menu library*/ +typedef struct { + // Stores the error code from the last menu action. + int32_t last_error_code; +} console_menu_state; + /* Type Definitions */ // Each menu item is defined by this struct typedef struct { @@ -49,6 +77,8 @@ char shortcutKey; // Function to be called when menu item is selected, if NULL, no function is called int32_t (*action)(uint32_t option); + // Submenu to be called when menu item is selected, if NULL, no sub menu is displayed + struct console_menu *submenu; // id value passed as the option value when calling menuAction uint32_t id; } console_menu_item; @@ -69,13 +99,24 @@ bool enableEscapeKey; } console_menu; -/* Function Declarations */ -/* Display a console menu, and handle user interactions */ +/******************************************************************************/ +/***************************** Public Declarations ***************************/ +/******************************************************************************/ int32_t adi_do_console_menu(const console_menu * menu); int32_t adi_get_decimal_int(uint8_t input_len); uint32_t adi_get_hex_integer(uint8_t input_len); float adi_get_decimal_float(uint8_t input_len); +int32_t adi_handle_user_input(const char* menu_prompt, + uint16_t min_val, + uint16_t max_val, + uint16_t *input_val, + uint8_t max_attempts, + uint8_t clear_lines); void adi_clear_console(void); +void adi_clear_last_menu_error(void); +int32_t adi_get_last_menu_error(void); void adi_press_any_key_to_continue(void); +extern console_menu_state adi_console_menu_state; + #endif /* ADI_CONSOLE_MENU_H_ */