From cecc238f6845f2e52cc84145fecbd4c5f283854b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 27 Nov 2018 14:40:40 -0600 Subject: [PATCH] Save recovery info on SD pause --- Marlin/src/feature/power_loss_recovery.cpp | 6 +++--- Marlin/src/feature/power_loss_recovery.h | 3 ++- Marlin/src/lcd/menu/menu_main.cpp | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Marlin/src/feature/power_loss_recovery.cpp b/Marlin/src/feature/power_loss_recovery.cpp index 5093e09f4..d81911c39 100644 --- a/Marlin/src/feature/power_loss_recovery.cpp +++ b/Marlin/src/feature/power_loss_recovery.cpp @@ -118,7 +118,7 @@ void PrintJobRecovery::load() { /** * Save the current machine state to the power-loss recovery file */ -void PrintJobRecovery::save(const bool force/*=false*/) { +void PrintJobRecovery::save(const bool force/*=false*/, const bool save_queue/*=true*/) { #if SAVE_INFO_INTERVAL_MS > 0 static millis_t next_save_ms; // = 0 @@ -182,8 +182,8 @@ void PrintJobRecovery::save(const bool force/*=false*/) { #endif // Commands in the queue + info.commands_in_queue = save_queue ? commands_in_queue : 0; info.cmd_queue_index_r = cmd_queue_index_r; - info.commands_in_queue = commands_in_queue; COPY(info.command_queue, command_queue); // Elapsed print job time @@ -332,7 +332,7 @@ void PrintJobRecovery::resume() { gcode.process_subcommands_now(cmd); // Process commands from the old pending queue - uint8_t r = info.cmd_queue_index_r, c = info.commands_in_queue; + uint8_t c = info.commands_in_queue, r = info.cmd_queue_index_r; for (; c--; r = (r + 1) % BUFSIZE) gcode.process_subcommands_now(info.command_queue[r]); diff --git a/Marlin/src/feature/power_loss_recovery.h b/Marlin/src/feature/power_loss_recovery.h index 0de0457c0..d2222c779 100644 --- a/Marlin/src/feature/power_loss_recovery.h +++ b/Marlin/src/feature/power_loss_recovery.h @@ -64,7 +64,7 @@ typedef struct { #endif // Command queue - uint8_t cmd_queue_index_r, commands_in_queue; + uint8_t commands_in_queue, cmd_queue_index_r; char command_queue[BUFSIZE][MAX_CMD_SIZE]; // SD Filename and position @@ -104,6 +104,7 @@ class PrintJobRecovery { #else false #endif + , const bool save_queue=true ); static inline bool valid() { return info.valid_head && info.valid_head == info.valid_foot; } diff --git a/Marlin/src/lcd/menu/menu_main.cpp b/Marlin/src/lcd/menu/menu_main.cpp index e7665bba4..b08125f41 100644 --- a/Marlin/src/lcd/menu/menu_main.cpp +++ b/Marlin/src/lcd/menu/menu_main.cpp @@ -37,7 +37,14 @@ #include "../../gcode/queue.h" #include "../../module/printcounter.h" + #if ENABLED(POWER_LOSS_RECOVERY) + #include "../../feature/power_loss_recovery.h" + #endif + void lcd_sdcard_pause() { + #if ENABLED(POWER_LOSS_RECOVERY) + if (recovery.enabled) recovery.save(true, false); + #endif card.pauseSDPrint(); print_job_timer.pause(); #if ENABLED(PARK_HEAD_ON_PAUSE)