From 67c7ad1c99287d83fea7f7c231ddd29758e05249 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sat, 25 Nov 2023 15:32:11 +0000 Subject: [PATCH] power panic: improve file position recovery - Only queue M26 for SD prints - Add M110 to set gcode_LastN for host prints - Remove one debug log to save resource (52 bytes) Change in memory: Flash: -14 bytes SRAM: 0 bytes --- Firmware/power_panic.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Firmware/power_panic.cpp b/Firmware/power_panic.cpp index 75ade9878..f326ed15d 100644 --- a/Firmware/power_panic.cpp +++ b/Firmware/power_panic.cpp @@ -462,17 +462,11 @@ void restore_print_from_eeprom(bool mbl_was_active) { SERIAL_ECHOPGM(", feedmultiply:"); MYSERIAL.println(feedmultiply_rec); - if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_SD) { // M23 restore_file_from_sd(); } - // SD: Position in file, USB: g-code line number - uint32_t position = eeprom_read_dword((uint32_t*)(EEPROM_FILE_POSITION)); - SERIAL_ECHOPGM("Position read from eeprom:"); - MYSERIAL.println(position); - // Move to the XY print position in logical coordinates, where the print has been killed, but // without shifting Z along the way. This requires performing the move without mbl. float pos_x = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)); @@ -508,8 +502,19 @@ void restore_print_from_eeprom(bool mbl_was_active) { // Set the fan speed saved at the power panic. enquecommandf_P(PSTR("M106 S%u"), fan_speed_rec); - // Set a position in the file. - enquecommandf_P(PSTR("M26 S%lu"), position); + // SD: Position in file, USB: g-code line number + uint32_t position = eeprom_read_dword((uint32_t*)(EEPROM_FILE_POSITION)); + if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_SD) + { + // Set a position in the file. + enquecommandf_P(PSTR("M26 S%lu"), position); + } + else if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_PRINT_TYPE) == PowerPanic::PRINT_TYPE_USB) + { + // Set line number + enquecommandf_P(PSTR("M110 N%lu"), position); + } + enquecommand_P(PSTR("G4 S0")); enquecommand_P(PSTR("PRUSA uvlo")); }