From 977792961c98ccb200e21e8ed39ff4c8d252e0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Mon, 9 Oct 2023 15:06:56 +0000 Subject: [PATCH] power panic: only send M23 for SD prints If the saved printing type was USB, then EEPROM_FILENAME does not contain anything. The firmware should also not be trying to open a file on a SD card which is maybe not even mounted. Change in memory: Flash: +12 bytes SRAM: 0 bytes --- Firmware/power_panic.cpp | 41 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/Firmware/power_panic.cpp b/Firmware/power_panic.cpp index f439c9c40..e4a7e8856 100644 --- a/Firmware/power_panic.cpp +++ b/Firmware/power_panic.cpp @@ -423,23 +423,12 @@ bool recover_machine_state_after_power_panic() { return mbl_was_active; } -void restore_print_from_eeprom(bool mbl_was_active) { - int feedrate_rec; - int feedmultiply_rec; - uint8_t fan_speed_rec; +/// @brief Read saved filename from EEPROM and send g-code command: M23 +void restore_file_from_sd() +{ char filename[FILENAME_LENGTH]; - uint8_t depth = 0; char dir_name[9]; - - fan_speed_rec = eeprom_read_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED); - feedrate_rec = eeprom_read_word((uint16_t*)EEPROM_UVLO_FEEDRATE); - feedmultiply_rec = eeprom_read_word((uint16_t*)EEPROM_UVLO_FEEDMULTIPLY); - SERIAL_ECHOPGM("Feedrate:"); - MYSERIAL.print(feedrate_rec); - SERIAL_ECHOPGM(", feedmultiply:"); - MYSERIAL.println(feedmultiply_rec); - - depth = eeprom_read_byte((uint8_t*)EEPROM_DIR_DEPTH); + uint8_t depth = eeprom_read_byte((uint8_t*)EEPROM_DIR_DEPTH); MYSERIAL.println(int(depth)); for (uint8_t i = 0; i < depth; i++) { @@ -459,6 +448,28 @@ void restore_print_from_eeprom(bool mbl_was_active) { MYSERIAL.print(filename); strcat_P(filename, PSTR(".gco")); enquecommandf_P(MSG_M23, filename); +} + +void restore_print_from_eeprom(bool mbl_was_active) { + int feedrate_rec; + int feedmultiply_rec; + uint8_t fan_speed_rec; + + fan_speed_rec = eeprom_read_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED); + feedrate_rec = eeprom_read_word((uint16_t*)EEPROM_UVLO_FEEDRATE); + feedmultiply_rec = eeprom_read_word((uint16_t*)EEPROM_UVLO_FEEDMULTIPLY); + SERIAL_ECHOPGM("Feedrate:"); + MYSERIAL.print(feedrate_rec); + 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);