precision-converters-firmware
Macros | Functions | Variables
adi_console_menu.c File Reference

: A simple console menu manager handler More...

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include "adi_console_menu.h"
Include dependency graph for adi_console_menu.c:

Macros

#define DIV_STRING   "\t=================================================="
 

Functions

int32_t adi_do_console_menu (const console_menu *menu)
 Display a consoleMenu and handle User interaction. More...
 
int32_t adi_get_decimal_int (uint8_t input_len)
 Reads a decimal string from the user. More...
 
uint32_t adi_get_hex_integer (uint8_t input_len)
 Reads a hexadecimal number from the user. More...
 
float adi_get_decimal_float (uint8_t input_len)
 Reads a floating string from the user. More...
 
int32_t adi_handle_user_input_integer (const char *menu_prompt, uint16_t min_val, uint16_t max_val, uint16_t *input_val, uint8_t input_len, uint8_t max_attempts, uint8_t clear_lines)
 Handles the integer type input from the user by displaying the menu message and provides a set number of input attempts for the user. More...
 
int32_t adi_handle_user_input_float (const char *menu_prompt, float min_val, float max_val, float *input_val, uint8_t input_len, uint8_t max_attempts, uint8_t clear_lines)
 Handles the float type input from the user by displaying the menu message and provides a set number of input attempts for the user. More...
 
void adi_clear_console (void)
 Clears the console terminal. More...
 
void adi_clear_last_menu_error (void)
 Clears the error code from the last menu. More...
 
int32_t adi_get_last_menu_error (void)
 Returns the error code from the last menu. More...
 
void adi_press_any_key_to_continue (void)
 waits for any key to be pressed, and displays a prompt to the user More...
 

Variables

console_menu_state adi_console_menu_state
 

Detailed Description

: A simple console menu manager handler

: A way to define using arrays of structs a set of menus that can be displayed to a user, easily, with all user interaction handled by the library, leaving only the implementation of the menu actions

to be done by the library user.

Copyright (c) 2019-2022 Analog Devices, Inc. All rights reserved.

This software is proprietary to Analog Devices, Inc. and its licensors. By using this software you agree to the terms of the associated Analog Devices Software License Agreement.

Macro Definition Documentation

◆ DIV_STRING

#define DIV_STRING   "\t=================================================="

Function Documentation

◆ adi_clear_console()

void adi_clear_console ( void  )

Clears the console terminal.

Clears the console terminal using VT100 escape code, or can be changed to output blank lines if serial link doesn't support VT100.

Here is the caller graph for this function:

◆ adi_clear_last_menu_error()

void adi_clear_last_menu_error ( void  )

Clears the error code from the last menu.

◆ adi_do_console_menu()

int32_t adi_do_console_menu ( const console_menu menu)

Display a consoleMenu and handle User interaction.

This displays the menuItems defined by the console menu, and handles all user interaction for the menu.

Note
The function will return either the item selected or error code from the last action. One at a time. Either define the menu action or sub menu. If both are defined the function would return error. If both menu action and sub menu are defined NULL, then the function will return the item selected
Here is the caller graph for this function:

◆ adi_get_decimal_float()

float adi_get_decimal_float ( uint8_t  input_len)

Reads a floating string from the user.

Parameters
input_lenmax number of character to accept from the user
Returns
The float value entered

Allows a user to type in number, echoing back to the user, up to input_len chars

Note
Only positive floating point numbers are supported currently
Here is the caller graph for this function:

◆ adi_get_decimal_int()

int32_t adi_get_decimal_int ( uint8_t  input_len)

Reads a decimal string from the user.

Parameters
input_lenmax number of character to accept from the user
Returns
The integer value entered

Allows a user to type in number, echoing back to the user, up to input_len chars

Note
Only positive integer numbers are supported currently
Here is the caller graph for this function:

◆ adi_get_hex_integer()

uint32_t adi_get_hex_integer ( uint8_t  input_len)

Reads a hexadecimal number from the user.

Parameters
input_lenmax number of character to accept from the user
Returns
The integer value entered

Allows a user to type in a hexnumber, echoing back to the user, up to input_len chars

Here is the caller graph for this function:

◆ adi_get_last_menu_error()

int32_t adi_get_last_menu_error ( void  )

Returns the error code from the last menu.

Returns
The error code value

◆ adi_handle_user_input_float()

int32_t adi_handle_user_input_float ( const char *  menu_prompt,
float  min_val,
float  max_val,
float *  input_val,
uint8_t  input_len,
uint8_t  max_attempts,
uint8_t  clear_lines 
)

Handles the float type input from the user by displaying the menu message and provides a set number of input attempts for the user.

Parameters
menu_prompt[in]- User specified prompt.
min_val[in]- minimum input value.
max_val[in]- maximum input value.
input_val[in,out]- User provided input value.
input_len[in]- User provided input length.
max_attempts[in]- Maximum number of input attempts.
clear_lines[in]- lines to clear in case of invalid input.
Returns
0 in case of success. -1 otherwise.

◆ adi_handle_user_input_integer()

int32_t adi_handle_user_input_integer ( const char *  menu_prompt,
uint16_t  min_val,
uint16_t  max_val,
uint16_t *  input_val,
uint8_t  input_len,
uint8_t  max_attempts,
uint8_t  clear_lines 
)

Handles the integer type input from the user by displaying the menu message and provides a set number of input attempts for the user.

Parameters
menu_prompt[in]- User specified prompt.
min_val[in]- minimum input value.
max_val[in]- maximum input value.
input_val[in,out]- User provided input value.
input_len[in]- User provided input length.
max_attempts[in]- Maximum number of input attempts.
clear_lines[in]- lines to clear in case of invalid input.
Returns
0 in case of success. -1 otherwise.

◆ adi_press_any_key_to_continue()

void adi_press_any_key_to_continue ( void  )

waits for any key to be pressed, and displays a prompt to the user

Here is the caller graph for this function:

Variable Documentation

◆ adi_console_menu_state

console_menu_state adi_console_menu_state
Initial value:
= {
.last_error_code = 0
}