Skip to content

Commit ee512c8

Browse files
committed
Improve Power-Loss Recovery
1 parent 4424645 commit ee512c8

4 files changed

Lines changed: 37 additions & 5 deletions

File tree

Marlin/src/feature/powerloss.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ void PrintJobRecovery::check() {
112112
if (card.isMounted()) {
113113
load();
114114
if (!valid()) return cancel();
115-
queue.inject_P(PSTR("M1000 S"));
116-
TERN_(DWIN_CREALITY_LCD, dwin_flag = true);
115+
queue.inject_P(PSTR("M1000S"));
117116
}
118117
}
119118

@@ -227,6 +226,10 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/
227226
// Elapsed print job time
228227
info.print_job_elapsed = print_job_timer.duration();
229228

229+
// Misc. Marlin flags
230+
info.flag.dryrun = !!(marlin_debug_flags & MARLIN_DEBUG_DRYRUN);
231+
info.flag.allow_cold_extrusion = TERN0(PREVENT_COLD_EXTRUSION, thermalManager.allow_cold_extrude);
232+
230233
write();
231234
}
232235
}
@@ -326,6 +329,12 @@ void PrintJobRecovery::resume() {
326329

327330
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
328331

332+
// Apply the dry-run flag if enabled
333+
if (info.flag.dryrun) marlin_debug_flags |= MARLIN_DEBUG_DRYRUN;
334+
335+
// Restore cold extrusion permission
336+
TERN_(PREVENT_COLD_EXTRUSION, thermalManager.allow_cold_extrude = info.flag.allow_cold_extrusion);
337+
329338
#if HAS_LEVELING
330339
// Make sure leveling is off before any G92 and G28
331340
gcode.process_subcommands_now_P(PSTR("M420 S0 Z0"));
@@ -337,7 +346,7 @@ void PrintJobRecovery::resume() {
337346
// If Z homing goes to max, just reset E and home all
338347
gcode.process_subcommands_now_P(PSTR(
339348
"G92.9 E0\n"
340-
"G28R0" TERN_(MARLIN_DEV_MODE, "S")
349+
"G28R0"
341350
));
342351

343352
#else // "G92.9 E0 ..."
@@ -358,7 +367,6 @@ void PrintJobRecovery::resume() {
358367

359368
gcode.process_subcommands_now_P(PSTR(
360369
"G28R0" // No raise during G28
361-
TERN_(MARLIN_DEV_MODE, "S") // Simulated Homing
362370
TERN_(IS_CARTESIAN, "XY") // Don't home Z on Cartesian
363371
));
364372

@@ -498,13 +506,23 @@ void PrintJobRecovery::resume() {
498506
LOOP_XYZ(i) update_workspace_offset((AxisEnum)i);
499507
#endif
500508

509+
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
510+
const uint8_t old_flags = marlin_debug_flags;
511+
marlin_debug_flags |= MARLIN_DEBUG_ECHO;
512+
#endif
513+
514+
// Continue to apply PLR when a file is resumed!
515+
enable(true);
516+
501517
// Resume the SD file from the last position
502518
char *fn = info.sd_filename;
503519
extern const char M23_STR[];
504520
sprintf_P(cmd, M23_STR, fn);
505521
gcode.process_subcommands_now(cmd);
506522
sprintf_P(cmd, PSTR("M24 S%ld T%ld"), resume_sdpos, info.print_job_elapsed);
507523
gcode.process_subcommands_now(cmd);
524+
525+
TERN_(DEBUG_POWER_LOSS_RECOVERY, marlin_debug_flags = old_flags);
508526
}
509527

510528
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
@@ -584,6 +602,8 @@ void PrintJobRecovery::resume() {
584602
DEBUG_ECHOLNPAIR("sd_filename: ", info.sd_filename);
585603
DEBUG_ECHOLNPAIR("sdpos: ", info.sdpos);
586604
DEBUG_ECHOLNPAIR("print_job_elapsed: ", info.print_job_elapsed);
605+
DEBUG_ECHOLNPAIR("dryrun: ", int(info.flag.dryrun));
606+
DEBUG_ECHOLNPAIR("allow_cold_extrusion: ", int(info.flag.allow_cold_extrusion));
587607
}
588608
else
589609
DEBUG_ECHOLNPGM("INVALID DATA");

Marlin/src/feature/powerloss.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ typedef struct {
107107
// Job elapsed time
108108
millis_t print_job_elapsed;
109109

110+
// Misc. Marlin flags
111+
struct {
112+
bool dryrun:1; // M111 S8
113+
bool allow_cold_extrusion:1; // M302 P1
114+
} flag;
115+
110116
uint8_t valid_foot;
111117

112118
bool valid() { return valid_head && valid_head == valid_foot; }
@@ -173,7 +179,10 @@ class PrintJobRecovery {
173179
}
174180
#endif
175181

176-
static inline bool valid() { return info.valid(); }
182+
// The referenced file exists
183+
static inline bool interrupted_file_exists() { return card.fileExists(info.sd_filename); }
184+
185+
static inline bool valid() { return info.valid() && interrupted_file_exists(); }
177186

178187
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
179188
static void debug(PGM_P const prefix);

Marlin/src/gcode/feature/powerloss/M1000.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ void GcodeSuite::M1000() {
6262
if (parser.seen('S')) {
6363
#if HAS_LCD_MENU
6464
ui.goto_screen(menu_job_recovery);
65+
#elif ENABLED(DWIN_CREALITY_LCD)
66+
recovery.dwin_flag = true;
6567
#elif ENABLED(EXTENSIBLE_UI)
6668
ExtUI::onPowerLossResume();
6769
#else

Marlin/src/gcode/feature/powerloss/M413.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void GcodeSuite::M413() {
5050
if (parser.seen("RL")) recovery.load();
5151
if (parser.seen('W')) recovery.save(true);
5252
if (parser.seen('P')) recovery.purge();
53+
if (parser.seen('D')) recovery.debug(PSTR("M413"));
5354
#if PIN_EXISTS(POWER_LOSS)
5455
if (parser.seen('O')) recovery._outage();
5556
#endif

0 commit comments

Comments
 (0)