From c5e411f49218535cd71c92b26bc226f9a9146e7d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 14 Nov 2020 18:09:17 -0600 Subject: [PATCH] Add parser.is_command(letter, code) --- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/gcode/parser.cpp | 4 ++-- Marlin/src/gcode/parser.h | 5 ++++- Marlin/src/gcode/queue.cpp | 13 ++++++++----- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index ee8aa0bba4..544d7b777d 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -250,7 +250,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { * Will still block Gcodes if M511 is disabled, in which case the printer should be unlocked via LCD Menu */ #if ENABLED(PASSWORD_FEATURE) - if (password.is_locked && !(parser.command_letter == 'M' && parser.codenum == 511)) { + if (password.is_locked && !parser.is_command('M', 511)) { SERIAL_ECHO_MSG(STR_PRINTER_LOCKED); return; } diff --git a/Marlin/src/gcode/parser.cpp b/Marlin/src/gcode/parser.cpp index bba64dbbc4..4bff045e30 100644 --- a/Marlin/src/gcode/parser.cpp +++ b/Marlin/src/gcode/parser.cpp @@ -45,7 +45,7 @@ char *GCodeParser::command_ptr, *GCodeParser::string_arg, *GCodeParser::value_ptr; char GCodeParser::command_letter; -int GCodeParser::codenum; +uint16_t GCodeParser::codenum; #if ENABLED(USE_GCODE_SUBCODES) uint8_t GCodeParser::subcode; @@ -270,7 +270,7 @@ void GCodeParser::parse(char *p) { // Special handling for M32 [P] !/path/to/file.g# // The path must be the last parameter - if (param == '!' && letter == 'M' && codenum == 32) { + if (param == '!' && is_command('M', 32)) { string_arg = p; // Name starts after '!' char * const lb = strchr(p, '#'); // Already seen '#' as SD char (to pause buffering) if (lb) *lb = '\0'; // Safe to mark the end of the filename diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 17fb084388..69bbdaf02d 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -84,7 +84,7 @@ public: static char *command_ptr, // The command, so it can be echoed *string_arg, // string of command line command_letter; // G, M, or T - static int codenum; // 123 + static uint16_t codenum; // 123 #if ENABLED(USE_GCODE_SUBCODES) static uint8_t subcode; // .1 #endif @@ -244,6 +244,9 @@ public: static bool chain(); #endif + // Test whether the parsed command matches the input + static inline bool is_command(const char ltr, const uint16_t num) { return command_letter == ltr && codenum == num; } + // The code value pointer was set FORCE_INLINE static bool has_value() { return !!value_ptr; } diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index f481052cbf..12dfce5111 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -416,11 +416,14 @@ inline void process_stream_char(const char c, uint8_t &sis, char (&buff)[MAX_CMD * keep sensor readings going and watchdog alive. */ inline bool process_line_done(uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind) { - sis = PS_NORMAL; - buff[ind] = 0; - if (ind) { ind = 0; return false; } - thermalManager.manage_heater(); - return true; + sis = PS_NORMAL; // "Normal" Serial Input State + buff[ind] = '\0'; // Of course, I'm a Terminator. + const bool is_empty = (ind == 0); // An empty line? + if (is_empty) + thermalManager.manage_heater(); // Keep sensors satisfied + else + ind = 0; // Start a new line + return is_empty; // Inform the caller } /**