My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

powerloss.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * feature/powerloss.cpp - Resume an SD print after power-loss
  24. */
  25. #include "../inc/MarlinConfigPre.h"
  26. #if ENABLED(POWER_LOSS_RECOVERY)
  27. #include "powerloss.h"
  28. #include "../core/macros.h"
  29. bool PrintJobRecovery::enabled; // Initialized by settings.load()
  30. SdFile PrintJobRecovery::file;
  31. job_recovery_info_t PrintJobRecovery::info;
  32. const char PrintJobRecovery::filename[5] = "/PLR";
  33. uint8_t PrintJobRecovery::queue_index_r;
  34. uint32_t PrintJobRecovery::cmd_sdpos, // = 0
  35. PrintJobRecovery::sdpos[BUFSIZE];
  36. #if HAS_DWIN_E3V2_BASIC
  37. bool PrintJobRecovery::dwin_flag; // = false
  38. #endif
  39. #include "../sd/cardreader.h"
  40. #include "../lcd/marlinui.h"
  41. #include "../gcode/queue.h"
  42. #include "../gcode/gcode.h"
  43. #include "../module/motion.h"
  44. #include "../module/planner.h"
  45. #include "../module/printcounter.h"
  46. #include "../module/temperature.h"
  47. #include "../core/serial.h"
  48. #if HOMING_Z_WITH_PROBE
  49. #include "../module/probe.h"
  50. #endif
  51. #if ENABLED(FWRETRACT)
  52. #include "fwretract.h"
  53. #endif
  54. #define DEBUG_OUT ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  55. #include "../core/debug_out.h"
  56. PrintJobRecovery recovery;
  57. #ifndef POWER_LOSS_PURGE_LEN
  58. #define POWER_LOSS_PURGE_LEN 0
  59. #endif
  60. #if DISABLED(BACKUP_POWER_SUPPLY)
  61. #undef POWER_LOSS_RETRACT_LEN // No retract at outage without backup power
  62. #endif
  63. #ifndef POWER_LOSS_RETRACT_LEN
  64. #define POWER_LOSS_RETRACT_LEN 0
  65. #endif
  66. /**
  67. * Clear the recovery info
  68. */
  69. void PrintJobRecovery::init() { memset(&info, 0, sizeof(info)); }
  70. /**
  71. * Enable or disable then call changed()
  72. */
  73. void PrintJobRecovery::enable(const bool onoff) {
  74. enabled = onoff;
  75. changed();
  76. }
  77. /**
  78. * The enabled state was changed:
  79. * - Enabled: Purge the job recovery file
  80. * - Disabled: Write the job recovery file
  81. */
  82. void PrintJobRecovery::changed() {
  83. if (!enabled)
  84. purge();
  85. else if (IS_SD_PRINTING())
  86. save(true);
  87. }
  88. /**
  89. * Check for Print Job Recovery during setup()
  90. *
  91. * If a saved state exists send 'M1000 S' to initiate job recovery.
  92. */
  93. bool PrintJobRecovery::check() {
  94. //if (!card.isMounted()) card.mount();
  95. bool success = false;
  96. if (card.isMounted()) {
  97. load();
  98. success = valid();
  99. if (!success)
  100. cancel();
  101. else
  102. queue.inject(F("M1000S"));
  103. }
  104. return success;
  105. }
  106. /**
  107. * Delete the recovery file and clear the recovery data
  108. */
  109. void PrintJobRecovery::purge() {
  110. init();
  111. card.removeJobRecoveryFile();
  112. }
  113. /**
  114. * Load the recovery data, if it exists
  115. */
  116. void PrintJobRecovery::load() {
  117. if (exists()) {
  118. open(true);
  119. (void)file.read(&info, sizeof(info));
  120. close();
  121. }
  122. debug(F("Load"));
  123. }
  124. /**
  125. * Set info fields that won't change
  126. */
  127. void PrintJobRecovery::prepare() {
  128. card.getAbsFilenameInCWD(info.sd_filename); // SD filename
  129. cmd_sdpos = 0;
  130. }
  131. /**
  132. * Save the current machine state to the power-loss recovery file
  133. */
  134. void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=POWER_LOSS_ZRAISE*/, const bool raised/*=false*/) {
  135. // We don't check IS_SD_PRINTING here so a save may occur during a pause
  136. #if SAVE_INFO_INTERVAL_MS > 0
  137. static millis_t next_save_ms; // = 0
  138. millis_t ms = millis();
  139. #endif
  140. #ifndef POWER_LOSS_MIN_Z_CHANGE
  141. #define POWER_LOSS_MIN_Z_CHANGE 0.05 // Vase-mode-friendly out of the box
  142. #endif
  143. // Did Z change since the last call?
  144. if (force
  145. #if DISABLED(SAVE_EACH_CMD_MODE) // Always save state when enabled
  146. #if SAVE_INFO_INTERVAL_MS > 0 // Save if interval is elapsed
  147. || ELAPSED(ms, next_save_ms)
  148. #endif
  149. // Save if Z is above the last-saved position by some minimum height
  150. || current_position.z > info.current_position.z + POWER_LOSS_MIN_Z_CHANGE
  151. #endif
  152. ) {
  153. #if SAVE_INFO_INTERVAL_MS > 0
  154. next_save_ms = ms + SAVE_INFO_INTERVAL_MS;
  155. #endif
  156. // Set Head and Foot to matching non-zero values
  157. if (!++info.valid_head) ++info.valid_head; // non-zero in sequence
  158. //if (!IS_SD_PRINTING()) info.valid_head = 0;
  159. info.valid_foot = info.valid_head;
  160. // Machine state
  161. // info.sdpos and info.current_position are pre-filled from the Stepper ISR
  162. info.feedrate = uint16_t(MMS_TO_MMM(feedrate_mm_s));
  163. info.zraise = zraise;
  164. info.flag.raised = raised; // Was Z raised before power-off?
  165. TERN_(GCODE_REPEAT_MARKERS, info.stored_repeat = repeat);
  166. TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
  167. TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
  168. E_TERN_(info.active_extruder = active_extruder);
  169. #if DISABLED(NO_VOLUMETRICS)
  170. info.flag.volumetric_enabled = parser.volumetric_enabled;
  171. #if HAS_MULTI_EXTRUDER
  172. EXTRUDER_LOOP() info.filament_size[e] = planner.filament_size[e];
  173. #else
  174. if (parser.volumetric_enabled) info.filament_size[0] = planner.filament_size[active_extruder];
  175. #endif
  176. #endif
  177. #if HAS_EXTRUDERS
  178. HOTEND_LOOP() info.target_temperature[e] = thermalManager.degTargetHotend(e);
  179. #endif
  180. TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.degTargetBed());
  181. #if HAS_FAN
  182. COPY(info.fan_speed, thermalManager.fan_speed);
  183. #endif
  184. #if HAS_LEVELING
  185. info.flag.leveling = planner.leveling_active;
  186. info.fade = TERN0(ENABLE_LEVELING_FADE_HEIGHT, planner.z_fade_height);
  187. #endif
  188. TERN_(GRADIENT_MIX, memcpy(&info.gradient, &mixer.gradient, sizeof(info.gradient)));
  189. #if ENABLED(FWRETRACT)
  190. COPY(info.retract, fwretract.current_retract);
  191. info.retract_hop = fwretract.current_hop;
  192. #endif
  193. // Elapsed print job time
  194. info.print_job_elapsed = print_job_timer.duration();
  195. // Relative axis modes
  196. info.axis_relative = gcode.axis_relative;
  197. // Misc. Marlin flags
  198. info.flag.dryrun = !!(marlin_debug_flags & MARLIN_DEBUG_DRYRUN);
  199. info.flag.allow_cold_extrusion = TERN0(PREVENT_COLD_EXTRUSION, thermalManager.allow_cold_extrude);
  200. write();
  201. }
  202. }
  203. #if PIN_EXISTS(POWER_LOSS)
  204. #if ENABLED(BACKUP_POWER_SUPPLY)
  205. void PrintJobRecovery::retract_and_lift(const_float_t zraise) {
  206. #if POWER_LOSS_RETRACT_LEN || POWER_LOSS_ZRAISE
  207. gcode.set_relative_mode(true); // Use relative coordinates
  208. #if POWER_LOSS_RETRACT_LEN
  209. // Retract filament now
  210. gcode.process_subcommands_now(F("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
  211. #endif
  212. #if POWER_LOSS_ZRAISE
  213. // Raise the Z axis now
  214. if (zraise) {
  215. char cmd[20], str_1[16];
  216. sprintf_P(cmd, PSTR("G0Z%s"), dtostrf(zraise, 1, 3, str_1));
  217. gcode.process_subcommands_now(cmd);
  218. }
  219. #else
  220. UNUSED(zraise);
  221. #endif
  222. //gcode.axis_relative = info.axis_relative;
  223. planner.synchronize();
  224. #endif
  225. }
  226. #endif
  227. #endif // POWER_LOSS_PIN
  228. #if PIN_EXISTS(POWER_LOSS) || ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  229. /**
  230. * An outage was detected by a sensor pin.
  231. * - If not SD printing, let the machine turn off on its own with no "KILL" screen
  232. * - Disable all heaters first to save energy
  233. * - Save the recovery data for the current instant
  234. * - If backup power is available Retract E and Raise Z
  235. * - Go to the KILL screen
  236. */
  237. void PrintJobRecovery::_outage(TERN_(DEBUG_POWER_LOSS_RECOVERY, const bool simulated/*=false*/)) {
  238. #if ENABLED(BACKUP_POWER_SUPPLY)
  239. static bool lock = false;
  240. if (lock) return; // No re-entrance from idle() during retract_and_lift()
  241. lock = true;
  242. #endif
  243. #if POWER_LOSS_ZRAISE
  244. // Get the limited Z-raise to do now or on resume
  245. const float zraise = _MAX(0, _MIN(current_position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - current_position.z);
  246. #else
  247. constexpr float zraise = 0;
  248. #endif
  249. // Save the current position, distance that Z was (or should be) raised,
  250. // and a flag whether the raise was already done here.
  251. if (IS_SD_PRINTING()) save(true, zraise, ENABLED(BACKUP_POWER_SUPPLY));
  252. // Disable all heaters to reduce power loss
  253. thermalManager.disable_all_heaters();
  254. #if ENABLED(BACKUP_POWER_SUPPLY)
  255. // Do a hard-stop of the steppers (with possibly a loud thud)
  256. quickstop_stepper();
  257. // With backup power a retract and raise can be done now
  258. retract_and_lift(zraise);
  259. #endif
  260. if (TERN0(DEBUG_POWER_LOSS_RECOVERY, simulated)) {
  261. card.fileHasFinished();
  262. current_position.reset();
  263. sync_plan_position();
  264. }
  265. else
  266. kill(GET_TEXT_F(MSG_OUTAGE_RECOVERY));
  267. }
  268. #endif // POWER_LOSS_PIN || DEBUG_POWER_LOSS_RECOVERY
  269. /**
  270. * Save the recovery info the recovery file
  271. */
  272. void PrintJobRecovery::write() {
  273. debug(F("Write"));
  274. open(false);
  275. file.seekSet(0);
  276. const int16_t ret = file.write(&info, sizeof(info));
  277. if (ret == -1) DEBUG_ECHOLNPGM("Power-loss file write failed.");
  278. if (!file.close()) DEBUG_ECHOLNPGM("Power-loss file close failed.");
  279. }
  280. /**
  281. * Resume the saved print job
  282. */
  283. void PrintJobRecovery::resume() {
  284. char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
  285. const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
  286. // Apply the dry-run flag if enabled
  287. if (info.flag.dryrun) marlin_debug_flags |= MARLIN_DEBUG_DRYRUN;
  288. // Restore cold extrusion permission
  289. TERN_(PREVENT_COLD_EXTRUSION, thermalManager.allow_cold_extrude = info.flag.allow_cold_extrusion);
  290. #if HAS_LEVELING
  291. // Make sure leveling is off before any G92 and G28
  292. gcode.process_subcommands_now(F("M420 S0 Z0"));
  293. #endif
  294. #if HAS_HEATED_BED
  295. const celsius_t bt = info.target_temperature_bed;
  296. if (bt) {
  297. // Restore the bed temperature
  298. sprintf_P(cmd, PSTR("M190S%i"), bt);
  299. gcode.process_subcommands_now(cmd);
  300. }
  301. #endif
  302. // Heat hotend enough to soften material
  303. #if HAS_HOTEND
  304. HOTEND_LOOP() {
  305. const celsius_t et = _MAX(info.target_temperature[e], 180);
  306. if (et) {
  307. #if HAS_MULTI_HOTEND
  308. sprintf_P(cmd, PSTR("T%iS"), e);
  309. gcode.process_subcommands_now(cmd);
  310. #endif
  311. sprintf_P(cmd, PSTR("M109S%i"), et);
  312. gcode.process_subcommands_now(cmd);
  313. }
  314. }
  315. #endif
  316. // Interpret the saved Z according to flags
  317. const float z_print = info.current_position.z,
  318. z_raised = z_print + info.zraise;
  319. //
  320. // Home the axes that can safely be homed, and
  321. // establish the current position as best we can.
  322. //
  323. gcode.process_subcommands_now(F("G92.9E0")); // Reset E to 0
  324. #if Z_HOME_TO_MAX
  325. float z_now = z_raised;
  326. // If Z homing goes to max then just move back to the "raised" position
  327. sprintf_P(cmd, PSTR(
  328. "G28R0\n" // Home all axes (no raise)
  329. "G1Z%sF1200" // Move Z down to (raised) height
  330. ), dtostrf(z_now, 1, 3, str_1));
  331. gcode.process_subcommands_now(cmd);
  332. #elif DISABLED(BELTPRINTER)
  333. #if ENABLED(POWER_LOSS_RECOVER_ZHOME) && defined(POWER_LOSS_ZHOME_POS)
  334. #define HOMING_Z_DOWN 1
  335. #endif
  336. float z_now = info.flag.raised ? z_raised : z_print;
  337. #if !HOMING_Z_DOWN
  338. // Set Z to the real position
  339. sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 3, str_1));
  340. gcode.process_subcommands_now(cmd);
  341. #endif
  342. // Does Z need to be raised now? It should be raised before homing XY.
  343. if (z_raised > z_now) {
  344. z_now = z_raised;
  345. sprintf_P(cmd, PSTR("G1Z%sF600"), dtostrf(z_now, 1, 3, str_1));
  346. gcode.process_subcommands_now(cmd);
  347. }
  348. // Home XY with no Z raise
  349. gcode.process_subcommands_now(F("G28R0XY")); // No raise during G28
  350. #endif
  351. #if HOMING_Z_DOWN
  352. // Move to a safe XY position and home Z while avoiding the print.
  353. const xy_pos_t p = xy_pos_t(POWER_LOSS_ZHOME_POS) TERN_(HOMING_Z_WITH_PROBE, - probe.offset_xy);
  354. sprintf_P(cmd, PSTR("G1X%sY%sF1000\nG28HZ"), dtostrf(p.x, 1, 3, str_1), dtostrf(p.y, 1, 3, str_2));
  355. gcode.process_subcommands_now(cmd);
  356. #endif
  357. // Mark all axes as having been homed (no effect on current_position)
  358. set_all_homed();
  359. #if HAS_LEVELING
  360. // Restore Z fade and possibly re-enable bed leveling compensation.
  361. // Leveling may already be enabled due to the ENABLE_LEVELING_AFTER_G28 option.
  362. // TODO: Add a G28 parameter to leave leveling disabled.
  363. sprintf_P(cmd, PSTR("M420S%cZ%s"), '0' + (char)info.flag.leveling, dtostrf(info.fade, 1, 1, str_1));
  364. gcode.process_subcommands_now(cmd);
  365. #if !HOMING_Z_DOWN
  366. // The physical Z was adjusted at power-off so undo the M420S1 correction to Z with G92.9.
  367. sprintf_P(cmd, PSTR("G92.9Z%s"), dtostrf(z_now, 1, 1, str_1));
  368. gcode.process_subcommands_now(cmd);
  369. #endif
  370. #endif
  371. #if ENABLED(POWER_LOSS_RECOVER_ZHOME)
  372. // Z was homed down to the bed, so move up to the raised height.
  373. z_now = z_raised;
  374. sprintf_P(cmd, PSTR("G1Z%sF600"), dtostrf(z_now, 1, 3, str_1));
  375. gcode.process_subcommands_now(cmd);
  376. #endif
  377. // Recover volumetric extrusion state
  378. #if DISABLED(NO_VOLUMETRICS)
  379. #if HAS_MULTI_EXTRUDER
  380. EXTRUDER_LOOP() {
  381. sprintf_P(cmd, PSTR("M200T%iD%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1));
  382. gcode.process_subcommands_now(cmd);
  383. }
  384. if (!info.flag.volumetric_enabled) {
  385. sprintf_P(cmd, PSTR("M200T%iD0"), info.active_extruder);
  386. gcode.process_subcommands_now(cmd);
  387. }
  388. #else
  389. if (info.flag.volumetric_enabled) {
  390. sprintf_P(cmd, PSTR("M200D%s"), dtostrf(info.filament_size[0], 1, 3, str_1));
  391. gcode.process_subcommands_now(cmd);
  392. }
  393. #endif
  394. #endif
  395. // Restore all hotend temperatures
  396. #if HAS_HOTEND
  397. HOTEND_LOOP() {
  398. const celsius_t et = info.target_temperature[e];
  399. if (et) {
  400. #if HAS_MULTI_HOTEND
  401. sprintf_P(cmd, PSTR("T%iS"), e);
  402. gcode.process_subcommands_now(cmd);
  403. #endif
  404. sprintf_P(cmd, PSTR("M109S%i"), et);
  405. gcode.process_subcommands_now(cmd);
  406. }
  407. }
  408. #endif
  409. // Restore the previously active tool (with no_move)
  410. #if HAS_MULTI_EXTRUDER || HAS_MULTI_HOTEND
  411. sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
  412. gcode.process_subcommands_now(cmd);
  413. #endif
  414. // Restore print cooling fan speeds
  415. #if HAS_FAN
  416. FANS_LOOP(i) {
  417. const int f = info.fan_speed[i];
  418. if (f) {
  419. sprintf_P(cmd, PSTR("M106P%iS%i"), i, f);
  420. gcode.process_subcommands_now(cmd);
  421. }
  422. }
  423. #endif
  424. // Restore retract and hop state from an active `G10` command
  425. #if ENABLED(FWRETRACT)
  426. EXTRUDER_LOOP() {
  427. if (info.retract[e] != 0.0) {
  428. fwretract.current_retract[e] = info.retract[e];
  429. fwretract.retracted.set(e);
  430. }
  431. }
  432. fwretract.current_hop = info.retract_hop;
  433. #endif
  434. #if ENABLED(GRADIENT_MIX)
  435. memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient));
  436. #endif
  437. // Un-retract if there was a retract at outage
  438. #if ENABLED(BACKUP_POWER_SUPPLY) && POWER_LOSS_RETRACT_LEN > 0
  439. gcode.process_subcommands_now(F("G1F3000E" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
  440. #endif
  441. // Additional purge on resume if configured
  442. #if POWER_LOSS_PURGE_LEN
  443. sprintf_P(cmd, PSTR("G1F3000E%d"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
  444. gcode.process_subcommands_now(cmd);
  445. #endif
  446. #if ENABLED(NOZZLE_CLEAN_FEATURE)
  447. gcode.process_subcommands_now(F("G12"));
  448. #endif
  449. // Move back over to the saved XY
  450. sprintf_P(cmd, PSTR("G1X%sY%sF3000"),
  451. dtostrf(info.current_position.x, 1, 3, str_1),
  452. dtostrf(info.current_position.y, 1, 3, str_2)
  453. );
  454. gcode.process_subcommands_now(cmd);
  455. // Move back down to the saved Z for printing
  456. sprintf_P(cmd, PSTR("G1Z%sF600"), dtostrf(z_print, 1, 3, str_1));
  457. gcode.process_subcommands_now(cmd);
  458. // Restore the feedrate
  459. sprintf_P(cmd, PSTR("G1F%d"), info.feedrate);
  460. gcode.process_subcommands_now(cmd);
  461. // Restore E position with G92.9
  462. sprintf_P(cmd, PSTR("G92.9E%s"), dtostrf(info.current_position.e, 1, 3, str_1));
  463. gcode.process_subcommands_now(cmd);
  464. TERN_(GCODE_REPEAT_MARKERS, repeat = info.stored_repeat);
  465. TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
  466. TERN_(HAS_POSITION_SHIFT, position_shift = info.position_shift);
  467. #if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
  468. LOOP_NUM_AXES(i) update_workspace_offset((AxisEnum)i);
  469. #endif
  470. // Relative axis modes
  471. gcode.axis_relative = info.axis_relative;
  472. #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  473. const uint8_t old_flags = marlin_debug_flags;
  474. marlin_debug_flags |= MARLIN_DEBUG_ECHO;
  475. #endif
  476. // Continue to apply PLR when a file is resumed!
  477. enable(true);
  478. // Resume the SD file from the last position
  479. char *fn = info.sd_filename;
  480. sprintf_P(cmd, M23_STR, fn);
  481. gcode.process_subcommands_now(cmd);
  482. sprintf_P(cmd, PSTR("M24S%ldT%ld"), resume_sdpos, info.print_job_elapsed);
  483. gcode.process_subcommands_now(cmd);
  484. TERN_(DEBUG_POWER_LOSS_RECOVERY, marlin_debug_flags = old_flags);
  485. }
  486. #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
  487. void PrintJobRecovery::debug(FSTR_P const prefix) {
  488. DEBUG_ECHOF(prefix);
  489. DEBUG_ECHOLNPGM(" Job Recovery Info...\nvalid_head:", info.valid_head, " valid_foot:", info.valid_foot);
  490. if (info.valid_head) {
  491. if (info.valid_head == info.valid_foot) {
  492. DEBUG_ECHOPGM("current_position: ");
  493. LOOP_LOGICAL_AXES(i) {
  494. if (i) DEBUG_CHAR(',');
  495. DEBUG_DECIMAL(info.current_position[i]);
  496. }
  497. DEBUG_EOL();
  498. DEBUG_ECHOLNPGM("feedrate: ", info.feedrate);
  499. DEBUG_ECHOLNPGM("zraise: ", info.zraise, " ", info.flag.raised ? "(before)" : "");
  500. #if ENABLED(GCODE_REPEAT_MARKERS)
  501. DEBUG_ECHOLNPGM("repeat index: ", info.stored_repeat.index);
  502. LOOP_L_N(i, info.stored_repeat.index)
  503. DEBUG_ECHOLNPGM("..... sdpos: ", info.stored_repeat.marker.sdpos, " count: ", info.stored_repeat.marker.counter);
  504. #endif
  505. #if HAS_HOME_OFFSET
  506. DEBUG_ECHOPGM("home_offset: ");
  507. LOOP_NUM_AXES(i) {
  508. if (i) DEBUG_CHAR(',');
  509. DEBUG_DECIMAL(info.home_offset[i]);
  510. }
  511. DEBUG_EOL();
  512. #endif
  513. #if HAS_POSITION_SHIFT
  514. DEBUG_ECHOPGM("position_shift: ");
  515. LOOP_NUM_AXES(i) {
  516. if (i) DEBUG_CHAR(',');
  517. DEBUG_DECIMAL(info.position_shift[i]);
  518. }
  519. DEBUG_EOL();
  520. #endif
  521. #if HAS_MULTI_EXTRUDER
  522. DEBUG_ECHOLNPGM("active_extruder: ", info.active_extruder);
  523. #endif
  524. #if DISABLED(NO_VOLUMETRICS)
  525. DEBUG_ECHOPGM("filament_size:");
  526. EXTRUDER_LOOP() DEBUG_ECHOLNPGM(" ", info.filament_size[e]);
  527. DEBUG_EOL();
  528. #endif
  529. #if HAS_HOTEND
  530. DEBUG_ECHOPGM("target_temperature: ");
  531. HOTEND_LOOP() {
  532. DEBUG_ECHO(info.target_temperature[e]);
  533. if (e < HOTENDS - 1) DEBUG_CHAR(',');
  534. }
  535. DEBUG_EOL();
  536. #endif
  537. #if HAS_HEATED_BED
  538. DEBUG_ECHOLNPGM("target_temperature_bed: ", info.target_temperature_bed);
  539. #endif
  540. #if HAS_FAN
  541. DEBUG_ECHOPGM("fan_speed: ");
  542. FANS_LOOP(i) {
  543. DEBUG_ECHO(info.fan_speed[i]);
  544. if (i < FAN_COUNT - 1) DEBUG_CHAR(',');
  545. }
  546. DEBUG_EOL();
  547. #endif
  548. #if HAS_LEVELING
  549. DEBUG_ECHOLNPGM("leveling: ", info.flag.leveling ? "ON" : "OFF", " fade: ", info.fade);
  550. #endif
  551. #if ENABLED(FWRETRACT)
  552. DEBUG_ECHOPGM("retract: ");
  553. EXTRUDER_LOOP() {
  554. DEBUG_ECHO(info.retract[e]);
  555. if (e < EXTRUDERS - 1) DEBUG_CHAR(',');
  556. }
  557. DEBUG_EOL();
  558. DEBUG_ECHOLNPGM("retract_hop: ", info.retract_hop);
  559. #endif
  560. // Mixing extruder and gradient
  561. #if BOTH(MIXING_EXTRUDER, GRADIENT_MIX)
  562. DEBUG_ECHOLNPGM("gradient: ", info.gradient.enabled ? "ON" : "OFF");
  563. #endif
  564. DEBUG_ECHOLNPGM("sd_filename: ", info.sd_filename);
  565. DEBUG_ECHOLNPGM("sdpos: ", info.sdpos);
  566. DEBUG_ECHOLNPGM("print_job_elapsed: ", info.print_job_elapsed);
  567. DEBUG_ECHOPGM("axis_relative:");
  568. if (TEST(info.axis_relative, REL_X)) DEBUG_ECHOPGM(" REL_X");
  569. if (TEST(info.axis_relative, REL_Y)) DEBUG_ECHOPGM(" REL_Y");
  570. if (TEST(info.axis_relative, REL_Z)) DEBUG_ECHOPGM(" REL_Z");
  571. if (TEST(info.axis_relative, REL_E)) DEBUG_ECHOPGM(" REL_E");
  572. if (TEST(info.axis_relative, E_MODE_ABS)) DEBUG_ECHOPGM(" E_MODE_ABS");
  573. if (TEST(info.axis_relative, E_MODE_REL)) DEBUG_ECHOPGM(" E_MODE_REL");
  574. DEBUG_EOL();
  575. DEBUG_ECHOLNPGM("flag.dryrun: ", AS_DIGIT(info.flag.dryrun));
  576. DEBUG_ECHOLNPGM("flag.allow_cold_extrusion: ", AS_DIGIT(info.flag.allow_cold_extrusion));
  577. DEBUG_ECHOLNPGM("flag.volumetric_enabled: ", AS_DIGIT(info.flag.volumetric_enabled));
  578. }
  579. else
  580. DEBUG_ECHOLNPGM("INVALID DATA");
  581. }
  582. DEBUG_ECHOLNPGM("---");
  583. }
  584. #endif // DEBUG_POWER_LOSS_RECOVERY
  585. #endif // POWER_LOSS_RECOVERY