menu: add hex and bin arguments

This commit is contained in:
King Kévin 2019-03-26 18:49:48 +01:00
parent a82666e997
commit b4612b03bb
2 changed files with 12 additions and 4 deletions

View File

@ -62,10 +62,16 @@ bool menu_handle_command(const char* line, const struct menu_command_t* command_
if (!word) { // no argument provided
(*command.command_handler)(NULL); // call without argument
} else if (MENU_ARGUMENT_SIGNED == command.argument) { // next argument should be a signed integer
int32_t argument = atoi(word); // get signed integer
int32_t argument = strtol(word, NULL, 10); // get signed integer
(*command.command_handler)(&argument); // call with argument
} else if (MENU_ARGUMENT_UNSIGNED == command.argument) { // next argument should be an unsigned integer
uint32_t argument = atoi(word); // get unsigned integer
uint32_t argument = strtoul(word, NULL, 10); // get unsigned integer
(*command.command_handler)(&argument); // call with argument
} else if (MENU_ARGUMENT_HEX == command.argument) { // next argument should be a hexadecimal
uint32_t argument = strtoul(word, NULL, 16); // get hexadecimal
(*command.command_handler)(&argument); // call with argument
} else if (MENU_ARGUMENT_BINARY == command.argument) { // next argument should be a binry
uint32_t argument = strtoul(word, NULL, 2); // get binary
(*command.command_handler)(&argument); // call with argument
} else if (MENU_ARGUMENT_FLOAT == command.argument) { // next argument should be a floating point number
double argument = atof(word); // get floating point number

View File

@ -22,8 +22,10 @@
/** types of argument accepted by the command */
enum menu_argument_t {
MENU_ARGUMENT_NONE, /**< no argument accepted */
MENU_ARGUMENT_SIGNED, /**< int32 argument accepted */
MENU_ARGUMENT_UNSIGNED, /**< uint32 argument accepted */
MENU_ARGUMENT_SIGNED, /**< int32 decimal argument accepted */
MENU_ARGUMENT_UNSIGNED, /**< uint32 decimal argument accepted */
MENU_ARGUMENT_HEX, /**< uint32 hexadecimal argument accepted */
MENU_ARGUMENT_BINARY, /**< uint32 binary argument accepted */
MENU_ARGUMENT_FLOAT, /**< double argument accepted */
MENU_ARGUMENT_STRING, /**< string argument accepted */
};