ADI console menu library

Committer:
mahphalke
Date:
Sun May 09 22:59:54 2021 +0530
Revision:
4:ced4fa6875ed
Parent:
3:b491377501ce
Added more ANSI VT100 escape sequences

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 4:ced4fa6875ed 33 #define VT100_MOVE_UP_1_LINE "\033[A"
mahphalke 4:ced4fa6875ed 34 #define VT100_MOVE_UP_N_LINES "\x1B[%dA"
mahphalke 4:ced4fa6875ed 35 #define VT100_CLEAR_CURRENT_LINE "\x1B[J"
mahphalke 4:ced4fa6875ed 36 #define VT100_CLEAR_CONSOLE "\x1B[2J"
mahphalke 4:ced4fa6875ed 37 #define VT100_MOVE_TO_HOME "\x1B[H"
mahphalke 3:b491377501ce 38
mahphalke 1:dcc17e5a913f 39 #ifndef ARRAY_SIZE
mahphalke 1:dcc17e5a913f 40 #define ARRAY_SIZE(x) ((sizeof (x)) / (sizeof ((x)[0])))
mahphalke 1:dcc17e5a913f 41 #endif
mahphalke 1:dcc17e5a913f 42
mahphalke 1:dcc17e5a913f 43 /* Type Definitions */
mahphalke 1:dcc17e5a913f 44 // Each menu item is defined by this struct
mahphalke 1:dcc17e5a913f 45 typedef struct {
mahphalke 1:dcc17e5a913f 46 // String displayed for menu item
mahphalke 1:dcc17e5a913f 47 char * text;
mahphalke 1:dcc17e5a913f 48 // character that can be pressed to select menu item
mahphalke 1:dcc17e5a913f 49 char shortcutKey;
mahphalke 1:dcc17e5a913f 50 // Function to be called when menu item is selected, if NULL, no function is called
mahphalke 1:dcc17e5a913f 51 int32_t (*action)(uint32_t option);
mahphalke 1:dcc17e5a913f 52 // id value passed as the option value when calling menuAction
mahphalke 1:dcc17e5a913f 53 uint32_t id;
mahphalke 1:dcc17e5a913f 54 } console_menu_item;
mahphalke 1:dcc17e5a913f 55
mahphalke 1:dcc17e5a913f 56 // This defines a complete menu with items
mahphalke 1:dcc17e5a913f 57 typedef struct {
mahphalke 1:dcc17e5a913f 58 // String to be displayed as the menu title
mahphalke 1:dcc17e5a913f 59 char * title;
mahphalke 1:dcc17e5a913f 60 // Array of all the menu items
mahphalke 1:dcc17e5a913f 61 console_menu_item * items;
mahphalke 1:dcc17e5a913f 62 // Number of menuItems
mahphalke 1:dcc17e5a913f 63 uint8_t itemCount;
mahphalke 1:dcc17e5a913f 64 // Function alled before Menu title is displayed if defined
mahphalke 1:dcc17e5a913f 65 void (*headerItem)(void);
mahphalke 1:dcc17e5a913f 66 // Function called after menu items are displayed if defined
mahphalke 1:dcc17e5a913f 67 void (*footerItem)(void);
mahphalke 1:dcc17e5a913f 68 // Should the escape key to exit the menu be enabled?
mahphalke 1:dcc17e5a913f 69 bool enableEscapeKey;
mahphalke 1:dcc17e5a913f 70 } console_menu;
mahphalke 1:dcc17e5a913f 71
mahphalke 1:dcc17e5a913f 72 /* Function Declarations */
mahphalke 1:dcc17e5a913f 73 /* Display a console menu, and handle user interactions */
mahphalke 1:dcc17e5a913f 74 int32_t adi_do_console_menu(const console_menu * menu);
mahphalke 1:dcc17e5a913f 75 int32_t adi_get_decimal_int(uint8_t input_len);
mahphalke 1:dcc17e5a913f 76 uint32_t adi_get_hex_integer(uint8_t input_len);
mahphalke 1:dcc17e5a913f 77 float adi_get_decimal_float(uint8_t input_len);
mahphalke 1:dcc17e5a913f 78 void adi_clear_console(void);
mahphalke 1:dcc17e5a913f 79 void adi_press_any_key_to_continue(void);
mahphalke 1:dcc17e5a913f 80
mahphalke 1:dcc17e5a913f 81 #endif /* ADI_CONSOLE_MENU_H_ */