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

Committer:
pmallick
Date:
Mon May 09 09:54:26 2022 +0530
Revision:
9:dee92955bc3d
Parent:
7:49c1587ecd29
* Missed out change from the last commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mahphalke 1:dcc17e5a913f 1 /*!
mahphalke 1:dcc17e5a913f 2 *****************************************************************************
mahphalke 1:dcc17e5a913f 3 @file: adi_console_menu.h
mahphalke 1:dcc17e5a913f 4
mahphalke 1:dcc17e5a913f 5 @brief: A simple console menu manager handler
mahphalke 1:dcc17e5a913f 6
mahphalke 1:dcc17e5a913f 7 @details:
mahphalke 1:dcc17e5a913f 8 -----------------------------------------------------------------------------
pmallick 7:49c1587ecd29 9 Copyright (c) 2019-2022 Analog Devices, Inc.
mahphalke 1:dcc17e5a913f 10 All rights reserved.
mahphalke 1:dcc17e5a913f 11
mahphalke 1:dcc17e5a913f 12 This software is proprietary to Analog Devices, Inc. and its licensors.
mahphalke 1:dcc17e5a913f 13 By using this software you agree to the terms of the associated
mahphalke 1:dcc17e5a913f 14 Analog Devices Software License Agreement.
mahphalke 1:dcc17e5a913f 15
mahphalke 1:dcc17e5a913f 16 *****************************************************************************/
mahphalke 1:dcc17e5a913f 17 #ifndef ADI_CONSOLE_MENU_H_
mahphalke 1:dcc17e5a913f 18 #define ADI_CONSOLE_MENU_H_
mahphalke 1:dcc17e5a913f 19
Kjansen 5:052b9936f41f 20 /******************************************************************************/
Kjansen 5:052b9936f41f 21 /***************************** Include Files **********************************/
Kjansen 5:052b9936f41f 22 /******************************************************************************/
mahphalke 1:dcc17e5a913f 23 #include <stdbool.h>
mahphalke 1:dcc17e5a913f 24 #include <stdint.h>
Kjansen 5:052b9936f41f 25 #include <limits.h>
mahphalke 1:dcc17e5a913f 26
Kjansen 5:052b9936f41f 27 /******************************************************************************/
Kjansen 5:052b9936f41f 28 /********************** Macros and Constants Definition ***********************/
Kjansen 5:052b9936f41f 29 /******************************************************************************/
Kjansen 5:052b9936f41f 30 #define MENU_ESCAPED INT_MAX
Kjansen 5:052b9936f41f 31 #define MENU_CONTINUE INT_MAX-1
Kjansen 5:052b9936f41f 32 #define MENU_DONE INT_MAX-2
mahphalke 1:dcc17e5a913f 33
mahphalke 1:dcc17e5a913f 34 #define ESCAPE_KEY_CODE (char)0x1B
mahphalke 1:dcc17e5a913f 35
mahphalke 1:dcc17e5a913f 36 #define EOL "\r\n"
mahphalke 1:dcc17e5a913f 37
mahphalke 3:b491377501ce 38 /* ANSI VT100 escape sequence codes */
mahphalke 4:ced4fa6875ed 39 #define VT100_MOVE_UP_1_LINE "\033[A"
mahphalke 4:ced4fa6875ed 40 #define VT100_MOVE_UP_N_LINES "\x1B[%dA"
mahphalke 4:ced4fa6875ed 41 #define VT100_CLEAR_CURRENT_LINE "\x1B[J"
mahphalke 4:ced4fa6875ed 42 #define VT100_CLEAR_CONSOLE "\x1B[2J"
mahphalke 4:ced4fa6875ed 43 #define VT100_MOVE_TO_HOME "\x1B[H"
Kjansen 5:052b9936f41f 44 #define VT100_COLORED_TEXT "\x1B[%dm"
mahphalke 3:b491377501ce 45
mahphalke 1:dcc17e5a913f 46 #ifndef ARRAY_SIZE
mahphalke 1:dcc17e5a913f 47 #define ARRAY_SIZE(x) ((sizeof (x)) / (sizeof ((x)[0])))
mahphalke 1:dcc17e5a913f 48 #endif
mahphalke 1:dcc17e5a913f 49
Kjansen 5:052b9936f41f 50 /* ANSI VT100 color codes */
Kjansen 5:052b9936f41f 51 enum vt100_colors {
Kjansen 5:052b9936f41f 52 VT_FG_DEFAULT = 0,
Kjansen 5:052b9936f41f 53 VT_FG_RED = 31,
Kjansen 5:052b9936f41f 54 VT_FG_GREEN = 32,
Kjansen 5:052b9936f41f 55 VT_FG_YELLOW = 33,
Kjansen 5:052b9936f41f 56 VT_FG_BLUE = 34,
Kjansen 5:052b9936f41f 57 VT_FG_MAGENTA = 35,
Kjansen 5:052b9936f41f 58 VT_FG_CYAN = 36,
Kjansen 5:052b9936f41f 59 VT_FG_WHITE = 37
Kjansen 5:052b9936f41f 60 };
Kjansen 5:052b9936f41f 61
Kjansen 5:052b9936f41f 62 /******************************************************************************/
Kjansen 5:052b9936f41f 63 /********************** Variables and User Defined Data Types *****************/
Kjansen 5:052b9936f41f 64 /******************************************************************************/
Kjansen 5:052b9936f41f 65 /* This define the state of the console menu library*/
Kjansen 5:052b9936f41f 66 typedef struct {
Kjansen 5:052b9936f41f 67 // Stores the error code from the last menu action.
Kjansen 5:052b9936f41f 68 int32_t last_error_code;
Kjansen 5:052b9936f41f 69 } console_menu_state;
Kjansen 5:052b9936f41f 70
mahphalke 1:dcc17e5a913f 71 /* Type Definitions */
mahphalke 1:dcc17e5a913f 72 // Each menu item is defined by this struct
mahphalke 1:dcc17e5a913f 73 typedef struct {
mahphalke 1:dcc17e5a913f 74 // String displayed for menu item
mahphalke 1:dcc17e5a913f 75 char * text;
mahphalke 1:dcc17e5a913f 76 // character that can be pressed to select menu item
mahphalke 1:dcc17e5a913f 77 char shortcutKey;
mahphalke 1:dcc17e5a913f 78 // Function to be called when menu item is selected, if NULL, no function is called
mahphalke 1:dcc17e5a913f 79 int32_t (*action)(uint32_t option);
Kjansen 5:052b9936f41f 80 // Submenu to be called when menu item is selected, if NULL, no sub menu is displayed
Kjansen 5:052b9936f41f 81 struct console_menu *submenu;
mahphalke 1:dcc17e5a913f 82 // id value passed as the option value when calling menuAction
mahphalke 1:dcc17e5a913f 83 uint32_t id;
mahphalke 1:dcc17e5a913f 84 } console_menu_item;
mahphalke 1:dcc17e5a913f 85
mahphalke 1:dcc17e5a913f 86 // This defines a complete menu with items
mahphalke 1:dcc17e5a913f 87 typedef struct {
mahphalke 1:dcc17e5a913f 88 // String to be displayed as the menu title
mahphalke 1:dcc17e5a913f 89 char * title;
mahphalke 1:dcc17e5a913f 90 // Array of all the menu items
mahphalke 1:dcc17e5a913f 91 console_menu_item * items;
mahphalke 1:dcc17e5a913f 92 // Number of menuItems
mahphalke 1:dcc17e5a913f 93 uint8_t itemCount;
mahphalke 1:dcc17e5a913f 94 // Function alled before Menu title is displayed if defined
mahphalke 1:dcc17e5a913f 95 void (*headerItem)(void);
mahphalke 1:dcc17e5a913f 96 // Function called after menu items are displayed if defined
mahphalke 1:dcc17e5a913f 97 void (*footerItem)(void);
mahphalke 1:dcc17e5a913f 98 // Should the escape key to exit the menu be enabled?
mahphalke 1:dcc17e5a913f 99 bool enableEscapeKey;
mahphalke 1:dcc17e5a913f 100 } console_menu;
mahphalke 1:dcc17e5a913f 101
Kjansen 5:052b9936f41f 102 /******************************************************************************/
Kjansen 5:052b9936f41f 103 /***************************** Public Declarations ***************************/
Kjansen 5:052b9936f41f 104 /******************************************************************************/
mahphalke 1:dcc17e5a913f 105 int32_t adi_do_console_menu(const console_menu * menu);
mahphalke 1:dcc17e5a913f 106 int32_t adi_get_decimal_int(uint8_t input_len);
mahphalke 1:dcc17e5a913f 107 uint32_t adi_get_hex_integer(uint8_t input_len);
mahphalke 1:dcc17e5a913f 108 float adi_get_decimal_float(uint8_t input_len);
pmallick 6:34034065d24b 109 int32_t adi_handle_user_input_integer(const char* menu_prompt,
pmallick 6:34034065d24b 110 uint16_t min_val,
pmallick 6:34034065d24b 111 uint16_t max_val,
pmallick 6:34034065d24b 112 uint16_t *input_val,
pmallick 6:34034065d24b 113 uint8_t input_len,
pmallick 6:34034065d24b 114 uint8_t max_attempts,
pmallick 6:34034065d24b 115 uint8_t clear_lines);
pmallick 6:34034065d24b 116 int32_t adi_handle_user_input_float(const char* menu_prompt,
pmallick 6:34034065d24b 117 float min_val,
pmallick 6:34034065d24b 118 float max_val,
pmallick 6:34034065d24b 119 float *input_val,
pmallick 6:34034065d24b 120 uint8_t input_len,
pmallick 6:34034065d24b 121 uint8_t max_attempts,
pmallick 6:34034065d24b 122 uint8_t clear_lines);
mahphalke 1:dcc17e5a913f 123 void adi_clear_console(void);
Kjansen 5:052b9936f41f 124 void adi_clear_last_menu_error(void);
Kjansen 5:052b9936f41f 125 int32_t adi_get_last_menu_error(void);
mahphalke 1:dcc17e5a913f 126 void adi_press_any_key_to_continue(void);
mahphalke 1:dcc17e5a913f 127
Kjansen 5:052b9936f41f 128 extern console_menu_state adi_console_menu_state;
Kjansen 5:052b9936f41f 129
mahphalke 1:dcc17e5a913f 130 #endif /* ADI_CONSOLE_MENU_H_ */