Merge pull request #4421 from gudnimg/sd-card-mount-opt

cleanup: Don't set root directory if SD card fails to mount + 3 renames
This commit is contained in:
3d-gussner 2024-01-22 09:11:19 +01:00 committed by GitHub
commit b80965731f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 42 deletions

View File

@ -1369,9 +1369,9 @@ void setup()
// Force SD card update. Otherwise the SD card update is done from loop() on card.checkautostart(false), // Force SD card update. Otherwise the SD card update is done from loop() on card.checkautostart(false),
// but this times out if a blocking dialog is shown in setup(). // but this times out if a blocking dialog is shown in setup().
card.initsd(); card.mount();
#ifdef DEBUG_SD_SPEED_TEST #ifdef DEBUG_SD_SPEED_TEST
if (card.cardOK) if (card.mounted)
{ {
uint8_t* buff = (uint8_t*)block_buffer; uint8_t* buff = (uint8_t*)block_buffer;
uint32_t block = 0; uint32_t block = 0;
@ -5251,7 +5251,7 @@ void process_commands()
### M21 - Init SD card <a href="https://reprap.org/wiki/G-code#M21:_Initialize_SD_card">M21: Initialize SD card</a> ### M21 - Init SD card <a href="https://reprap.org/wiki/G-code#M21:_Initialize_SD_card">M21: Initialize SD card</a>
*/ */
case 21: case 21:
card.initsd(); card.mount();
break; break;
/*! /*!
@ -5316,7 +5316,7 @@ void process_commands()
- `S` - Index in bytes - `S` - Index in bytes
*/ */
case 26: case 26:
if(card.cardOK && code_seen('S')) { if(card.mounted && code_seen('S')) {
long index = code_value_long(); long index = code_value_long();
card.setIndex(index); card.setIndex(index);
// We don't disable interrupt during update of sdpos_atomic // We don't disable interrupt during update of sdpos_atomic
@ -5361,7 +5361,7 @@ void process_commands()
*/ */
case 30: case 30:
if (card.cardOK){ if (card.mounted){
card.closefile(); card.closefile();
card.removeFile(strchr_pointer + 4); card.removeFile(strchr_pointer + 4);
} }
@ -5391,7 +5391,7 @@ void process_commands()
if(strchr_pointer>namestartpos) if(strchr_pointer>namestartpos)
call_procedure=false; //false alert, 'P' found within filename call_procedure=false; //false alert, 'P' found within filename
if( card.cardOK ) if( card.mounted )
{ {
card.openFileReadFilteredGcode(namestartpos,!call_procedure); card.openFileReadFilteredGcode(namestartpos,!call_procedure);
if(code_seen('S')) if(code_seen('S'))

View File

@ -24,7 +24,7 @@ CardReader::CardReader()
filesize = 0; filesize = 0;
sdpos = 0; sdpos = 0;
sdprinting = false; sdprinting = false;
cardOK = false; mounted = false;
saving = false; saving = false;
logging = false; logging = false;
workDirDepth = 0; workDirDepth = 0;
@ -198,9 +198,9 @@ void CardReader::ls(ls_param params)
} }
void CardReader::initsd(bool doPresort/* = true*/) void CardReader::mount(bool doPresort/* = true*/)
{ {
cardOK = false; mounted = false;
if(root.isOpen()) if(root.isOpen())
root.close(); root.close();
#ifdef SDSLOW #ifdef SDSLOW
@ -226,33 +226,21 @@ void CardReader::initsd(bool doPresort/* = true*/)
} }
else else
{ {
cardOK = true; mounted = true;
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNRPGM(_n("SD card ok"));////MSG_SD_CARD_OK SERIAL_ECHOLNRPGM(_n("SD card ok"));////MSG_SD_CARD_OK
} }
workDir=root;
curDir=&root;
workDirDepth = 0;
#ifdef SDCARD_SORT_ALPHA if (mounted)
if (doPresort)
presort();
#endif
/*
if(!workDir.openRoot(&volume))
{ {
SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL); cdroot(doPresort);
} }
*/
} }
void CardReader::setroot(bool doPresort) void __attribute__((noinline)) CardReader::cdroot(bool doPresort)
{ {
workDir=root; workDir=root;
workDirDepth = 0; workDirDepth = 0;
curDir=&workDir; curDir=&workDir;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
if (doPresort) if (doPresort)
@ -264,14 +252,14 @@ void CardReader::setroot(bool doPresort)
void CardReader::release() void CardReader::release()
{ {
sdprinting = false; sdprinting = false;
cardOK = false; mounted = false;
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNRPGM(_n("SD card released"));////MSG_SD_CARD_RELEASED SERIAL_ECHOLNRPGM(_n("SD card released"));////MSG_SD_CARD_RELEASED
} }
void CardReader::startFileprint() void CardReader::startFileprint()
{ {
if(cardOK) if(mounted)
{ {
sdprinting = true; sdprinting = true;
SetPrinterState(PrinterState::IsSDPrinting); //set printer state to hide LCD menu SetPrinterState(PrinterState::IsSDPrinting); //set printer state to hide LCD menu
@ -346,7 +334,7 @@ bool CardReader::diveSubfolder (const char *&fileName)
const char *dirname_start, *dirname_end; const char *dirname_start, *dirname_end;
if (fileName[0] == '/') // absolute path if (fileName[0] == '/') // absolute path
{ {
setroot(false); cdroot(false);
dirname_start = fileName + 1; dirname_start = fileName + 1;
while (*dirname_start) while (*dirname_start)
{ {
@ -396,7 +384,7 @@ static const char ofSDPrinting[] PROGMEM = "SD-PRINTING";
static const char ofWritingToFile[] PROGMEM = "Writing to file: "; static const char ofWritingToFile[] PROGMEM = "Writing to file: ";
void CardReader::openFileReadFilteredGcode(const char* name, bool replace_current/* = false*/){ void CardReader::openFileReadFilteredGcode(const char* name, bool replace_current/* = false*/){
if(!cardOK) if(!mounted)
return; return;
if(file.isOpen()){ //replacing current file by new file, or subfile call if(file.isOpen()){ //replacing current file by new file, or subfile call
@ -461,7 +449,7 @@ void CardReader::openFileReadFilteredGcode(const char* name, bool replace_curren
void CardReader::openFileWrite(const char* name) void CardReader::openFileWrite(const char* name)
{ {
if(!cardOK) if(!mounted)
return; return;
if(file.isOpen()){ //replacing current file by new file, or subfile call if(file.isOpen()){ //replacing current file by new file, or subfile call
#if 0 #if 0
@ -525,7 +513,7 @@ void CardReader::openFileWrite(const char* name)
void CardReader::removeFile(const char* name) void CardReader::removeFile(const char* name)
{ {
if(!cardOK) return; if(!mounted) return;
file.close(); file.close();
sdprinting = false; sdprinting = false;
@ -626,10 +614,10 @@ void CardReader::checkautostart(bool force)
return; return;
} }
autostart_stilltocheck = false; autostart_stilltocheck = false;
if(!cardOK) if(!mounted)
{ {
initsd(); mount();
if(!cardOK) //fail if(!mounted) //fail
return; return;
} }

View File

@ -27,7 +27,7 @@ public:
inline ls_param(bool LFN, bool timestamp):LFN(LFN), timestamp(timestamp) { } inline ls_param(bool LFN, bool timestamp):LFN(LFN), timestamp(timestamp) { }
} __attribute__((packed)); } __attribute__((packed));
void initsd(bool doPresort = true); void mount(bool doPresort = true);
void write_command(char *buf); void write_command(char *buf);
void write_command_no_newline(char *buf); void write_command_no_newline(char *buf);
//files auto[0-9].g on the sd card are performed in a row //files auto[0-9].g on the sd card are performed in a row
@ -59,7 +59,7 @@ public:
void ls(ls_param params); void ls(ls_param params);
bool chdir(const char * relpath, bool doPresort); bool chdir(const char * relpath, bool doPresort);
void updir(); void updir();
void setroot(bool doPresort); void cdroot(bool doPresort);
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
void presort(); void presort();
@ -91,7 +91,7 @@ public:
bool saving; bool saving;
bool logging; bool logging;
bool sdprinting ; bool sdprinting ;
bool cardOK ; bool mounted;
char filename[FILENAME_LENGTH]; char filename[FILENAME_LENGTH];
// There are scenarios when simple modification time is not enough (on MS Windows) // There are scenarios when simple modification time is not enough (on MS Windows)
// Therefore these timestamps hold the most recent one of creation/modification date/times // Therefore these timestamps hold the most recent one of creation/modification date/times

View File

@ -5233,7 +5233,7 @@ static void lcd_main_menu()
// Menu item for reprint // Menu item for reprint
if(!printer_active() && (heating_status == HeatingStatus::NO_HEATING)) { if(!printer_active() && (heating_status == HeatingStatus::NO_HEATING)) {
if ((GetPrinterState() == PrinterState::SDPrintingFinished) && card.cardOK) { if ((GetPrinterState() == PrinterState::SDPrintingFinished) && card.mounted) {
MENU_ITEM_FUNCTION_P(_T(MSG_REPRINT), lcd_reprint_from_eeprom); MENU_ITEM_FUNCTION_P(_T(MSG_REPRINT), lcd_reprint_from_eeprom);
} else if ((GetPrinterState() == PrinterState::HostPrintingFinished) && M79_timer_get_status()) { } else if ((GetPrinterState() == PrinterState::HostPrintingFinished) && M79_timer_get_status()) {
MENU_ITEM_FUNCTION_P(_T(MSG_REPRINT), lcd_send_action_start); MENU_ITEM_FUNCTION_P(_T(MSG_REPRINT), lcd_send_action_start);
@ -5298,7 +5298,7 @@ static void lcd_main_menu()
) )
{ {
#ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code #ifdef SDSUPPORT //!@todo SDSUPPORT undefined creates several issues in source code
if (card.cardOK || lcd_commands_type != LcdCommands::Idle) { if (card.mounted || lcd_commands_type != LcdCommands::Idle) {
if (!card.isFileOpen()) { if (!card.isFileOpen()) {
if (!usb_timer.running() && (lcd_commands_type == LcdCommands::Idle)) { if (!usb_timer.running() && (lcd_commands_type == LcdCommands::Idle)) {
bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function bMain=true; // flag ('fake parameter') for 'lcd_sdcard_menu()' function
@ -5625,7 +5625,7 @@ static void lcd_control_temperature_menu()
static void lcd_sd_refresh() static void lcd_sd_refresh()
{ {
#if SDCARDDETECT == -1 #if SDCARDDETECT == -1
card.initsd(); card.mount();
#else #else
card.presort(); card.presort();
#endif #endif
@ -7363,9 +7363,9 @@ void menu_lcd_lcdupdate_func(void)
backlight_wake(); backlight_wake();
if (lcd_oldcardstatus) if (lcd_oldcardstatus)
{ {
if (!card.cardOK) if (!card.mounted)
{ {
card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back() card.mount(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back()
card.presort_flag = true; //force sorting of the SD menu card.presort_flag = true; //force sorting of the SD menu
} }
LCD_MESSAGERPGM(MSG_WELCOME); LCD_MESSAGERPGM(MSG_WELCOME);