Browse Source

Add parser.is_command(letter, code)

Scott Lahteine 4 years ago
parent
commit
c5e411f492

+ 1
- 1
Marlin/src/gcode/gcode.cpp View File

250
   * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu
250
   * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu
251
   */
251
   */
252
   #if ENABLED(PASSWORD_FEATURE)
252
   #if ENABLED(PASSWORD_FEATURE)
253
-    if (password.is_locked && !(parser.command_letter == 'M' && parser.codenum == 511)) {
253
+    if (password.is_locked && !parser.is_command('M', 511)) {
254
       SERIAL_ECHO_MSG(STR_PRINTER_LOCKED);
254
       SERIAL_ECHO_MSG(STR_PRINTER_LOCKED);
255
       return;
255
       return;
256
     }
256
     }

+ 2
- 2
Marlin/src/gcode/parser.cpp View File

45
      *GCodeParser::string_arg,
45
      *GCodeParser::string_arg,
46
      *GCodeParser::value_ptr;
46
      *GCodeParser::value_ptr;
47
 char GCodeParser::command_letter;
47
 char GCodeParser::command_letter;
48
-int GCodeParser::codenum;
48
+uint16_t GCodeParser::codenum;
49
 
49
 
50
 #if ENABLED(USE_GCODE_SUBCODES)
50
 #if ENABLED(USE_GCODE_SUBCODES)
51
   uint8_t GCodeParser::subcode;
51
   uint8_t GCodeParser::subcode;
270
 
270
 
271
     // Special handling for M32 [P] !/path/to/file.g#
271
     // Special handling for M32 [P] !/path/to/file.g#
272
     // The path must be the last parameter
272
     // The path must be the last parameter
273
-    if (param == '!' && letter == 'M' && codenum == 32) {
273
+    if (param == '!' && is_command('M', 32)) {
274
       string_arg = p;                           // Name starts after '!'
274
       string_arg = p;                           // Name starts after '!'
275
       char * const lb = strchr(p, '#');         // Already seen '#' as SD char (to pause buffering)
275
       char * const lb = strchr(p, '#');         // Already seen '#' as SD char (to pause buffering)
276
       if (lb) *lb = '\0';                       // Safe to mark the end of the filename
276
       if (lb) *lb = '\0';                       // Safe to mark the end of the filename

+ 4
- 1
Marlin/src/gcode/parser.h View File

84
   static char *command_ptr,               // The command, so it can be echoed
84
   static char *command_ptr,               // The command, so it can be echoed
85
               *string_arg,                // string of command line
85
               *string_arg,                // string of command line
86
               command_letter;             // G, M, or T
86
               command_letter;             // G, M, or T
87
-  static int codenum;                     // 123
87
+  static uint16_t codenum;                // 123
88
   #if ENABLED(USE_GCODE_SUBCODES)
88
   #if ENABLED(USE_GCODE_SUBCODES)
89
     static uint8_t subcode;               // .1
89
     static uint8_t subcode;               // .1
90
   #endif
90
   #endif
244
     static bool chain();
244
     static bool chain();
245
   #endif
245
   #endif
246
 
246
 
247
+  // Test whether the parsed command matches the input
248
+  static inline bool is_command(const char ltr, const uint16_t num) { return command_letter == ltr && codenum == num; }
249
+
247
   // The code value pointer was set
250
   // The code value pointer was set
248
   FORCE_INLINE static bool has_value() { return !!value_ptr; }
251
   FORCE_INLINE static bool has_value() { return !!value_ptr; }
249
 
252
 

+ 8
- 5
Marlin/src/gcode/queue.cpp View File

416
  * keep sensor readings going and watchdog alive.
416
  * keep sensor readings going and watchdog alive.
417
  */
417
  */
418
 inline bool process_line_done(uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind) {
418
 inline bool process_line_done(uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind) {
419
-  sis = PS_NORMAL;
420
-  buff[ind] = 0;
421
-  if (ind) { ind = 0; return false; }
422
-  thermalManager.manage_heater();
423
-  return true;
419
+  sis = PS_NORMAL;                    // "Normal" Serial Input State
420
+  buff[ind] = '\0';                   // Of course, I'm a Terminator.
421
+  const bool is_empty = (ind == 0);   // An empty line?
422
+  if (is_empty)
423
+    thermalManager.manage_heater();   // Keep sensors satisfied
424
+  else
425
+    ind = 0;                          // Start a new line
426
+  return is_empty;                    // Inform the caller
424
 }
427
 }
425
 
428
 
426
 /**
429
 /**

Loading…
Cancel
Save