diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f5e2fd5a6..dff04d564 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -321,6 +321,7 @@ uint8_t saved_bed_temperature; //!< Bed temperature bool saved_extruder_relative_mode; uint8_t saved_fan_speed = 0; //!< Print fan speed //! @} +static bool uvlo_auto_recovery_ready = false; static int saved_feedmultiply_mm = 100; @@ -522,7 +523,8 @@ bool __attribute__((noinline)) printer_active() { || (lcd_commands_type != LcdCommands::Idle) || MMU2::mmu2.MMU_PRINT_SAVED() || homing_flag - || mesh_bed_leveling_flag; + || mesh_bed_leveling_flag + || (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != PowerPanic::NO_PENDING_RECOVERY); } // Currently only used in one place, allowed to be inlined @@ -979,7 +981,7 @@ static void fw_crash_init() if(xfdump_check_state(&crash_reason)) { // always signal to the host that a dump is available for retrieval - puts_P(_N("// action:dump_available")); + puts_P(_N("//action:dump_available")); #ifdef EMERGENCY_DUMP if(crash_reason != dump_crash_reason::manual && @@ -1584,7 +1586,8 @@ void setup() #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER printf_P(_N("Power panic detected!\nCurrent bed temp:%d\nSaved bed temp:%d\n"), (int)degBed(), eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED)); #endif - if ( degBed() > ( (float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED) - AUTOMATIC_UVLO_BED_TEMP_OFFSET) ){ + uvlo_auto_recovery_ready = (degBed() > ( (float)eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED) - AUTOMATIC_UVLO_BED_TEMP_OFFSET)); + if (uvlo_auto_recovery_ready){ #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER puts_P(_N("Automatic recovery!")); #endif @@ -1594,7 +1597,7 @@ void setup() #ifdef DEBUG_UVLO_AUTOMATIC_RECOVER puts_P(_N("Normal recovery!")); #endif - if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::PRINT_TYPE_USB) { + if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == PowerPanic::PRINT_TYPE_HOST) { recover_print(0); } else { const uint8_t btn = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_RECOVER_PRINT), false); @@ -1730,7 +1733,7 @@ void loop() KEEPALIVE_STATE(NOT_BUSY); } - if (printingIsPaused() && saved_printing_type == PowerPanic::PRINT_TYPE_USB) { //keep believing that usb is being printed. Prevents accessing dangerous menus while pausing. + if (printingIsPaused() && saved_printing_type == PowerPanic::PRINT_TYPE_HOST) { //keep believing that usb is being printed. Prevents accessing dangerous menus while pausing. usb_timer.start(); } else if (usb_timer.expired(USB_TIMER_TIMEOUT)) { //just need to check if it expired. Nothing else is needed to be done. @@ -4126,10 +4129,10 @@ void process_commands() // M24 - Start SD print enquecommand_P(MSG_M24); - // Print is recovered, clear the recovery flag - eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY); + // Print is recovered, clear the recovery flag + eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY); } - else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB) + else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_HOST) { // For Host prints we need to start the timer so that the pause has any effect // this will allow g-codes to be processed while in the paused state @@ -5998,12 +6001,18 @@ Sigma_Exit: } } - if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB && printingIsPaused()) { + if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_HOST + && eeprom_read_byte((uint8_t*)EEPROM_UVLO) != PowerPanic::NO_PENDING_RECOVERY + && printingIsPaused()) { // The print is in a paused state. The print was recovered following a power panic // but up to this point the printer has been waiting for the M79 from the host // Send action to the host, so the host can resume the print. It is up to the host // to resume the print correctly. - SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_UVLO_RECOVERY_READY); + if (uvlo_auto_recovery_ready) { + SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_UVLO_AUTO_RECOVERY_READY); + } else { + SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_UVLO_RECOVERY_READY); + } } break; @@ -10655,7 +10664,7 @@ void save_print_file_state() { nlines = planner_calc_sd_length(); //number of lines of commands in planner saved_sdpos -= nlines; saved_sdpos -= buflen; //number of blocks in cmd buffer - saved_printing_type = PowerPanic::PRINT_TYPE_USB; + saved_printing_type = PowerPanic::PRINT_TYPE_HOST; } else { saved_printing_type = PowerPanic::PRINT_TYPE_NONE; @@ -10756,7 +10765,7 @@ void restore_print_file_state() { card.setIndex(saved_sdpos); sdpos_atomic = saved_sdpos; card.sdprinting = true; - } else if (saved_printing_type == PowerPanic::PRINT_TYPE_USB) { //was usb printing + } else if (saved_printing_type == PowerPanic::PRINT_TYPE_HOST) { //was usb printing gcode_LastN = saved_sdpos; //saved_sdpos was reused for storing line number when usb printing serial_count = 0; FlushSerialRequestResend(); diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 3f5056018..c6b95762a 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -228,15 +228,16 @@ const char MSG_ENDSTOP_OPEN[] PROGMEM_N1 = "open"; //// const char MSG_POWERUP[] PROGMEM_N1 = "PowerUp"; //// const char MSG_ERR_STOPPED[] PROGMEM_N1 = "Printer stopped due to errors. Supervision required."; //// const char MSG_ENDSTOP_HIT[] PROGMEM_N1 = "TRIGGERED"; //// -const char MSG_OCTOPRINT_ASK_PAUSE[] PROGMEM_N1 = "// action:pause"; //// -const char MSG_OCTOPRINT_PAUSED[] PROGMEM_N1 = "// action:paused"; //// -const char MSG_OCTOPRINT_ASK_RESUME[] PROGMEM_N1 = "// action:resume"; //// -const char MSG_OCTOPRINT_RESUMED[] PROGMEM_N1 = "// action:resumed"; //// -const char MSG_OCTOPRINT_CANCEL[] PROGMEM_N1 = "// action:cancel"; //// -const char MSG_OCTOPRINT_READY[] PROGMEM_N1 = "// action:ready"; //// -const char MSG_OCTOPRINT_NOT_READY[] PROGMEM_N1 = "// action:not_ready"; //// -const char MSG_OCTOPRINT_START[] PROGMEM_N1 = "// action:start"; //// -const char MSG_OCTOPRINT_UVLO_RECOVERY_READY[] PROGMEM_N1 = "// action:uvlo_recovery_ready"; //// +const char MSG_HOST_ACTION_ASK_PAUSE[] PROGMEM_N1 = "//action:pause"; //// +const char MSG_HOST_ACTION_PAUSED[] PROGMEM_N1 = "//action:paused"; //// +const char MSG_HOST_ACTION_ASK_RESUME[] PROGMEM_N1 = "//action:resume"; //// +const char MSG_HOST_ACTION_RESUMED[] PROGMEM_N1 = "//action:resumed"; //// +const char MSG_HOST_ACTION_CANCEL[] PROGMEM_N1 = "//action:cancel"; //// +const char MSG_HOST_ACTION_READY[] PROGMEM_N1 = "//action:ready"; //// +const char MSG_HOST_ACTION_NOT_READY[] PROGMEM_N1 = "//action:not_ready"; //// +const char MSG_HOST_ACTION_START[] PROGMEM_N1 = "//action:start"; //// +const char MSG_HOST_ACTION_UVLO_RECOVERY_READY[] PROGMEM_N1 = "//action:uvlo_recovery_ready"; //// +const char MSG_HOST_ACTION_UVLO_AUTO_RECOVERY_READY[] PROGMEM_N1 = "//action:uvlo_auto_recovery_ready"; //// #ifdef HOST_SHUTDOWN const char MSG_HOST_ACTION_SHUTDOWN[] PROGMEM_N1 = "//action:shutdown"; //// #endif //HOST_SHUTOWN diff --git a/Firmware/messages.h b/Firmware/messages.h index 76f4e507d..3c2732f04 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -232,15 +232,16 @@ extern const char MSG_ERR_STOPPED[]; extern const char MSG_ENDSTOP_HIT[]; extern const char MSG_EJECT_FROM_MMU[]; extern const char MSG_CUT_FILAMENT[]; -extern const char MSG_OCTOPRINT_ASK_PAUSE[]; -extern const char MSG_OCTOPRINT_PAUSED[]; -extern const char MSG_OCTOPRINT_ASK_RESUME[]; -extern const char MSG_OCTOPRINT_RESUMED[]; -extern const char MSG_OCTOPRINT_CANCEL[]; -extern const char MSG_OCTOPRINT_READY[]; -extern const char MSG_OCTOPRINT_NOT_READY[]; -extern const char MSG_OCTOPRINT_START[]; -extern const char MSG_OCTOPRINT_UVLO_RECOVERY_READY[]; +extern const char MSG_HOST_ACTION_ASK_PAUSE[]; +extern const char MSG_HOST_ACTION_PAUSED[]; +extern const char MSG_HOST_ACTION_ASK_RESUME[]; +extern const char MSG_HOST_ACTION_RESUMED[]; +extern const char MSG_HOST_ACTION_CANCEL[]; +extern const char MSG_HOST_ACTION_READY[]; +extern const char MSG_HOST_ACTION_NOT_READY[]; +extern const char MSG_HOST_ACTION_START[]; +extern const char MSG_HOST_ACTION_UVLO_RECOVERY_READY[]; +extern const char MSG_HOST_ACTION_UVLO_AUTO_RECOVERY_READY[]; #ifdef HOST_SHUTDOWN extern const char MSG_HOST_ACTION_SHUTDOWN[]; #endif //HOST_SHUTOWN diff --git a/Firmware/power_panic.cpp b/Firmware/power_panic.cpp index 8b9e6de71..802f9c625 100644 --- a/Firmware/power_panic.cpp +++ b/Firmware/power_panic.cpp @@ -473,7 +473,7 @@ void restore_print_from_eeprom(bool mbl_was_active) { // Set a position in the file. enquecommandf_P(PSTR("M26 S%lu"), position); } - else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB) + else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_HOST) { // Set line number enquecommandf_P(PSTR("M110 N%lu"), position); diff --git a/Firmware/power_panic.h b/Firmware/power_panic.h index 7dcb627dc..c34a831e3 100644 --- a/Firmware/power_panic.h +++ b/Firmware/power_panic.h @@ -10,7 +10,7 @@ enum PowerPanicFlag : uint8_t { // Types of printjobs possible when power panic is triggered enum PrintType : uint8_t { PRINT_TYPE_SD = 0, - PRINT_TYPE_USB = 1, + PRINT_TYPE_HOST = 1, PRINT_TYPE_NONE = 2, }; } // namespace PowerPanic diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index c45c75639..19fcf7f2f 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -45,6 +45,8 @@ #include "Prusa_farm.h" +#include "power_panic.h" + static void lcd_sd_updir(); static void lcd_mesh_bed_leveling_settings(); #ifdef LCD_BL_PIN @@ -1033,7 +1035,7 @@ void lcd_pause_print() { stop_and_save_print_to_ram(0.0, -default_retraction); - SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_PAUSED); + SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_PAUSED); // Indicate that the printer is paused did_pause_print = true; @@ -1048,7 +1050,7 @@ void lcd_pause_print() //! @brief Send host action "pause" void lcd_pause_usb_print() { - SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_PAUSE); + SERIAL_PROTOCOLLNRPGM(MSG_HOST_ACTION_ASK_PAUSE); } static void lcd_move_menu_axis(); @@ -5033,7 +5035,7 @@ void lcd_resume_print() if (print_job_timer.isPaused()) print_job_timer.start(); refresh_cmd_timeout(); - SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_RESUMED); //resume octoprint + SERIAL_PROTOCOLLNRPGM(MSG_HOST_ACTION_RESUMED); custom_message_type = CustomMsg::Status; } @@ -5044,7 +5046,7 @@ void lcd_resume_usb_print() if (!resume_print_checks()) return; // resume the usb host - SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_ASK_RESUME); + SERIAL_PROTOCOLLNRPGM(MSG_HOST_ACTION_ASK_RESUME); } static void change_sheet() @@ -5151,10 +5153,10 @@ static void lcd_sheet_menu() static void lcd_printer_ready_state_toggle() { if (GetPrinterState() == PrinterState::IsReady) { - SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_NOT_READY); + SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_NOT_READY); } else { - SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_READY); + SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_READY); } } @@ -5251,12 +5253,12 @@ static void lcd_main_menu() MENU_ITEM_SUBMENU_P(_T(MSG_TUNE), lcd_tune_menu); } else if (!Stopped) { MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=18 - } - if (GetPrinterState() < PrinterState::IsSDPrinting && M79_timer_get_status()) { - if(GetPrinterState() == PrinterState::IsReady) { - MENU_ITEM_FUNCTION_P(_T(MSG_SET_NOT_READY), lcd_printer_ready_state_toggle); - } else { - MENU_ITEM_FUNCTION_P(_T(MSG_SET_READY), lcd_printer_ready_state_toggle); + if (M79_timer_get_status()) { + if(GetPrinterState() == PrinterState::IsReady) { + MENU_ITEM_FUNCTION_P(_T(MSG_SET_NOT_READY), lcd_printer_ready_state_toggle); + } else { + MENU_ITEM_FUNCTION_P(_T(MSG_SET_READY), lcd_printer_ready_state_toggle); + } } } if (mesh_bed_leveling_flag == false && homing_flag == false && !printingIsPaused() && !processing_tcode) { @@ -5281,7 +5283,11 @@ static void lcd_main_menu() } } } - if((printJobOngoing() || printingIsPaused()) && (custom_message_type != CustomMsg::MeshBedLeveling) && !processing_tcode) { + if((printJobOngoing() + || printingIsPaused() + || (eeprom_read_byte((uint8_t*)EEPROM_UVLO) != PowerPanic::NO_PENDING_RECOVERY)) + && (custom_message_type != CustomMsg::MeshBedLeveling) + && !processing_tcode) { MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop); } #ifdef THERMAL_MODEL @@ -5292,6 +5298,7 @@ static void lcd_main_menu() // only allow starting SD print if hardware errors (temperature or fan) are cleared if(!get_temp_error() + && !printer_active() #ifdef FANCHECK && fan_check_error != EFCE_REPORTED #endif //FANCHECK @@ -5714,7 +5721,7 @@ void print_stop(bool interactive) card.sdprinting = false; card.closefile(); } else { - SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint + SERIAL_ECHOLNRPGM(MSG_HOST_ACTION_CANCEL); } #ifdef MESH_BED_LEVELING @@ -7510,6 +7517,6 @@ void lcd_reprint_from_eeprom() { //! @brief Send host action "start" void lcd_send_action_start() { - SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_START); + SERIAL_PROTOCOLLNRPGM(MSG_HOST_ACTION_START); lcd_return_to_status(); } diff --git a/Firmware/xyzcal.cpp b/Firmware/xyzcal.cpp index 96130d2c9..12c0f67b4 100644 --- a/Firmware/xyzcal.cpp +++ b/Firmware/xyzcal.cpp @@ -568,7 +568,7 @@ void __attribute__((noinline)) xyzcal_scan_pixels_32x32_Zhop(int16_t cx, int16_t xyzcal_lineXYZ_to((d & 1) ? (cx + 992) : (cx - 992), cy - 992 + r * 64, _Z, delay_us, 0); sm4_set_dir(X_AXIS, d); //@size=242 - DBG(_n("%d\n"), 64 - (r * 2 + d)); ///< to keep OctoPrint connection alive + DBG(_n("%d\n"), 64 - (r * 2 + d)); ///< to keep host connection alive lcd_set_cursor(4,3); lcd_printf_P(PSTR("Countdown: %d "),64 - (r * 2 + d)); ////MSG_COUNTDOWN c=12