@@ -78,6 +78,14 @@ PrintJobRecovery recovery;
78
78
#define POWER_LOSS_RETRACT_LEN 0
79
79
#endif
80
80
81
+ // Allow power-loss recovery to be aborted
82
+ #define PLR_CAN_ABORT
83
+ #if ENABLED(PLR_CAN_ABORT)
84
+ #define PROCESS_SUBCOMMANDS_NOW (cmd ) do { if (card.flag .abort_sd_printing ) return ; gcode.process_subcommands_now (cmd); }while (0 )
85
+ #else
86
+ #define PROCESS_SUBCOMMANDS_NOW (cmd ) gcode.process_subcommands_now(cmd)
87
+ #endif
88
+
81
89
/* *
82
90
* Clear the recovery info
83
91
*/
@@ -352,20 +360,31 @@ void PrintJobRecovery::resume() {
352
360
// Apply the dry-run flag if enabled
353
361
if (info.flag .dryrun ) marlin_debug_flags |= MARLIN_DEBUG_DRYRUN;
354
362
363
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
364
+ struct OnExit {
365
+ uint8_t old_flags;
366
+ OnExit () {
367
+ old_flags = marlin_debug_flags;
368
+ marlin_debug_flags |= MARLIN_DEBUG_ECHO;
369
+ }
370
+ ~OnExit () { marlin_debug_flags = old_flags; }
371
+ } on_exit;
372
+ #endif
373
+
355
374
// Restore cold extrusion permission
356
375
TERN_ (PREVENT_COLD_EXTRUSION, thermalManager.allow_cold_extrude = info.flag .allow_cold_extrusion );
357
376
358
377
#if HAS_LEVELING
359
378
// Make sure leveling is off before any G92 and G28
360
- gcode. process_subcommands_now (F (" M420 S0 Z0 " ));
379
+ PROCESS_SUBCOMMANDS_NOW (F (" M420S0 " ));
361
380
#endif
362
381
363
382
#if HAS_HEATED_BED
364
383
const celsius_t bt = info.target_temperature_bed ;
365
384
if (bt) {
366
385
// Restore the bed temperature
367
386
sprintf_P (cmd, PSTR (" M190S%i" ), bt);
368
- gcode. process_subcommands_now (cmd);
387
+ PROCESS_SUBCOMMANDS_NOW (cmd);
369
388
}
370
389
#endif
371
390
@@ -376,10 +395,10 @@ void PrintJobRecovery::resume() {
376
395
if (et) {
377
396
#if HAS_MULTI_HOTEND
378
397
sprintf_P (cmd, PSTR (" T%iS" ), e);
379
- gcode. process_subcommands_now (cmd);
398
+ PROCESS_SUBCOMMANDS_NOW (cmd);
380
399
#endif
381
400
sprintf_P (cmd, PSTR (" M109S%i" ), et);
382
- gcode. process_subcommands_now (cmd);
401
+ PROCESS_SUBCOMMANDS_NOW (cmd);
383
402
}
384
403
}
385
404
#endif
@@ -393,7 +412,7 @@ void PrintJobRecovery::resume() {
393
412
// establish the current position as best we can.
394
413
//
395
414
396
- gcode. process_subcommands_now (F (" G92.9E0" )); // Reset E to 0
415
+ PROCESS_SUBCOMMANDS_NOW (F (" G92.9E0" )); // Reset E to 0
397
416
398
417
#if Z_HOME_TO_MAX
399
418
@@ -404,7 +423,7 @@ void PrintJobRecovery::resume() {
404
423
" G28R0\n " // Home all axes (no raise)
405
424
" G1Z%sF1200" // Move Z down to (raised) height
406
425
), dtostrf (z_now, 1 , 3 , str_1));
407
- gcode. process_subcommands_now (cmd);
426
+ PROCESS_SUBCOMMANDS_NOW (cmd);
408
427
409
428
#elif DISABLED(BELTPRINTER)
410
429
@@ -417,26 +436,26 @@ void PrintJobRecovery::resume() {
417
436
#if !HOMING_Z_DOWN
418
437
// Set Z to the real position
419
438
sprintf_P (cmd, PSTR (" G92.9Z%s" ), dtostrf (z_now, 1 , 3 , str_1));
420
- gcode. process_subcommands_now (cmd);
439
+ PROCESS_SUBCOMMANDS_NOW (cmd);
421
440
#endif
422
441
423
442
// Does Z need to be raised now? It should be raised before homing XY.
424
443
if (z_raised > z_now) {
425
444
z_now = z_raised;
426
445
sprintf_P (cmd, PSTR (" G1Z%sF600" ), dtostrf (z_now, 1 , 3 , str_1));
427
- gcode. process_subcommands_now (cmd);
446
+ PROCESS_SUBCOMMANDS_NOW (cmd);
428
447
}
429
448
430
449
// Home XY with no Z raise
431
- gcode. process_subcommands_now (F (" G28R0XY" )); // No raise during G28
450
+ PROCESS_SUBCOMMANDS_NOW (F (" G28R0XY" )); // No raise during G28
432
451
433
452
#endif
434
453
435
454
#if HOMING_Z_DOWN
436
455
// Move to a safe XY position and home Z while avoiding the print.
437
456
const xy_pos_t p = xy_pos_t (POWER_LOSS_ZHOME_POS) TERN_ (HOMING_Z_WITH_PROBE, - probe.offset_xy );
438
457
sprintf_P (cmd, PSTR (" G1X%sY%sF1000\n G28HZ" ), dtostrf (p.x , 1 , 3 , str_1), dtostrf (p.y , 1 , 3 , str_2));
439
- gcode. process_subcommands_now (cmd);
458
+ PROCESS_SUBCOMMANDS_NOW (cmd);
440
459
#endif
441
460
442
461
// Mark all axes as having been homed (no effect on current_position)
@@ -447,37 +466,37 @@ void PrintJobRecovery::resume() {
447
466
// Leveling may already be enabled due to the ENABLE_LEVELING_AFTER_G28 option.
448
467
// TODO: Add a G28 parameter to leave leveling disabled.
449
468
sprintf_P (cmd, PSTR (" M420S%cZ%s" ), ' 0' + (char )info.flag .leveling , dtostrf (info.fade , 1 , 1 , str_1));
450
- gcode. process_subcommands_now (cmd);
469
+ PROCESS_SUBCOMMANDS_NOW (cmd);
451
470
452
471
#if !HOMING_Z_DOWN
453
472
// The physical Z was adjusted at power-off so undo the M420S1 correction to Z with G92.9.
454
473
sprintf_P (cmd, PSTR (" G92.9Z%s" ), dtostrf (z_now, 1 , 1 , str_1));
455
- gcode. process_subcommands_now (cmd);
474
+ PROCESS_SUBCOMMANDS_NOW (cmd);
456
475
#endif
457
476
#endif
458
477
459
478
#if ENABLED(POWER_LOSS_RECOVER_ZHOME)
460
479
// Z was homed down to the bed, so move up to the raised height.
461
480
z_now = z_raised;
462
481
sprintf_P (cmd, PSTR (" G1Z%sF600" ), dtostrf (z_now, 1 , 3 , str_1));
463
- gcode. process_subcommands_now (cmd);
482
+ PROCESS_SUBCOMMANDS_NOW (cmd);
464
483
#endif
465
484
466
485
// Recover volumetric extrusion state
467
486
#if DISABLED(NO_VOLUMETRICS)
468
487
#if HAS_MULTI_EXTRUDER
469
488
EXTRUDER_LOOP () {
470
489
sprintf_P (cmd, PSTR (" M200T%iD%s" ), e, dtostrf (info.filament_size [e], 1 , 3 , str_1));
471
- gcode. process_subcommands_now (cmd);
490
+ PROCESS_SUBCOMMANDS_NOW (cmd);
472
491
}
473
492
if (!info.flag .volumetric_enabled ) {
474
493
sprintf_P (cmd, PSTR (" M200T%iD0" ), info.active_extruder );
475
- gcode. process_subcommands_now (cmd);
494
+ PROCESS_SUBCOMMANDS_NOW (cmd);
476
495
}
477
496
#else
478
497
if (info.flag .volumetric_enabled ) {
479
498
sprintf_P (cmd, PSTR (" M200D%s" ), dtostrf (info.filament_size [0 ], 1 , 3 , str_1));
480
- gcode. process_subcommands_now (cmd);
499
+ PROCESS_SUBCOMMANDS_NOW (cmd);
481
500
}
482
501
#endif
483
502
#endif
@@ -489,18 +508,18 @@ void PrintJobRecovery::resume() {
489
508
if (et) {
490
509
#if HAS_MULTI_HOTEND
491
510
sprintf_P (cmd, PSTR (" T%iS" ), e);
492
- gcode. process_subcommands_now (cmd);
511
+ PROCESS_SUBCOMMANDS_NOW (cmd);
493
512
#endif
494
513
sprintf_P (cmd, PSTR (" M109S%i" ), et);
495
- gcode. process_subcommands_now (cmd);
514
+ PROCESS_SUBCOMMANDS_NOW (cmd);
496
515
}
497
516
}
498
517
#endif
499
518
500
519
// Restore the previously active tool (with no_move)
501
520
#if HAS_MULTI_EXTRUDER || HAS_MULTI_HOTEND
502
521
sprintf_P (cmd, PSTR (" T%i S" ), info.active_extruder );
503
- gcode. process_subcommands_now (cmd);
522
+ PROCESS_SUBCOMMANDS_NOW (cmd);
504
523
#endif
505
524
506
525
// Restore print cooling fan speeds
@@ -509,7 +528,7 @@ void PrintJobRecovery::resume() {
509
528
const int f = info.fan_speed [i];
510
529
if (f) {
511
530
sprintf_P (cmd, PSTR (" M106P%iS%i" ), i, f);
512
- gcode. process_subcommands_now (cmd);
531
+ PROCESS_SUBCOMMANDS_NOW (cmd);
513
532
}
514
533
}
515
534
#endif
@@ -531,37 +550,37 @@ void PrintJobRecovery::resume() {
531
550
532
551
// Un-retract if there was a retract at outage
533
552
#if ENABLED(BACKUP_POWER_SUPPLY) && POWER_LOSS_RETRACT_LEN > 0
534
- gcode. process_subcommands_now (F (" G1F3000E" STRINGIFY (POWER_LOSS_RETRACT_LEN)));
553
+ PROCESS_SUBCOMMANDS_NOW (F (" G1F3000E" STRINGIFY (POWER_LOSS_RETRACT_LEN)));
535
554
#endif
536
555
537
556
// Additional purge on resume if configured
538
557
#if POWER_LOSS_PURGE_LEN
539
558
sprintf_P (cmd, PSTR (" G1F3000E%d" ), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
540
- gcode. process_subcommands_now (cmd);
559
+ PROCESS_SUBCOMMANDS_NOW (cmd);
541
560
#endif
542
561
543
562
#if ENABLED(NOZZLE_CLEAN_FEATURE)
544
- gcode. process_subcommands_now (F (" G12" ));
563
+ PROCESS_SUBCOMMANDS_NOW (F (" G12" ));
545
564
#endif
546
565
547
566
// Move back over to the saved XY
548
567
sprintf_P (cmd, PSTR (" G1X%sY%sF3000" ),
549
568
dtostrf (info.current_position .x , 1 , 3 , str_1),
550
569
dtostrf (info.current_position .y , 1 , 3 , str_2)
551
570
);
552
- gcode. process_subcommands_now (cmd);
571
+ PROCESS_SUBCOMMANDS_NOW (cmd);
553
572
554
573
// Move back down to the saved Z for printing
555
574
sprintf_P (cmd, PSTR (" G1Z%sF600" ), dtostrf (z_print, 1 , 3 , str_1));
556
- gcode. process_subcommands_now (cmd);
575
+ PROCESS_SUBCOMMANDS_NOW (cmd);
557
576
558
577
// Restore the feedrate
559
578
sprintf_P (cmd, PSTR (" G1F%d" ), info.feedrate );
560
- gcode. process_subcommands_now (cmd);
579
+ PROCESS_SUBCOMMANDS_NOW (cmd);
561
580
562
581
// Restore E position with G92.9
563
582
sprintf_P (cmd, PSTR (" G92.9E%s" ), dtostrf (info.current_position .e , 1 , 3 , str_1));
564
- gcode. process_subcommands_now (cmd);
583
+ PROCESS_SUBCOMMANDS_NOW (cmd);
565
584
566
585
TERN_ (GCODE_REPEAT_MARKERS, repeat = info.stored_repeat );
567
586
TERN_ (HAS_HOME_OFFSET, home_offset = info.home_offset );
@@ -573,22 +592,14 @@ void PrintJobRecovery::resume() {
573
592
// Relative axis modes
574
593
gcode.axis_relative = info.axis_relative ;
575
594
576
- #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
577
- const uint8_t old_flags = marlin_debug_flags;
578
- marlin_debug_flags |= MARLIN_DEBUG_ECHO;
579
- #endif
580
-
581
595
// Continue to apply PLR when a file is resumed!
582
596
enable (true );
583
597
584
598
// Resume the SD file from the last position
585
- char *fn = info.sd_filename ;
586
- sprintf_P (cmd, M23_STR, fn);
587
- gcode.process_subcommands_now (cmd);
599
+ sprintf_P (cmd, M23_STR, &info.sd_filename [0 ]);
600
+ PROCESS_SUBCOMMANDS_NOW (cmd);
588
601
sprintf_P (cmd, PSTR (" M24S%ldT%ld" ), resume_sdpos, info.print_job_elapsed );
589
- gcode.process_subcommands_now (cmd);
590
-
591
- TERN_ (DEBUG_POWER_LOSS_RECOVERY, marlin_debug_flags = old_flags);
602
+ PROCESS_SUBCOMMANDS_NOW (cmd);
592
603
}
593
604
594
605
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
0 commit comments