diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 38eef424c5..d08f925cc7 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1060,7 +1060,7 @@ bool code_has_value() { while (c == ' ') c = seen_pointer[++i]; if (c == '-' || c == '+') c = seen_pointer[++i]; if (c == '.') c = seen_pointer[++i]; - return (c >= '0' && c <= '9'); + return NUMERIC(c); } float code_value() { @@ -6066,9 +6066,9 @@ void process_next_command() { // - Bypass N[-0-9][0-9]*[ ]* // - Overwrite * with nul to mark the end while (*current_command == ' ') ++current_command; - if (*current_command == 'N' && ((current_command[1] >= '0' && current_command[1] <= '9') || current_command[1] == '-')) { + if (*current_command == 'N' && NUMERIC_SIGNED(current_command[1])) { current_command += 2; // skip N[-0-9] - while (*current_command >= '0' && *current_command <= '9') ++current_command; // skip [0-9]* + while (NUMERIC(*current_command)) ++current_command; // skip [0-9]* while (*current_command == ' ') ++current_command; // skip [ ]* } char* starpos = strchr(current_command, '*'); // * should always be the last parameter @@ -6668,7 +6668,7 @@ void ok_to_send() { if (*p == 'N') { SERIAL_PROTOCOL(' '); SERIAL_ECHO(*p++); - while ((*p >= '0' && *p <= '9') || *p == '-') + while (NUMERIC_SIGNED(*p)) SERIAL_ECHO(*p++); } SERIAL_PROTOCOLPGM(" P"); SERIAL_PROTOCOL(int(BLOCK_BUFFER_SIZE - movesplanned() - 1)); diff --git a/Marlin/macros.h b/Marlin/macros.h index 966fc48d02..c2ff0044f5 100644 --- a/Marlin/macros.h +++ b/Marlin/macros.h @@ -51,6 +51,8 @@ #define ENABLED(b) _CAT(SWITCH_ENABLED_, b) #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b)) +#define NUMERIC(a) ((a) >= '0' && '9' >= (a)) +#define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-') #define COUNT(a) (sizeof(a)/sizeof(*a)) #endif //__MACROS_H