From 67403603edfda7898ce28e649ee8b625fe6e9479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 25 Jun 2023 16:51:53 +0000 Subject: [PATCH] power panic: Re-use saving print file state This also adds the Gcode position into EEPROM for Octoprint/PrusaLink prints. Though the recovery part doesn't support that yet. --- Firmware/Marlin.h | 3 +++ Firmware/Marlin_main.cpp | 2 +- Firmware/power_panic.cpp | 9 ++------- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 99bdc1c6a..7ecc248e8 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -297,6 +297,7 @@ extern bool mesh_bed_leveling_flag; // save/restore printing extern bool saved_printing; +extern uint32_t saved_sdpos; extern uint8_t saved_printing_type; #define PRINTING_TYPE_SD 0 #define PRINTING_TYPE_USB 1 @@ -384,6 +385,8 @@ extern void print_world_coordinates(); extern void print_physical_coordinates(); extern void print_mesh_bed_leveling_table(); +void save_print_file_state(); +void restore_print_file_state(); extern void stop_and_save_print_to_ram(float z_move, float e_move); void restore_extruder_temperature_from_ram(); extern void restore_print_from_ram_and_continue(float e_move); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0a26dabf6..6e9e6cd70 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -309,7 +309,7 @@ static bool chdkActive = false; //! @name RAM save/restore printing //! @{ bool saved_printing = false; //!< Print is paused and saved in RAM -static uint32_t saved_sdpos = 0; //!< SD card position, or line number in case of USB printing +uint32_t saved_sdpos = 0; //!< SD card position, or line number in case of USB printing uint8_t saved_printing_type = PRINTING_TYPE_SD; static float saved_pos[4] = { X_COORD_INVALID, 0, 0, 0 }; static uint16_t saved_feedrate2 = 0; //!< Default feedrate (truncated from float) diff --git a/Firmware/power_panic.cpp b/Firmware/power_panic.cpp index 24683f74c..33c48004b 100644 --- a/Firmware/power_panic.cpp +++ b/Firmware/power_panic.cpp @@ -60,12 +60,7 @@ void uvlo_() { setTargetBed(0); // Calculate the file position, from which to resume this print. - long sd_position = sdpos_atomic; //atomic sd position of last command added in queue - uint16_t sdlen_planner = planner_calc_sd_length(); //length of sd commands in planner - sd_position -= sdlen_planner; - uint16_t sdlen_cmdqueue = cmdqueue_calc_sd_length(); //length of sd commands in cmdqueue - sd_position -= sdlen_cmdqueue; - if (sd_position < 0) sd_position = 0; + save_print_file_state(); // save the global state at planning time bool pos_invalid = mesh_bed_leveling_flag || homing_flag; @@ -134,7 +129,7 @@ void uvlo_() { poweroff_z(); // Write the file position. - eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position); + eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), saved_sdpos); // Store the mesh bed leveling offsets. This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case. for (uint8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point)