Add parser.is_command(letter, code)

This commit is contained in:
Scott Lahteine 2020-11-14 18:09:17 -06:00
parent 189306d24e
commit c5e411f492
4 changed files with 15 additions and 9 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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; }

View file

@ -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
}
/**