@@ -54,6 +54,10 @@ uint32_t PrintJobRecovery::cmd_sdpos, // = 0
54
54
#include " ../module/temperature.h"
55
55
#include " ../core/serial.h"
56
56
57
+ #if HOMING_Z_WITH_PROBE
58
+ #include " ../module/probe.h"
59
+ #endif
60
+
57
61
#if ENABLED(FWRETRACT)
58
62
#include " fwretract.h"
59
63
#endif
@@ -178,7 +182,8 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POW
178
182
info.valid_foot = info.valid_head ;
179
183
180
184
// Machine state
181
- info.current_position = current_position;
185
+ // info.sdpos and info.current_position are pre-filled from the Stepper ISR
186
+
182
187
info.feedrate = uint16_t (MMS_TO_MMM (feedrate_mm_s));
183
188
info.zraise = zraise;
184
189
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
265
270
266
271
#endif
267
272
273
+ #endif // POWER_LOSS_PIN
274
+
275
+ #if PIN_EXISTS(POWER_LOSS) || ENABLED(DEBUG_POWER_LOSS_RECOVERY)
276
+
268
277
/* *
269
278
* An outage was detected by a sensor pin.
270
279
* - 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
273
282
* - If backup power is available Retract E and Raise Z
274
283
* - Go to the KILL screen
275
284
*/
276
- void PrintJobRecovery::_outage () {
285
+ void PrintJobRecovery::_outage (TERN_(DEBUG_POWER_LOSS_RECOVERY, const bool simulated /* =false */ ) ) {
277
286
#if ENABLED(BACKUP_POWER_SUPPLY)
278
287
static bool lock = false ;
279
288
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
301
310
retract_and_lift (zraise);
302
311
#endif
303
312
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));
305
320
}
306
321
307
- #endif
322
+ #endif // POWER_LOSS_PIN || DEBUG_POWER_LOSS_RECOVERY
308
323
309
324
/* *
310
325
* Save the recovery info the recovery file
@@ -390,14 +405,12 @@ void PrintJobRecovery::resume() {
390
405
391
406
#if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
392
407
#define HOMING_Z_DOWN 1
393
- #else
394
- #define HOME_XY_ONLY 1
395
408
#endif
396
409
397
410
float z_now = info.flag .raised ? z_raised : z_print;
398
411
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
401
414
sprintf_P (cmd, PSTR (" G92.9Z%s" ), dtostrf (z_now, 1 , 3 , str_1));
402
415
gcode.process_subcommands_now (cmd);
403
416
#endif
@@ -409,15 +422,15 @@ void PrintJobRecovery::resume() {
409
422
gcode.process_subcommands_now (cmd);
410
423
}
411
424
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
414
427
415
428
#endif
416
429
417
430
#if HOMING_Z_DOWN
418
431
// 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));
421
434
gcode.process_subcommands_now (cmd);
422
435
#endif
423
436
@@ -431,7 +444,7 @@ void PrintJobRecovery::resume() {
431
444
sprintf_P (cmd, PSTR (" M420S%cZ%s" ), ' 0' + (char )info.flag .leveling , dtostrf (info.fade , 1 , 1 , str_1));
432
445
gcode.process_subcommands_now (cmd);
433
446
434
- #if HOME_XY_ONLY
447
+ #if !HOMING_Z_DOWN
435
448
// The physical Z was adjusted at power-off so undo the M420S1 correction to Z with G92.9.
436
449
sprintf_P (cmd, PSTR (" G92.9Z%s" ), dtostrf (z_now, 1 , 1 , str_1));
437
450
gcode.process_subcommands_now (cmd);
@@ -513,12 +526,12 @@ void PrintJobRecovery::resume() {
513
526
514
527
// Un-retract if there was a retract at outage
515
528
#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)));
517
530
#endif
518
531
519
532
// Additional purge on resume if configured
520
533
#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));
522
535
gcode.process_subcommands_now (cmd);
523
536
#endif
524
537
0 commit comments