From 5d8eb84965f94c4e0e653dbaabdcb3bcd6f338af Mon Sep 17 00:00:00 2001 From: Vojtech Pavlik Date: Thu, 6 Jun 2019 14:24:34 +0200 Subject: [PATCH 1/3] M0/M1/M117 fix: Move M0/M1 to the top of decoder. Move M0/M1 decoding before any other command. The M0/M1 message can contain arbitrary characters and so it also can contain substrings that other decoders trigger on, like the letter 'G'. Any such substring would cause misdecoding of the M0/M1 and unpredictable behavior in addition to not making the printer stop. M117 already received the same treatment in the past, so we take the same approach for M0/M1. --- Firmware/Marlin_main.cpp | 93 ++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f75b141ff..314514f0a 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3432,6 +3432,52 @@ void process_commands() lcd_setstatus(strchr_pointer + 5); } + else if (code_seen("M0 ") || code_seen("M1 ")) { // M0 and M1 - (Un)conditional stop - Wait for user buttn press on LCD + + char *src = strchr_pointer + 2; + + codenum = 0; + + bool hasP = false, hasS = false; + if (code_seen('P')) { + codenum = code_value(); // milliseconds to wait + hasP = codenum > 0; + } + if (code_seen('S')) { + codenum = code_value() * 1000; // seconds to wait + hasS = codenum > 0; + } + starpos = strchr(src, '*'); + if (starpos != NULL) *(starpos) = '\0'; + while (*src == ' ') ++src; + if (!hasP && !hasS && *src != '\0') { + lcd_setstatus(src); + } else { + LCD_MESSAGERPGM(_i("Wait for user..."));////MSG_USERWAIT + } + + lcd_ignore_click(); //call lcd_ignore_click aslo for else ??? + st_synchronize(); + previous_millis_cmd = _millis(); + if (codenum > 0){ + codenum += _millis(); // keep track of when we started waiting + KEEPALIVE_STATE(PAUSED_FOR_USER); + while(_millis() < codenum && !lcd_clicked()){ + manage_heater(); + manage_inactivity(true); + lcd_update(0); + } + KEEPALIVE_STATE(IN_HANDLER); + lcd_ignore_click(false); + }else{ + marlin_wait_for_click(); + } + if (IS_SD_PRINTING) + LCD_MESSAGERPGM(_T(MSG_RESUMING_PRINT)); + else + LCD_MESSAGERPGM(_T(WELCOME_MSG)); + } + #ifdef TMC2130 else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("CRASH_"), 6) == 0) { @@ -4968,53 +5014,6 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) switch(mcode_in_progress) { - case 0: // M0 - Unconditional stop - Wait for user button press on LCD - case 1: // M1 - Conditional stop - Wait for user button press on LCD - { - char *src = strchr_pointer + 2; - - codenum = 0; - - bool hasP = false, hasS = false; - if (code_seen('P')) { - codenum = code_value(); // milliseconds to wait - hasP = codenum > 0; - } - if (code_seen('S')) { - codenum = code_value() * 1000; // seconds to wait - hasS = codenum > 0; - } - starpos = strchr(src, '*'); - if (starpos != NULL) *(starpos) = '\0'; - while (*src == ' ') ++src; - if (!hasP && !hasS && *src != '\0') { - lcd_setstatus(src); - } else { - LCD_MESSAGERPGM(_i("Wait for user..."));////MSG_USERWAIT - } - - lcd_ignore_click(); //call lcd_ignore_click aslo for else ??? - st_synchronize(); - previous_millis_cmd = _millis(); - if (codenum > 0){ - codenum += _millis(); // keep track of when we started waiting - KEEPALIVE_STATE(PAUSED_FOR_USER); - while(_millis() < codenum && !lcd_clicked()){ - manage_heater(); - manage_inactivity(true); - lcd_update(0); - } - KEEPALIVE_STATE(IN_HANDLER); - lcd_ignore_click(false); - }else{ - marlin_wait_for_click(); - } - if (IS_SD_PRINTING) - LCD_MESSAGERPGM(_T(MSG_RESUMING_PRINT)); - else - LCD_MESSAGERPGM(_T(WELCOME_MSG)); - } - break; case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE enable_x(); From 5494f2394286a9b177a09da02e5957e3efdf8b8a Mon Sep 17 00:00:00 2001 From: Vojtech Pavlik Date: Thu, 6 Jun 2019 14:25:06 +0200 Subject: [PATCH 2/3] M0/M1/M117 fix: Add new CUSTOM_MSG states. When the printer prints from a SD card, the display of progress messages and filename takes precedence over CUSTOM_MSG_TYPE_STATUS messages used by M0/M1/M117. Let's introduce two new CUSTOM_MSG states, one that overrides the SD status while waiting in M0/M1 (M0WAIT) and one that ensures the message will be displayed in at least one screen update (MSGUPD). --- Firmware/ultralcd.cpp | 3 +++ Firmware/ultralcd.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3b2be088a..5d23acf64 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -794,7 +794,10 @@ void lcdui_print_status_line(void) { // Otherwise check for other special events switch (custom_message_type) { + case CUSTOM_MSG_TYPE_MSGUPD: + custom_message_type = CUSTOM_MSG_TYPE_STATUS; case CUSTOM_MSG_TYPE_STATUS: // Nothing special, print status message normally + case CUSTOM_MSG_TYPE_M0WAIT: lcd_print(lcd_status_message); break; case CUSTOM_MSG_TYPE_MESHBL: // If mesh bed leveling in progress, show the status diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 665c1233f..27b1c23ae 100644 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -106,6 +106,8 @@ extern int8_t FSensorStateMenu; #define CUSTOM_MSG_TYPE_PIDCAL 3 // PID tuning in progress #define CUSTOM_MSG_TYPE_TEMCAL 4 // PINDA temp calibration #define CUSTOM_MSG_TYPE_TEMPRE 5 // Temp compensation preheat +#define CUSTOM_MSG_TYPE_M0WAIT 6 // M0/M1 Wait command working even from SD +#define CUSTOM_MSG_TYPE_MSGUPD 7 // Short message even while printing from SD extern unsigned int custom_message_type; extern unsigned int custom_message_state; From a4bc91ed2f1c8b79ca5e0cd6d629898d945fbd39 Mon Sep 17 00:00:00 2001 From: Vojtech Pavlik Date: Thu, 6 Jun 2019 14:25:36 +0200 Subject: [PATCH 3/3] M0/M1/M117 fix: Use CUSTOM_MSG states in M0/1/M117 Now that we have the new CUSTOM_MSG states, we can use them in the M0/M1 and M117 handlers to force the user message to be displayed even when the printer is printing from a SD card and displaying a file name. --- Firmware/Marlin_main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 314514f0a..586bdbe97 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3430,6 +3430,7 @@ void process_commands() if (starpos != NULL) *(starpos) = '\0'; lcd_setstatus(strchr_pointer + 5); + custom_message_type = CUSTOM_MSG_TYPE_MSGUPD; } else if (code_seen("M0 ") || code_seen("M1 ")) { // M0 and M1 - (Un)conditional stop - Wait for user buttn press on LCD @@ -3450,6 +3451,7 @@ void process_commands() starpos = strchr(src, '*'); if (starpos != NULL) *(starpos) = '\0'; while (*src == ' ') ++src; + custom_message_type = CUSTOM_MSG_TYPE_M0WAIT; if (!hasP && !hasS && *src != '\0') { lcd_setstatus(src); } else { @@ -3476,6 +3478,7 @@ void process_commands() LCD_MESSAGERPGM(_T(MSG_RESUMING_PRINT)); else LCD_MESSAGERPGM(_T(WELCOME_MSG)); + custom_message_type = CUSTOM_MSG_TYPE_MSGUPD; } #ifdef TMC2130