|
@@ -472,50 +472,53 @@ void CardReader::mount() {
|
472
|
472
|
#endif
|
473
|
473
|
|
474
|
474
|
void CardReader::manage_media() {
|
475
|
|
- static uint8_t prev_stat = 2; // First call, no prior state
|
|
475
|
+ static uint8_t prev_stat = 2; // First call, no prior state
|
476
|
476
|
uint8_t stat = uint8_t(IS_SD_INSERTED());
|
477
|
477
|
if (stat == prev_stat) return;
|
478
|
478
|
|
479
|
|
- DEBUG_ECHOLNPGM("SD: Status changed from ", prev_stat, " to ", stat);
|
|
479
|
+ DEBUG_SECTION(mm, "CardReader::manage_media", true);
|
|
480
|
+ DEBUG_ECHOLNPGM("SD Status ", prev_stat, " -> ", stat);
|
480
|
481
|
|
481
|
|
- flag.workDirIsRoot = true; // Return to root on mount/release
|
|
482
|
+ flag.workDirIsRoot = true; // Return to root on mount/release
|
482
|
483
|
|
483
|
|
- if (ui.detected()) {
|
|
484
|
+ if (!ui.detected()) {
|
|
485
|
+ DEBUG_ECHOLNPGM("SD: No UI Detected.");
|
|
486
|
+ return;
|
|
487
|
+ }
|
484
|
488
|
|
485
|
|
- uint8_t old_stat = prev_stat;
|
486
|
|
- prev_stat = stat; // Change now to prevent re-entry
|
|
489
|
+ uint8_t old_stat = prev_stat;
|
|
490
|
+ prev_stat = stat; // Change now to prevent re-entry
|
487
|
491
|
|
488
|
|
- if (stat) { // Media Inserted
|
489
|
|
- safe_delay(500); // Some boards need a delay to get settled
|
490
|
|
- if (TERN1(SD_IGNORE_AT_STARTUP, old_stat != 2))
|
491
|
|
- mount(); // Try to mount the media
|
492
|
|
- #if MB(FYSETC_CHEETAH, FYSETC_CHEETAH_V12, FYSETC_AIO_II)
|
493
|
|
- reset_stepper_drivers(); // Workaround for Cheetah bug
|
494
|
|
- #endif
|
495
|
|
- if (!isMounted()) stat = 0; // Not mounted?
|
496
|
|
- }
|
497
|
|
- else {
|
498
|
|
- #if PIN_EXISTS(SD_DETECT)
|
499
|
|
- release(); // Card is released
|
500
|
|
- #endif
|
501
|
|
- }
|
|
492
|
+ if (stat) { // Media Inserted
|
|
493
|
+ safe_delay(500); // Some boards need a delay to get settled
|
|
494
|
+ if (TERN1(SD_IGNORE_AT_STARTUP, old_stat != 2))
|
|
495
|
+ mount(); // Try to mount the media
|
|
496
|
+ #if MB(FYSETC_CHEETAH, FYSETC_CHEETAH_V12, FYSETC_AIO_II)
|
|
497
|
+ reset_stepper_drivers(); // Workaround for Cheetah bug
|
|
498
|
+ #endif
|
|
499
|
+ if (!isMounted()) stat = 0; // Not mounted?
|
|
500
|
+ }
|
|
501
|
+ else {
|
|
502
|
+ #if PIN_EXISTS(SD_DETECT)
|
|
503
|
+ release(); // Card is released
|
|
504
|
+ #endif
|
|
505
|
+ }
|
502
|
506
|
|
503
|
|
- ui.media_changed(old_stat, stat); // Update the UI
|
|
507
|
+ ui.media_changed(old_stat, stat); // Update the UI
|
504
|
508
|
|
505
|
|
- if (stat) {
|
506
|
|
- TERN_(SDCARD_EEPROM_EMULATION, settings.first_load());
|
507
|
|
- if (old_stat == 2) { // First mount?
|
508
|
|
- DEBUG_ECHOLNPGM("First mount.");
|
509
|
|
- #if ENABLED(POWER_LOSS_RECOVERY)
|
510
|
|
- recovery.check(); // Check for PLR file. (If not there then call autofile_begin)
|
511
|
|
- #elif DISABLED(NO_SD_AUTOSTART)
|
512
|
|
- autofile_begin(); // Look for auto0.g on the next loop
|
513
|
|
- #endif
|
514
|
|
- }
|
515
|
|
- }
|
516
|
|
- }
|
517
|
|
- else
|
518
|
|
- DEBUG_ECHOLNPGM("SD: No UI Detected.");
|
|
509
|
+ if (!stat) return; // Exit if no media is present
|
|
510
|
+
|
|
511
|
+ TERN_(SDCARD_EEPROM_EMULATION, settings.first_load());
|
|
512
|
+
|
|
513
|
+ if (old_stat != 2) return; // First mount?
|
|
514
|
+
|
|
515
|
+ DEBUG_ECHOLNPGM("First mount.");
|
|
516
|
+
|
|
517
|
+ #if ENABLED(POWER_LOSS_RECOVERY)
|
|
518
|
+ recovery.check(); // Check for PLR file. (If not there then call autofile_begin)
|
|
519
|
+ #elif DISABLED(NO_SD_AUTOSTART)
|
|
520
|
+ autofile_begin(); // Look for auto0.g on the next loop
|
|
521
|
+ #endif
|
519
|
522
|
}
|
520
|
523
|
|
521
|
524
|
/**
|