From 4d9dc11510f676c66ded4d493bf2e51c0cf19b70 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sun, 26 Nov 2023 15:59:23 +0000 Subject: [PATCH] power panic: pause the print, and wait for M79 "PRUSA uvlo" is the last g-code to be processed after the power panic recovery. For host prints, we want to finish processing all these g-codes and put the print in a paused state. Currently I am using lcd_pause_print() but this may be simplified later. A new PrinterState is introduced PowerPanicWaitingForHost to differentiate this paused state from the typical paused state. In this new paused state the printer is waiting for the host to boot up and send M79. Once M79 is seen a new action is sent "// action:uvlo_recovery_ready" It is up to the host software to then resume the print correctly. All the needed information to resume the print is in EEPROM and can be read by using the D3 g-code. Change in memory: Flash: +82 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 26 ++++++++++++++++++++++++++ Firmware/messages.cpp | 1 + Firmware/messages.h | 1 + Firmware/printer_state.h | 1 + 4 files changed, 29 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 430679b49..85a03f04e 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4112,6 +4112,20 @@ void process_commands() // M24 - Start SD print enquecommand_P(MSG_M24); } + else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB) + { + // 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 + // For SD prints, M24 starts the timer + print_job_timer.start(); + + // Park the extruder to the side and don't resume the print + // we must assume that the host as not fully booted up at this point + lcd_pause_print(); + + // Used by M79 to differentiate from a normal pause + SetPrinterState(PrinterState::PowerPanicWaitingForHost); + } // Print is recovered, clear the recovery flag eeprom_update_byte((uint8_t*)EEPROM_UVLO, PowerPanic::NO_PENDING_RECOVERY); @@ -5972,6 +5986,18 @@ Sigma_Exit: SetHostStatusScreenName(str.GetUnquotedString()); } } + + if (GetPrinterState() == PrinterState::PowerPanicWaitingForHost && print_job_timer.isPaused()) { + // 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); + + // Update the state so the action is not repeated again + SetPrinterState(PrinterState::IsHostPrinting); + } + break; /*! diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index 39e5c1081..d264887e1 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -233,6 +233,7 @@ 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_FANCHECK_HOTEND[] PROGMEM_N1 = "Err:HOTEND FAN ERROR"; ////c=20 const char MSG_FANCHECK_PRINT[] PROGMEM_N1 = "Err:PRINT FAN ERROR"; ////c=20 const char MSG_M112_KILL[] PROGMEM_N1 = "M112 called. Emergency Stop."; ////c=20 diff --git a/Firmware/messages.h b/Firmware/messages.h index 9d8423fdc..c04672ddf 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -237,6 +237,7 @@ 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_FANCHECK_HOTEND[]; extern const char MSG_FANCHECK_PRINT[]; extern const char MSG_M112_KILL[]; diff --git a/Firmware/printer_state.h b/Firmware/printer_state.h index 22b9fe5bd..a88d36f4a 100644 --- a/Firmware/printer_state.h +++ b/Firmware/printer_state.h @@ -23,6 +23,7 @@ enum class PrinterState : uint8_t HostPrintingFinished = 4, IsSDPrinting = 5, IsHostPrinting = 6, + PowerPanicWaitingForHost = 7, }; PrinterState GetPrinterState();