diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index 74008ed55a..e880f802dc 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -108,13 +108,18 @@ void PrintJobRecovery::changed() { * * If a saved state exists send 'M1000 S' to initiate job recovery. */ -void PrintJobRecovery::check() { +bool PrintJobRecovery::check() { //if (!card.isMounted()) card.mount(); + bool success = false; if (card.isMounted()) { load(); - if (!valid()) return cancel(); - queue.inject(F("M1000S")); + success = valid(); + if (!success) + cancel(); + else + queue.inject(F("M1000S")); } + return success; } /** diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index 4e97109bb7..33d9dc007c 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -176,11 +176,11 @@ class PrintJobRecovery { static void open(const bool read) { card.openJobRecoveryFile(read); } static void close() { file.close(); } - static void check(); + static bool check(); static void resume(); static void purge(); - static void cancel() { purge(); IF_DISABLED(NO_SD_AUTOSTART, card.autofile_begin()); } + static void cancel() { purge(); } static void load(); static void save(const bool force=ENABLED(SAVE_EACH_CMD_MODE), const float zraise=POWER_LOSS_ZRAISE, const bool raised=false); diff --git a/Marlin/src/gcode/feature/powerloss/M413.cpp b/Marlin/src/gcode/feature/powerloss/M413.cpp index 4807d3e8f9..f6d82b0ad9 100644 --- a/Marlin/src/gcode/feature/powerloss/M413.cpp +++ b/Marlin/src/gcode/feature/powerloss/M413.cpp @@ -49,7 +49,7 @@ void GcodeSuite::M413() { if (parser.seen_test('P')) recovery.purge(); if (parser.seen_test('D')) recovery.debug(F("M413")); if (parser.seen_test('O')) recovery._outage(true); - if (parser.seen_test('C')) recovery.check(); + if (parser.seen_test('C')) (void)recovery.check(); if (parser.seen_test('E')) SERIAL_ECHOF(recovery.exists() ? F("PLR Exists\n") : F("No PLR\n")); if (parser.seen_test('V')) SERIAL_ECHOF(recovery.valid() ? F("Valid\n") : F("Invalid\n")); #endif diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h index 9f4a66b707..9250ee1127 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h @@ -27,7 +27,7 @@ #define BOARD_WEBSITE_URL "fysetc.com" #define BOARD_NO_NATIVE_USB - +#define RESET_STEPPERS_ON_MEDIA_INSERT #define DISABLE_JTAG #define pins_v2_20190128 // new pins define diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h index c473a37d3e..beda50d29b 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h @@ -32,7 +32,7 @@ //#define BOGUS_TEMPERATURE_GRACE_PERIOD 2000 #define BOARD_NO_NATIVE_USB - +#define RESET_STEPPERS_ON_MEDIA_INSERT #define DISABLE_JTAG #if EITHER(NO_EEPROM_SELECTED, FLASH_EEPROM_EMULATION) diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 652a44e526..ec5f1a9709 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -472,50 +472,55 @@ void CardReader::mount() { #endif void CardReader::manage_media() { - static uint8_t prev_stat = 2; // First call, no prior state + static uint8_t prev_stat = 2; // First call, no prior state 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 + flag.workDirIsRoot = true; // Return to root on mount/release - if (ui.detected()) { - - uint8_t old_stat = prev_stat; - prev_stat = stat; // Change now to prevent re-entry - - if (stat) { // Media Inserted - safe_delay(500); // Some boards need a delay to get settled - if (TERN1(SD_IGNORE_AT_STARTUP, old_stat != 2)) - mount(); // Try to mount the media - #if MB(FYSETC_CHEETAH, FYSETC_CHEETAH_V12, FYSETC_AIO_II) - reset_stepper_drivers(); // Workaround for Cheetah bug - #endif - if (!isMounted()) stat = 0; // Not mounted? - } - else { - #if PIN_EXISTS(SD_DETECT) - release(); // Card is released - #endif - } - - ui.media_changed(old_stat, stat); // Update the UI - - if (stat) { - TERN_(SDCARD_EEPROM_EMULATION, settings.first_load()); - if (old_stat == 2) { // 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 + 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 + + if (stat) { // Media Inserted + safe_delay(500); // Some boards need a delay to get settled + + // Try to mount the media (only later with SD_IGNORE_AT_STARTUP) + if (TERN1(SD_IGNORE_AT_STARTUP, old_stat != 2)) mount(); + if (!isMounted()) stat = 0; // Not mounted? + + TERN_(RESET_STEPPERS_ON_MEDIA_INSERT, reset_stepper_drivers()); // Workaround for Cheetah bug + } + else { + #if PIN_EXISTS(SD_DETECT) + release(); // Card is released + #endif + } + + ui.media_changed(old_stat, stat); // Update the UI + + if (!stat) return; // Exit if no media is present + + TERN_(SDCARD_EEPROM_EMULATION, settings.first_load()); + + if (old_stat != 2) return; // First mount? + + DEBUG_ECHOLNPGM("First mount."); + + bool do_auto = true; UNUSED(do_auto); + + // Check for PLR file. + TERN_(POWER_LOSS_RECOVERY, if (recovery.check()) do_auto = false); + + // Look for auto0.g on the next idle() + IF_DISABLED(NO_SD_AUTOSTART, if (do_auto) autofile_begin()); } /**