From 21d0130626510230406067080d131d235ceded13 Mon Sep 17 00:00:00 2001 From: gudnimg Date: Sat, 14 Oct 2023 13:41:22 +0000 Subject: [PATCH] power panic: simplify recovering SD filename We can just read the whole EEPROM block since short filenames are always null terminated. strcat_P will then apply the file extension at the correct position. Change in memory: Flash: -24 bytes SRAM: 0 bytes --- Firmware/power_panic.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Firmware/power_panic.cpp b/Firmware/power_panic.cpp index f03cbabe1..fc6d77264 100644 --- a/Firmware/power_panic.cpp +++ b/Firmware/power_panic.cpp @@ -438,11 +438,9 @@ void restore_file_from_sd() card.chdir(dir_name, false); } - for (uint8_t i = 0; i < 8; i++) { - const char c = eeprom_read_byte((uint8_t*)EEPROM_FILENAME + i); - filename[i] = c; - if (c == '\0') break; // Filename is shorter than 8 characters - } + // Recover DOS 8.3 filename without extension. + // Short filenames are always null terminated. + eeprom_read_block(filename, (const char *)EEPROM_FILENAME, 8); // Add null delimiter in case all 8 characters were not NULL filename[8] = '\0';