Add NUMERIC compare macros to simplify code
This commit is contained in:
parent
2e4ddd5c22
commit
f1ed310322
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue