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
adi_console_menu.h
00001 /*! 00002 ***************************************************************************** 00003 @file: adi_console_menu.h 00004 00005 @brief: A simple console menu manager handler 00006 00007 @details: 00008 ----------------------------------------------------------------------------- 00009 Copyright (c) 2019-2022 Analog Devices, Inc. 00010 All rights reserved. 00011 00012 This software is proprietary to Analog Devices, Inc. and its licensors. 00013 By using this software you agree to the terms of the associated 00014 Analog Devices Software License Agreement. 00015 00016 *****************************************************************************/ 00017 #ifndef ADI_CONSOLE_MENU_H_ 00018 #define ADI_CONSOLE_MENU_H_ 00019 00020 /******************************************************************************/ 00021 /***************************** Include Files **********************************/ 00022 /******************************************************************************/ 00023 #include <stdbool.h> 00024 #include <stdint.h> 00025 #include <limits.h> 00026 00027 /******************************************************************************/ 00028 /********************** Macros and Constants Definition ***********************/ 00029 /******************************************************************************/ 00030 #define MENU_ESCAPED INT_MAX 00031 #define MENU_CONTINUE INT_MAX-1 00032 #define MENU_DONE INT_MAX-2 00033 00034 #define ESCAPE_KEY_CODE (char)0x1B 00035 00036 #define EOL "\r\n" 00037 00038 /* ANSI VT100 escape sequence codes */ 00039 #define VT100_MOVE_UP_1_LINE "\033[A" 00040 #define VT100_MOVE_UP_N_LINES "\x1B[%dA" 00041 #define VT100_CLEAR_CURRENT_LINE "\x1B[J" 00042 #define VT100_CLEAR_CONSOLE "\x1B[2J" 00043 #define VT100_MOVE_TO_HOME "\x1B[H" 00044 #define VT100_COLORED_TEXT "\x1B[%dm" 00045 00046 #ifndef ARRAY_SIZE 00047 #define ARRAY_SIZE(x) ((sizeof (x)) / (sizeof ((x)[0]))) 00048 #endif 00049 00050 /* ANSI VT100 color codes */ 00051 enum vt100_colors { 00052 VT_FG_DEFAULT = 0, 00053 VT_FG_RED = 31, 00054 VT_FG_GREEN = 32, 00055 VT_FG_YELLOW = 33, 00056 VT_FG_BLUE = 34, 00057 VT_FG_MAGENTA = 35, 00058 VT_FG_CYAN = 36, 00059 VT_FG_WHITE = 37 00060 }; 00061 00062 /******************************************************************************/ 00063 /********************** Variables and User Defined Data Types *****************/ 00064 /******************************************************************************/ 00065 /* This define the state of the console menu library*/ 00066 typedef struct { 00067 // Stores the error code from the last menu action. 00068 int32_t last_error_code; 00069 } console_menu_state; 00070 00071 /* Type Definitions */ 00072 // Each menu item is defined by this struct 00073 typedef struct { 00074 // String displayed for menu item 00075 char * text; 00076 // character that can be pressed to select menu item 00077 char shortcutKey; 00078 // Function to be called when menu item is selected, if NULL, no function is called 00079 int32_t (*action)(uint32_t option); 00080 // Submenu to be called when menu item is selected, if NULL, no sub menu is displayed 00081 struct console_menu *submenu; 00082 // id value passed as the option value when calling menuAction 00083 uint32_t id; 00084 } console_menu_item; 00085 00086 // This defines a complete menu with items 00087 typedef struct { 00088 // String to be displayed as the menu title 00089 char * title; 00090 // Array of all the menu items 00091 console_menu_item * items; 00092 // Number of menuItems 00093 uint8_t itemCount; 00094 // Function alled before Menu title is displayed if defined 00095 void (*headerItem)(void); 00096 // Function called after menu items are displayed if defined 00097 void (*footerItem)(void); 00098 // Should the escape key to exit the menu be enabled? 00099 bool enableEscapeKey; 00100 } console_menu; 00101 00102 /******************************************************************************/ 00103 /***************************** Public Declarations ***************************/ 00104 /******************************************************************************/ 00105 int32_t adi_do_console_menu(const console_menu * menu); 00106 int32_t adi_get_decimal_int(uint8_t input_len); 00107 uint32_t adi_get_hex_integer(uint8_t input_len); 00108 float adi_get_decimal_float(uint8_t input_len); 00109 int32_t adi_handle_user_input_integer(const char* menu_prompt, 00110 uint16_t min_val, 00111 uint16_t max_val, 00112 uint16_t *input_val, 00113 uint8_t input_len, 00114 uint8_t max_attempts, 00115 uint8_t clear_lines); 00116 int32_t adi_handle_user_input_float(const char* menu_prompt, 00117 float min_val, 00118 float max_val, 00119 float *input_val, 00120 uint8_t input_len, 00121 uint8_t max_attempts, 00122 uint8_t clear_lines); 00123 void adi_clear_console(void); 00124 void adi_clear_last_menu_error(void); 00125 int32_t adi_get_last_menu_error(void); 00126 void adi_press_any_key_to_continue(void); 00127 00128 extern console_menu_state adi_console_menu_state; 00129 00130 #endif /* ADI_CONSOLE_MENU_H_ */
Generated on Wed Jul 13 2022 14:24:06 by 1.7.2