Browse Source

Improve Power-Loss Recovery (#19540)

Scott Lahteine 4 years ago
parent
commit
9142f5446a
No account linked to committer's email address

+ 24
- 4
Marlin/src/feature/powerloss.cpp View File

@@ -112,8 +112,7 @@ void PrintJobRecovery::check() {
112 112
   if (card.isMounted()) {
113 113
     load();
114 114
     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"));
117 116
   }
118 117
 }
119 118
 
@@ -227,6 +226,10 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/
227 226
     // Elapsed print job time
228 227
     info.print_job_elapsed = print_job_timer.duration();
229 228
 
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
+
230 233
     write();
231 234
   }
232 235
 }
@@ -326,6 +329,12 @@ void PrintJobRecovery::resume() {
326 329
 
327 330
   const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
328 331
 
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
+
329 338
   #if HAS_LEVELING
330 339
     // Make sure leveling is off before any G92 and G28
331 340
     gcode.process_subcommands_now_P(PSTR("M420 S0 Z0"));
@@ -337,7 +346,7 @@ void PrintJobRecovery::resume() {
337 346
     // If Z homing goes to max, just reset E and home all
338 347
     gcode.process_subcommands_now_P(PSTR(
339 348
       "G92.9 E0\n"
340
-      "G28R0" TERN_(MARLIN_DEV_MODE, "S")
349
+      "G28R0"
341 350
     ));
342 351
 
343 352
   #else // "G92.9 E0 ..."
@@ -358,7 +367,6 @@ void PrintJobRecovery::resume() {
358 367
 
359 368
     gcode.process_subcommands_now_P(PSTR(
360 369
       "G28R0"                               // No raise during G28
361
-      TERN_(MARLIN_DEV_MODE, "S")           // Simulated Homing
362 370
       TERN_(IS_CARTESIAN, "XY")             // Don't home Z on Cartesian
363 371
     ));
364 372
 
@@ -498,6 +506,14 @@ void PrintJobRecovery::resume() {
498 506
     LOOP_XYZ(i) update_workspace_offset((AxisEnum)i);
499 507
   #endif
500 508
 
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
+
501 517
   // Resume the SD file from the last position
502 518
   char *fn = info.sd_filename;
503 519
   extern const char M23_STR[];
@@ -505,6 +521,8 @@ void PrintJobRecovery::resume() {
505 521
   gcode.process_subcommands_now(cmd);
506 522
   sprintf_P(cmd, PSTR("M24 S%ld T%ld"), resume_sdpos, info.print_job_elapsed);
507 523
   gcode.process_subcommands_now(cmd);
524
+
525
+  TERN_(DEBUG_POWER_LOSS_RECOVERY, marlin_debug_flags = old_flags);
508 526
 }
509 527
 
510 528
 #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
@@ -584,6 +602,8 @@ void PrintJobRecovery::resume() {
584 602
         DEBUG_ECHOLNPAIR("sd_filename: ", info.sd_filename);
585 603
         DEBUG_ECHOLNPAIR("sdpos: ", info.sdpos);
586 604
         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));
587 607
       }
588 608
       else
589 609
         DEBUG_ECHOLNPGM("INVALID DATA");

+ 10
- 1
Marlin/src/feature/powerloss.h View File

@@ -107,6 +107,12 @@ typedef struct {
107 107
   // Job elapsed time
108 108
   millis_t print_job_elapsed;
109 109
 
110
+  // Misc. Marlin flags
111
+  struct {
112
+    bool dryrun:1;                // M111 S8
113
+    bool allow_cold_extrusion:1;  // M302 P1
114
+  } flag;
115
+
110 116
   uint8_t valid_foot;
111 117
 
112 118
   bool valid() { return valid_head && valid_head == valid_foot; }
@@ -173,7 +179,10 @@ class PrintJobRecovery {
173 179
       }
174 180
     #endif
175 181
 
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(); }
177 186
 
178 187
     #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
179 188
       static void debug(PGM_P const prefix);

+ 2
- 0
Marlin/src/gcode/feature/powerloss/M1000.cpp View File

@@ -62,6 +62,8 @@ void GcodeSuite::M1000() {
62 62
     if (parser.seen('S')) {
63 63
       #if HAS_LCD_MENU
64 64
         ui.goto_screen(menu_job_recovery);
65
+      #elif ENABLED(DWIN_CREALITY_LCD)
66
+        recovery.dwin_flag = true;
65 67
       #elif ENABLED(EXTENSIBLE_UI)
66 68
         ExtUI::onPowerLossResume();
67 69
       #else

+ 1
- 0
Marlin/src/gcode/feature/powerloss/M413.cpp View File

@@ -50,6 +50,7 @@ void GcodeSuite::M413() {
50 50
     if (parser.seen("RL")) recovery.load();
51 51
     if (parser.seen('W')) recovery.save(true);
52 52
     if (parser.seen('P')) recovery.purge();
53
+    if (parser.seen('D')) recovery.debug(PSTR("M413"));
53 54
     #if PIN_EXISTS(POWER_LOSS)
54 55
       if (parser.seen('O')) recovery._outage();
55 56
     #endif

Loading…
Cancel
Save