diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 72e2d5e17..2b8d16862 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -307,6 +307,7 @@ extern uint16_t saved_extruder_temperature; //!< Active extruder temperature extern uint8_t saved_bed_temperature; //!< Bed temperature extern bool saved_extruder_relative_mode; extern uint8_t saved_fan_speed; //!< Print fan speed, ranges from 0 to 255 +extern float saved_pos[NUM_AXIS]; extern uint16_t saved_feedrate2; //estimated time to end of the print diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 60fe27e0e..1c4256be4 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -311,7 +311,7 @@ static bool chdkActive = false; bool saved_printing = false; //!< Print is paused and saved in RAM 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 }; +float saved_pos[NUM_AXIS] = { X_COORD_INVALID, 0, 0, 0 }; uint16_t saved_feedrate2 = 0; //!< Default feedrate (truncated from float) static int saved_feedmultiply2 = 0; uint16_t saved_extruder_temperature; //!< Active extruder temperature diff --git a/Firmware/power_panic.cpp b/Firmware/power_panic.cpp index df5b8e475..3035aca21 100644 --- a/Firmware/power_panic.cpp +++ b/Firmware/power_panic.cpp @@ -71,15 +71,20 @@ void uvlo_() { saved_extruder_relative_mode = axis_relative_modes & E_AXIS_MASK; } - // Stop all heaters + // Stop all heaters before continuing setTargetHotend(0); setTargetBed(0); - // Calculate the file position, from which to resume this print. - save_print_file_state(); + if (!sd_print_saved_in_ram) { + // Calculate the file position, from which to resume this print. + save_print_file_state(); - // save the global state at planning time - save_planner_global_state(); + // save the global state at planning time + save_planner_global_state(); + + memcpy(saved_pos, current_position, sizeof(saved_pos)); + if (pos_invalid) saved_pos[X_AXIS] = X_COORD_INVALID; + } // From this point on and up to the print recovery, Z should not move during X/Y travels and // should be controlled precisely. Reset the MBL status before planner_abort_hard in order to @@ -94,12 +99,12 @@ void uvlo_() { // Store the print logical Z position, which we need to recover (a slight error here would be // recovered on the next Gcode instruction, while a physical location error would not) - float logical_z = current_position[Z_AXIS]; - if(mbl_was_active) logical_z -= mbl.get_z(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS)); + float logical_z = saved_pos[Z_AXIS]; + if(mbl_was_active) logical_z = current_position[Z_AXIS] - mbl.get_z(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS)); eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z, logical_z); // Store the print E position before we lose track - eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]); + eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), saved_pos[E_AXIS]); eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, !saved_extruder_relative_mode); // Clean the input command queue, inhibit serial processing using saved_printing @@ -150,13 +155,8 @@ void uvlo_() { eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps); // Store the current position. - if (pos_invalid) - eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), X_COORD_INVALID); - else - { - eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]); - eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]); - } + eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), saved_pos[X_AXIS]); + eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), saved_pos[Y_AXIS]); // Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates) eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDRATE, saved_feedrate2);