Bladeren bron

Fix has_value with FASTER_GCODE_PARSER

Scott Lahteine 7 jaren geleden
bovenliggende
commit
399bca316a
2 gewijzigde bestanden met toevoegingen van 16 en 11 verwijderingen
  1. 1
    8
      Marlin/src/gcode/parser.cpp
  2. 15
    3
      Marlin/src/gcode/parser.h

+ 1
- 8
Marlin/src/gcode/parser.cpp Bestand weergeven

@@ -196,14 +196,7 @@ void GCodeParser::parse(char *p) {
196 196
 
197 197
       while (*p == ' ') p++;                    // Skip spaces between parameters & values
198 198
 
199
-      const bool has_num = NUMERIC(p[0])                            // [0-9]
200
-                        || (p[0] == '.' && NUMERIC(p[1]))           // .[0-9]
201
-                        || (
202
-                              (p[0] == '-' || p[0] == '+') && (     // [-+]
203
-                                NUMERIC(p[1])                       //     [0-9]
204
-                                || (p[1] == '.' && NUMERIC(p[2]))   //     .[0-9]
205
-                              )
206
-                            );
199
+      const bool has_num = valid_float(p);
207 200
 
208 201
       #if ENABLED(DEBUG_GCODE_PARSER)
209 202
         if (debug) {

+ 15
- 3
Marlin/src/gcode/parser.h Bestand weergeven

@@ -92,6 +92,18 @@ public:
92 92
 
93 93
   #if ENABLED(FASTER_GCODE_PARSER)
94 94
 
95
+    FORCE_INLINE static bool valid_signless(const char * const p) {
96
+      return NUMERIC(p[0]) || (p[0] == '.' && NUMERIC(p[1])); // .?[0-9]
97
+    }
98
+
99
+    FORCE_INLINE static bool valid_float(const char * const p) {
100
+      return valid_signless(p) || ((p[0] == '-' || p[0] == '+') && valid_signless(&p[1])); // [-+]?.?[0-9]
101
+    }
102
+
103
+    FORCE_INLINE static bool valid_int(const char * const p) {
104
+      return NUMERIC(p[0]) || ((p[0] == '-' || p[0] == '+') && NUMERIC(p[1])); // [-+]?[0-9]
105
+    }
106
+
95 107
     // Set the flag and pointer for a parameter
96 108
     static void set(const char c, char * const ptr) {
97 109
       const uint8_t ind = LETTER_BIT(c);
@@ -130,9 +142,9 @@ public:
130 142
     // Code is found in the string. If not found, value_ptr is unchanged.
131 143
     // This allows "if (seen('A')||seen('B'))" to use the last-found value.
132 144
     static bool seen(const char c) {
133
-      char *p = strchr(command_args, c);
145
+      const char *p = strchr(command_args, c);
134 146
       const bool b = !!p;
135
-      if (b) value_ptr = DECIMAL_SIGNED(p[1]) ? &p[1] : (char*)NULL;
147
+      if (b) value_ptr = valid_float(&p[1]) ? &p[1] : (char*)NULL;
136 148
       return b;
137 149
     }
138 150
 
@@ -196,7 +208,7 @@ public:
196 208
   inline static uint8_t value_byte() { return (uint8_t)constrain(value_long(), 0, 255); }
197 209
 
198 210
   // Bool is true with no value or non-zero
199
-  inline static bool value_bool() { return !has_value() || value_byte(); }
211
+  inline static bool value_bool() { return !has_value() || !!value_byte(); }
200 212
 
201 213
   // Units modes: Inches, Fahrenheit, Kelvin
202 214
 

Laden…
Annuleren
Opslaan