From b9fc73c4c360ecc743771dc47c64bc77e74d68c1 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 7 Jul 2022 10:12:57 +0200 Subject: [PATCH] TM: Pause the print and allow recovery from a thermal error Do not allow resuming until all thermal and fan errors are clear. Call the appropriate resume function when resuming a printing depending on the saved_print state (is saved_print is available, then we always need to resume from the saved state even when printing via usb). Clear the Stopped state when resuming, so that commands can be accepted again. --- Firmware/Marlin_main.cpp | 16 ++++++++++++---- Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + Firmware/temperature.cpp | 12 ++++++++++-- Firmware/temperature.h | 1 + Firmware/ultralcd.cpp | 31 +++++++++++++++++++++++-------- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 194d9083..f83d3c79 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9989,7 +9989,7 @@ void ThermalStop(bool pause) Stopped = true; if(pause && (IS_SD_PRINTING || usb_timer.running())) { if (!isPrintPaused) { - // we cannot make a distinction for an host here, the pause must be instantaneous + // we cannot make a distinction for the host here, the pause must be instantaneous lcd_pause_print(); } } else { @@ -10005,7 +10005,9 @@ void ThermalStop(bool pause) // higher-priority alert status message) LCD_MESSAGERPGM(_T(MSG_STOPPED)); - Sound_MakeCustom(1000,0,true); + // Make a warning sound! We cannot use Sound_MakeCustom as this would stop further moves. + // Turn on the speaker here (if not already), and turn it off when back in the main loop. + WRITE(BEEPER, HIGH); } // Return to the status screen to stop any pending menu action which could have been @@ -10857,8 +10859,14 @@ void long_pause() //long pause print plan_buffer_line_curposXYZE(50); } - // Turn off the print fan - fanSpeed = 0; + // did we come here from a thermal error? + if(get_temp_error()) { + // time to stop the error beep + WRITE(BEEPER, LOW); + } else { + // Turn off the print fan + fanSpeed = 0; + } } void serialecho_temperatures() { diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 66ada492..2b5e21d6 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -161,6 +161,7 @@ const char MSG_IR_UNKNOWN[] PROGMEM_I1 = ISTR("unknown state");////MSG_IR_UNKNOW #endif #ifdef TEMP_MODEL extern const char MSG_THERMAL_ANOMALY[] PROGMEM_I1 = ISTR("THERMAL ANOMALY");////c=20 +extern const char MSG_PAUSED_THERMAL_ERROR[] PROGMEM_I1 = ISTR("PAUSED THERMAL ERROR");////c=20 #endif //not internationalized messages diff --git a/Firmware/messages.h b/Firmware/messages.h index b5116776..1cfbe6c3 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -170,6 +170,7 @@ extern const char MSG_IR_UNKNOWN[]; #endif #ifdef TEMP_MODEL extern const char MSG_THERMAL_ANOMALY[]; +extern const char MSG_PAUSED_THERMAL_ERROR[]; #endif //not internationalized messages diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 042d3d30..4a7aeca1 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -512,6 +512,11 @@ void set_temp_error(TempErrorSource source, uint8_t index, TempErrorType type) temp_error_state.assert = true; } +bool get_temp_error() +{ + return temp_error_state.v; +} + void handle_temp_error(); void manage_heater() @@ -1751,8 +1756,11 @@ void handle_temp_error() #ifdef TEMP_MODEL case TempErrorType::model: if(temp_error_state.assert) { - // TODO: do something meaningful - SERIAL_ECHOLNPGM("TM: error triggered!"); + if(IsStopped() == false) { + lcd_setalertstatuspgm(MSG_PAUSED_THERMAL_ERROR, LCD_STATUS_CRITICAL); + SERIAL_ECHOLNPGM("TM: error triggered!"); + } + ThermalStop(true); WRITE(BEEPER, HIGH); } else { temp_error_state.v = 0; diff --git a/Firmware/temperature.h b/Firmware/temperature.h index bae77091..57116578 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -42,6 +42,7 @@ void soft_pwm_init(); //initialize the soft pwm isr void temp_mgr_init(); //initialize the temperature handler void manage_heater(); //it is critical that this is called periodically. +bool get_temp_error(); //return true if any thermal error is set extern bool checkAllHotends(void); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a7add6ff..e2e1a468 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5698,16 +5698,20 @@ static bool fan_error_selftest() void lcd_resume_print() { lcd_return_to_status(); - lcd_reset_alert_level(); //for fan speed error - if (fan_error_selftest()) { + lcd_reset_alert_level(); + + // ensure thermal issues (temp or fan) are resolved before we allow to resume + if (get_temp_error() || fan_error_selftest()) { if (usb_timer.running()) SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); - return; //abort if error persists + return; // abort if error persists } + cmdqueue_serial_disabled = false; lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS)); st_synchronize(); custom_message_type = CustomMsg::Resuming; isPrintPaused = false; + Stopped = false; // resume processing USB commands again restore_print_from_ram_and_continue(default_retraction); pause_time += (_millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation refresh_cmd_timeout(); @@ -5899,14 +5903,16 @@ static void lcd_main_menu() } if(isPrintPaused) { + // only allow resuming if hardware errors (temperature or fan) are cleared + if(!get_temp_error() #ifdef FANCHECK - if((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK)) + && ((fan_check_error == EFCE_FIXED) || (fan_check_error == EFCE_OK)) #endif //FANCHECK - { - if (usb_timer.running()) { - MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print); - } else { + ) { + if (saved_printing) { MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_print); + } else { + MENU_ITEM_SUBMENU_P(_T(MSG_RESUME_PRINT), lcd_resume_usb_print); } } } @@ -6332,6 +6338,15 @@ void print_stop() } st_synchronize(); + // did we come here from a thermal error? + if(get_temp_error()) { + // time to stop the error beep + WRITE(BEEPER, LOW); + } else { + // Turn off the print fan + fanSpeed = 0; + } + if (mmu_enabled) extr_unload(); //M702 C finishAndDisableSteppers(); //M84 axis_relative_modes = E_AXIS_MASK; //XYZ absolute, E relative