@@ -54,6 +54,10 @@ uint32_t PrintJobRecovery::cmd_sdpos, // = 0
5454#include " ../module/temperature.h"
5555#include " ../core/serial.h"
5656
57+ #if HOMING_Z_WITH_PROBE
58+ #include " ../module/probe.h"
59+ #endif
60+
5761#if ENABLED(FWRETRACT)
5862 #include " fwretract.h"
5963#endif
@@ -178,7 +182,8 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
178182 info.valid_foot = info.valid_head ;
179183
180184 // Machine state
181- info.current_position = current_position;
185+ // info.sdpos and info.current_position are pre-filled from the Stepper ISR
186+
182187 info.feedrate = uint16_t (MMS_TO_MMM (feedrate_mm_s));
183188 info.zraise = zraise;
184189 info.flag .raised = raised; // Was Z raised before power-off?
@@ -265,6 +270,10 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
265270
266271 #endif
267272
273+ #endif // POWER_LOSS_PIN
274+
275+ #if PIN_EXISTS(POWER_LOSS) || ENABLED(DEBUG_POWER_LOSS_RECOVERY)
276+
268277 /* *
269278 * An outage was detected by a sensor pin.
270279 * - If not SD printing, let the machine turn off on its own with no "KILL" screen
@@ -273,7 +282,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
273282 * - If backup power is available Retract E and Raise Z
274283 * - Go to the KILL screen
275284 */
276- void PrintJobRecovery::_outage () {
285+ void PrintJobRecovery::_outage (TERN_(DEBUG_POWER_LOSS_RECOVERY, const bool simulated /* =false */ ) ) {
277286 #if ENABLED(BACKUP_POWER_SUPPLY)
278287 static bool lock = false ;
279288 if (lock) return ; // No re-entrance from idle() during retract_and_lift()
@@ -301,10 +310,16 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
301310 retract_and_lift (zraise);
302311 #endif
303312
304- kill (GET_TEXT_F (MSG_OUTAGE_RECOVERY));
313+ if (TERN0 (DEBUG_POWER_LOSS_RECOVERY, simulated)) {
314+ card.fileHasFinished ();
315+ current_position.reset ();
316+ sync_plan_position ();
317+ }
318+ else
319+ kill (GET_TEXT_F (MSG_OUTAGE_RECOVERY));
305320 }
306321
307- #endif
322+ #endif // POWER_LOSS_PIN || DEBUG_POWER_LOSS_RECOVERY
308323
309324/* *
310325 * Save the recovery info the recovery file
@@ -390,14 +405,12 @@ void PrintJobRecovery::resume() {
390405
391406 #if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
392407 #define HOMING_Z_DOWN 1
393- #else
394- #define HOME_XY_ONLY 1
395408 #endif
396409
397410 float z_now = info.flag .raised ? z_raised : z_print;
398411
399- // Reset E to 0 and set Z to the real position
400- # if HOME_XY_ONLY
412+ # if !HOMING_Z_DOWN
413+ // Set Z to the real position
401414 sprintf_P (cmd, PSTR (" G92.9Z%s" ), dtostrf (z_now, 1 , 3 , str_1));
402415 gcode.process_subcommands_now (cmd);
403416 #endif
@@ -409,15 +422,15 @@ void PrintJobRecovery::resume() {
409422 gcode.process_subcommands_now (cmd);
410423 }
411424
412- // Home XY with no Z raise, and also home Z here if Z isn't homing down below.
413- gcode.process_subcommands_now (F (" G28R0 " TERN_ (HOME_XY_ONLY, " XY " ) )); // No raise during G28
425+ // Home XY with no Z raise
426+ gcode.process_subcommands_now (F (" G28R0XY " )); // No raise during G28
414427
415428 #endif
416429
417430 #if HOMING_Z_DOWN
418431 // Move to a safe XY position and home Z while avoiding the print.
419- constexpr xy_pos_t p = POWER_LOSS_ZHOME_POS;
420- sprintf_P (cmd, PSTR (" G1X%sY%sF1000\n G28Z " ), dtostrf (p.x , 1 , 3 , str_1), dtostrf (p.y , 1 , 3 , str_2));
432+ const xy_pos_t p = xy_pos_t ( POWER_LOSS_ZHOME_POS) TERN_ (HOMING_Z_WITH_PROBE, - probe. offset_xy ) ;
433+ sprintf_P (cmd, PSTR (" G1X%sY%sF1000\n G28HZ " ), dtostrf (p.x , 1 , 3 , str_1), dtostrf (p.y , 1 , 3 , str_2));
421434 gcode.process_subcommands_now (cmd);
422435 #endif
423436
@@ -431,7 +444,7 @@ void PrintJobRecovery::resume() {
431444 sprintf_P (cmd, PSTR (" M420S%cZ%s" ), ' 0' + (char )info.flag .leveling , dtostrf (info.fade , 1 , 1 , str_1));
432445 gcode.process_subcommands_now (cmd);
433446
434- #if HOME_XY_ONLY
447+ #if !HOMING_Z_DOWN
435448 // The physical Z was adjusted at power-off so undo the M420S1 correction to Z with G92.9.
436449 sprintf_P (cmd, PSTR (" G92.9Z%s" ), dtostrf (z_now, 1 , 1 , str_1));
437450 gcode.process_subcommands_now (cmd);
@@ -513,12 +526,12 @@ void PrintJobRecovery::resume() {
513526
514527 // Un-retract if there was a retract at outage
515528 #if ENABLED(BACKUP_POWER_SUPPLY) && POWER_LOSS_RETRACT_LEN > 0
516- gcode.process_subcommands_now (F (" G1E " STRINGIFY (POWER_LOSS_RETRACT_LEN) " F3000 " ));
529+ gcode.process_subcommands_now (F (" G1F3000E " STRINGIFY (POWER_LOSS_RETRACT_LEN)));
517530 #endif
518531
519532 // Additional purge on resume if configured
520533 #if POWER_LOSS_PURGE_LEN
521- sprintf_P (cmd, PSTR (" G1 E%d F3000 " ), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
534+ sprintf_P (cmd, PSTR (" G1F3000E%d " ), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
522535 gcode.process_subcommands_now (cmd);
523536 #endif
524537
0 commit comments