Browse Source

Improve Power-Loss Recovery (#19540)

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

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

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

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

107
   // Job elapsed time
107
   // Job elapsed time
108
   millis_t print_job_elapsed;
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
   uint8_t valid_foot;
116
   uint8_t valid_foot;
111
 
117
 
112
   bool valid() { return valid_head && valid_head == valid_foot; }
118
   bool valid() { return valid_head && valid_head == valid_foot; }
173
       }
179
       }
174
     #endif
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
     #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
187
     #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
179
       static void debug(PGM_P const prefix);
188
       static void debug(PGM_P const prefix);

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

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

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

50
     if (parser.seen("RL")) recovery.load();
50
     if (parser.seen("RL")) recovery.load();
51
     if (parser.seen('W')) recovery.save(true);
51
     if (parser.seen('W')) recovery.save(true);
52
     if (parser.seen('P')) recovery.purge();
52
     if (parser.seen('P')) recovery.purge();
53
+    if (parser.seen('D')) recovery.debug(PSTR("M413"));
53
     #if PIN_EXISTS(POWER_LOSS)
54
     #if PIN_EXISTS(POWER_LOSS)
54
       if (parser.seen('O')) recovery._outage();
55
       if (parser.seen('O')) recovery._outage();
55
     #endif
56
     #endif

Loading…
Cancel
Save