From 9b6fca92144b372fdf79db0a3f8981f5635fb0c2 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 28 Mar 2021 16:39:02 +0200 Subject: [PATCH 1/4] Introduce lcd_show_yes_no_and_wait for future use Split off yes/no lcd handling from lcd_show_fullscreen_message_yes_no_and_wait_P into a separate function in order to allow generic requests where the text prompt can change. --- Firmware/ultralcd.cpp | 22 ++++++++++++++++------ Firmware/ultralcd.h | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a3ee0c45..e7841712 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3579,18 +3579,14 @@ int8_t lcd_show_multiscreen_message_two_choices_and_wait_P(const char *msg, bool } } -//! @brief Show single screen message with yes and no possible choices and wait with possible timeout -//! @param msg Message to show +//! @brief Display and wait for a Yes/No choice using the last two lines of the LCD //! @param allow_timeouting if true, allows time outing of the screen //! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected //! @retval 1 yes choice selected by user //! @retval 0 no choice selected by user //! @retval -1 screen timed out -int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes) +int8_t lcd_show_yes_no_and_wait(bool allow_timeouting, bool default_yes) { - - lcd_display_message_fullscreen_P(msg); - if (default_yes) { lcd_putc_at(0, 2, '>'); lcd_puts_P(_T(MSG_YES)); @@ -3643,6 +3639,20 @@ int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow return retval; } +//! @brief Show single screen message with yes and no possible choices and wait with possible timeout +//! @param msg Message to show +//! @param allow_timeouting if true, allows time outing of the screen +//! @param default_yes if true, yes choice is selected by default, otherwise no choice is preselected +//! @retval 1 yes choice selected by user +//! @retval 0 no choice selected by user +//! @retval -1 screen timed out +//! @relates lcd_show_yes_no_and_wait +int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes) +{ + lcd_display_message_fullscreen_P(msg); + return lcd_show_yes_no_and_wait(allow_timeouting, default_yes); +} + void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask) { const char *msg = NULL; diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 36fcad57..d8ea9b47 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -72,6 +72,8 @@ extern void lcd_wait_for_click(); extern bool lcd_wait_for_click_delay(uint16_t nDelay); extern void lcd_show_fullscreen_message_and_wait_P(const char *msg); // 0: no, 1: yes, -1: timeouted +extern int8_t lcd_show_yes_no_and_wait(bool allow_timeouting = true, bool default_yes = false); +// 0: no, 1: yes, -1: timeouted extern int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting = true, bool default_yes = false); extern int8_t lcd_show_multiscreen_message_two_choices_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes, const char *first_choice, const char *second_choice); From 3a00054c55973ec064858ee39fc5e297ba5359d6 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 28 Mar 2021 16:41:46 +0200 Subject: [PATCH 2/4] Show the axes invoved during crash detection Explicitly show which axes are affected on the status line when a crash has been detected. When the crash recovery prompt is triggered, also show all axes which have been affected during the detection interval (currently X, Y, or both). The timer detection has been simplified to match the MK3 optical filament timeout handling, which makes more sense: a crash immediately following a crash recovery prompt will trigger the prompt again. The timer needs to properly expire in order to reset the crash count. This helps crash detection tuning (and help users reporting issues with crash detection) without having to monitor the serial line. This currently abuses the MSG_CRASH_DETECTED message by prepending the [X][Y] labels to the message, which is ok in english but might not translate that well for all languages. --- Firmware/Marlin_main.cpp | 52 +++++++++++++++++++++++++--------------- Firmware/messages.cpp | 2 +- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b900492b..92e0cd33 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -598,23 +598,18 @@ void crashdet_detected(uint8_t mask) { st_synchronize(); static uint8_t crashDet_counter = 0; + static uint8_t crashDet_axes = 0; bool automatic_recovery_after_crash = true; + char msg[LCD_WIDTH+1] = ""; - if (crashDet_counter++ == 0) { - crashDetTimer.start(); - } - else if (crashDetTimer.expired(CRASHDET_TIMER * 1000ul)){ - crashDetTimer.stop(); - crashDet_counter = 0; - } - else if(crashDet_counter == CRASHDET_COUNTER_MAX){ - automatic_recovery_after_crash = false; - crashDetTimer.stop(); - crashDet_counter = 0; - } - else { - crashDetTimer.start(); - } + if (crashDetTimer.expired(CRASHDET_TIMER * 1000ul)) { + crashDet_counter = 0; + } + if(++crashDet_counter >= CRASHDET_COUNTER_MAX) { + automatic_recovery_after_crash = false; + } + crashDetTimer.start(); + crashDet_axes |= mask; lcd_update_enable(true); lcd_clear(); @@ -624,18 +619,23 @@ void crashdet_detected(uint8_t mask) { eeprom_update_byte((uint8_t*)EEPROM_CRASH_COUNT_X, eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X) + 1); eeprom_update_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT, eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) + 1); + strcat(msg, "X"); } if (mask & Y_AXIS_MASK) { eeprom_update_byte((uint8_t*)EEPROM_CRASH_COUNT_Y, eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y) + 1); eeprom_update_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT, eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) + 1); + strcat(msg, "Y"); } - - lcd_update_enable(true); lcd_update(2); - lcd_setstatuspgm(_T(MSG_CRASH_DETECTED)); + + // prepare the status message with the _current_ axes stauts + strcat(msg, " "); + strcat_P(msg, _T(MSG_CRASH_DETECTED)); + lcd_setstatus(msg); + gcode_G28(true, true, false); //home X and Y st_synchronize(); @@ -643,7 +643,21 @@ void crashdet_detected(uint8_t mask) enquecommand_P(PSTR("CRASH_RECOVER")); }else{ setTargetHotend(0, active_extruder); - bool yesno = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Crash detected. Resume print?"), false);////MSG_CRASH_RESUME c=20 r=3 + + // notify the user of *all* the axes previously affected, not just the last one + lcd_update_enable(false); + lcd_clear(); + if (crashDet_axes & X_AXIS_MASK) lcd_putc('X'); + if (crashDet_axes & Y_AXIS_MASK) lcd_putc('Y'); + crashDet_axes = 0; + lcd_putc(' '); + lcd_puts_P(_T(MSG_CRASH_DETECTED)); + + // ask whether to resume printing + lcd_set_cursor(0, 1); + lcd_puts_P(MSG_RESUME_PRINT); + lcd_putc('?'); + bool yesno = lcd_show_yes_no_and_wait(false); lcd_update_enable(true); if (yesno) { diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 9bf313bb..807bdbb2 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -24,7 +24,7 @@ const char MSG_COMMUNITY_MADE[] PROGMEM_I1 = ISTR("Community made"); ////c=18 const char MSG_CONFIRM_NOZZLE_CLEAN[] PROGMEM_I1 = ISTR("Please clean the nozzle for calibration. Click when done."); ////c=20 r=8 const char MSG_COOLDOWN[] PROGMEM_I1 = ISTR("Cooldown"); ////c=18 const char MSG_CRASH[] PROGMEM_I1 = ISTR("Crash"); ////c=7 -const char MSG_CRASH_DETECTED[] PROGMEM_I1 = ISTR("Crash detected."); ////c=20 +const char MSG_CRASH_DETECTED[] PROGMEM_I1 = ISTR("Crash detected."); ////c=17 r=1 const char MSG_CRASHDETECT[] PROGMEM_I1 = ISTR("Crash det."); ////c=13 const char MSG_ERROR[] PROGMEM_I1 = ISTR("ERROR:"); ////c=10 const char MSG_EXTRUDER[] PROGMEM_I1 = ISTR("Extruder"); ////c=17 From 35a67ad51f38d2256a5eebea60430c6d84c407ab Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 16 Feb 2022 16:23:31 +0100 Subject: [PATCH 3/4] Fix typo --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 92e0cd33..a961099a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -631,7 +631,7 @@ void crashdet_detected(uint8_t mask) lcd_update_enable(true); lcd_update(2); - // prepare the status message with the _current_ axes stauts + // prepare the status message with the _current_ axes status strcat(msg, " "); strcat_P(msg, _T(MSG_CRASH_DETECTED)); lcd_setstatus(msg); From 5b6a057037451c63c6d8846e6b771e62a50ad2a0 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 16 Feb 2022 16:45:06 +0100 Subject: [PATCH 4/4] Reduce duplication and code size --- Firmware/Marlin_main.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a961099a..9f653fc1 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -594,6 +594,14 @@ void crashdet_restore_print_and_continue() // babystep_apply(); } +void crashdet_fmt_error(char* buf, uint8_t mask) +{ + if(mask & X_AXIS_MASK) *buf++ = axis_codes[X_AXIS]; + if(mask & Y_AXIS_MASK) *buf++ = axis_codes[Y_AXIS]; + *buf++ = ' '; + strcpy_P(buf, _T(MSG_CRASH_DETECTED)); +} + void crashdet_detected(uint8_t mask) { st_synchronize(); @@ -619,21 +627,18 @@ void crashdet_detected(uint8_t mask) { eeprom_update_byte((uint8_t*)EEPROM_CRASH_COUNT_X, eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X) + 1); eeprom_update_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT, eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) + 1); - strcat(msg, "X"); } if (mask & Y_AXIS_MASK) { eeprom_update_byte((uint8_t*)EEPROM_CRASH_COUNT_Y, eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y) + 1); eeprom_update_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT, eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) + 1); - strcat(msg, "Y"); } lcd_update_enable(true); lcd_update(2); // prepare the status message with the _current_ axes status - strcat(msg, " "); - strcat_P(msg, _T(MSG_CRASH_DETECTED)); + crashdet_fmt_error(msg, mask); lcd_setstatus(msg); gcode_G28(true, true, false); //home X and Y @@ -647,11 +652,9 @@ void crashdet_detected(uint8_t mask) // notify the user of *all* the axes previously affected, not just the last one lcd_update_enable(false); lcd_clear(); - if (crashDet_axes & X_AXIS_MASK) lcd_putc('X'); - if (crashDet_axes & Y_AXIS_MASK) lcd_putc('Y'); + crashdet_fmt_error(msg, crashDet_axes); crashDet_axes = 0; - lcd_putc(' '); - lcd_puts_P(_T(MSG_CRASH_DETECTED)); + lcd_print(msg); // ask whether to resume printing lcd_set_cursor(0, 1);