diff --git a/lib/menu.c b/lib/menu.c index e1bef01..f451352 100644 --- a/lib/menu.c +++ b/lib/menu.c @@ -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 diff --git a/lib/menu.h b/lib/menu.h index 3c7d465..b7aaa1e 100644 --- a/lib/menu.h +++ b/lib/menu.h @@ -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 */ };