Przeglądaj źródła

Add parser.is_command(letter, code)

Scott Lahteine 3 lat temu
rodzic
commit
c5e411f492

+ 1
- 1
Marlin/src/gcode/gcode.cpp Wyświetl plik

@@ -250,7 +250,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
250 250
   * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu
251 251
   */
252 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 254
       SERIAL_ECHO_MSG(STR_PRINTER_LOCKED);
255 255
       return;
256 256
     }

+ 2
- 2
Marlin/src/gcode/parser.cpp Wyświetl plik

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

+ 4
- 1
Marlin/src/gcode/parser.h Wyświetl plik

@@ -84,7 +84,7 @@ public:
84 84
   static char *command_ptr,               // The command, so it can be echoed
85 85
               *string_arg,                // string of command line
86 86
               command_letter;             // G, M, or T
87
-  static int codenum;                     // 123
87
+  static uint16_t codenum;                // 123
88 88
   #if ENABLED(USE_GCODE_SUBCODES)
89 89
     static uint8_t subcode;               // .1
90 90
   #endif
@@ -244,6 +244,9 @@ public:
244 244
     static bool chain();
245 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 250
   // The code value pointer was set
248 251
   FORCE_INLINE static bool has_value() { return !!value_ptr; }
249 252
 

+ 8
- 5
Marlin/src/gcode/queue.cpp Wyświetl plik

@@ -416,11 +416,14 @@ inline void process_stream_char(const char c, uint8_t &sis, char (&buff)[MAX_CMD
416 416
  * keep sensor readings going and watchdog alive.
417 417
  */
418 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
 /**

Ładowanie…
Anuluj
Zapisz