🎨 Flatten manage_media code

This commit is contained in:
Scott Lahteine
2022-04-17 21:18:39 -05:00
parent 5eeb6e0bca
commit fb54d06582

View File

@@ -476,11 +476,15 @@ void CardReader::manage_media() {
uint8_t stat = uint8_t(IS_SD_INSERTED());
if (stat == prev_stat) return;
DEBUG_ECHOLNPGM("SD: Status changed from ", prev_stat, " to ", stat);
DEBUG_SECTION(mm, "CardReader::manage_media", true);
DEBUG_ECHOLNPGM("SD Status ", prev_stat, " -> ", stat);
flag.workDirIsRoot = true; // Return to root on mount/release
if (ui.detected()) {
if (!ui.detected()) {
DEBUG_ECHOLNPGM("SD: No UI Detected.");
return;
}
uint8_t old_stat = prev_stat;
prev_stat = stat; // Change now to prevent re-entry
@@ -502,21 +506,20 @@ void CardReader::manage_media() {
ui.media_changed(old_stat, stat); // Update the UI
if (stat) {
if (!stat) return; // Exit if no media is present
TERN_(SDCARD_EEPROM_EMULATION, settings.first_load());
if (old_stat == 2) { // First mount?
if (old_stat != 2) return; // First mount?
DEBUG_ECHOLNPGM("First mount.");
#if ENABLED(POWER_LOSS_RECOVERY)
recovery.check(); // Check for PLR file. (If not there then call autofile_begin)
#elif DISABLED(NO_SD_AUTOSTART)
autofile_begin(); // Look for auto0.g on the next loop
#endif
}
}
}
else
DEBUG_ECHOLNPGM("SD: No UI Detected.");
}
/**
* "Release" the media by clearing the 'mounted' flag.