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:
mahphalke
Date:
Fri Feb 19 09:25:57 2021 +0000
Revision:
3:b491377501ce
Parent:
1:dcc17e5a913f
Child:
4:ced4fa6875ed
Added ANSI VT100 escape sequence to move cursor one line up

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 -----------------------------------------------------------------------------
mahphalke 3:b491377501ce 9 Copyright (c) 2019-2021 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
mahphalke 1:dcc17e5a913f 18 #ifndef ADI_CONSOLE_MENU_H_
mahphalke 1:dcc17e5a913f 19 #define ADI_CONSOLE_MENU_H_
mahphalke 1:dcc17e5a913f 20
mahphalke 1:dcc17e5a913f 21 #include <stdbool.h>
mahphalke 1:dcc17e5a913f 22 #include <stdint.h>
mahphalke 1:dcc17e5a913f 23
mahphalke 1:dcc17e5a913f 24 #define MENU_ESCAPED -1
mahphalke 1:dcc17e5a913f 25 #define MENU_CONTINUE 0
mahphalke 1:dcc17e5a913f 26 #define MENU_DONE 1
mahphalke 1:dcc17e5a913f 27
mahphalke 1:dcc17e5a913f 28 #define ESCAPE_KEY_CODE (char)0x1B
mahphalke 1:dcc17e5a913f 29
mahphalke 1:dcc17e5a913f 30 #define EOL "\r\n"
mahphalke 1:dcc17e5a913f 31
mahphalke 3:b491377501ce 32 /* ANSI VT100 escape sequence codes */
mahphalke 3:b491377501ce 33 #define VT100_MOVE_UP_1_LINE "\033[A"
mahphalke 3:b491377501ce 34
mahphalke 1:dcc17e5a913f 35 #ifndef ARRAY_SIZE
mahphalke 1:dcc17e5a913f 36 #define ARRAY_SIZE(x) ((sizeof (x)) / (sizeof ((x)[0])))
mahphalke 1:dcc17e5a913f 37 #endif
mahphalke 1:dcc17e5a913f 38
mahphalke 1:dcc17e5a913f 39 /* Type Definitions */
mahphalke 1:dcc17e5a913f 40 // Each menu item is defined by this struct
mahphalke 1:dcc17e5a913f 41 typedef struct {
mahphalke 1:dcc17e5a913f 42 // String displayed for menu item
mahphalke 1:dcc17e5a913f 43 char * text;
mahphalke 1:dcc17e5a913f 44 // character that can be pressed to select menu item
mahphalke 1:dcc17e5a913f 45 char shortcutKey;
mahphalke 1:dcc17e5a913f 46 // Function to be called when menu item is selected, if NULL, no function is called
mahphalke 1:dcc17e5a913f 47 int32_t (*action)(uint32_t option);
mahphalke 1:dcc17e5a913f 48 // id value passed as the option value when calling menuAction
mahphalke 1:dcc17e5a913f 49 uint32_t id;
mahphalke 1:dcc17e5a913f 50 } console_menu_item;
mahphalke 1:dcc17e5a913f 51
mahphalke 1:dcc17e5a913f 52 // This defines a complete menu with items
mahphalke 1:dcc17e5a913f 53 typedef struct {
mahphalke 1:dcc17e5a913f 54 // String to be displayed as the menu title
mahphalke 1:dcc17e5a913f 55 char * title;
mahphalke 1:dcc17e5a913f 56 // Array of all the menu items
mahphalke 1:dcc17e5a913f 57 console_menu_item * items;
mahphalke 1:dcc17e5a913f 58 // Number of menuItems
mahphalke 1:dcc17e5a913f 59 uint8_t itemCount;
mahphalke 1:dcc17e5a913f 60 // Function alled before Menu title is displayed if defined
mahphalke 1:dcc17e5a913f 61 void (*headerItem)(void);
mahphalke 1:dcc17e5a913f 62 // Function called after menu items are displayed if defined
mahphalke 1:dcc17e5a913f 63 void (*footerItem)(void);
mahphalke 1:dcc17e5a913f 64 // Should the escape key to exit the menu be enabled?
mahphalke 1:dcc17e5a913f 65 bool enableEscapeKey;
mahphalke 1:dcc17e5a913f 66 } console_menu;
mahphalke 1:dcc17e5a913f 67
mahphalke 1:dcc17e5a913f 68 /* Function Declarations */
mahphalke 1:dcc17e5a913f 69 /* Display a console menu, and handle user interactions */
mahphalke 1:dcc17e5a913f 70 int32_t adi_do_console_menu(const console_menu * menu);
mahphalke 1:dcc17e5a913f 71 int32_t adi_get_decimal_int(uint8_t input_len);
mahphalke 1:dcc17e5a913f 72 uint32_t adi_get_hex_integer(uint8_t input_len);
mahphalke 1:dcc17e5a913f 73 float adi_get_decimal_float(uint8_t input_len);
mahphalke 1:dcc17e5a913f 74 void adi_clear_console(void);
mahphalke 1:dcc17e5a913f 75 void adi_press_any_key_to_continue(void);
mahphalke 1:dcc17e5a913f 76
mahphalke 1:dcc17e5a913f 77 #endif /* ADI_CONSOLE_MENU_H_ */