From 621a508c767e16e547ff8b00e77a3b51285a248a Mon Sep 17 00:00:00 2001 From: vovodroid Date: Thu, 11 Jan 2024 10:07:26 +0200 Subject: [PATCH 1/4] Add auto restart If PLR auto resume enabled. --- Marlin/Configuration_adv.h | 2 ++ Marlin/src/MarlinCore.cpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 49eea39180f7..558a2b357dfa 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1750,6 +1750,7 @@ //#define POWER_LOSS_PIN 44 // Pin to detect power-loss. Set to -1 to disable default pin on boards without module, or comment to use board default. //#define POWER_LOSS_STATE HIGH // State of pin indicating power-loss + #endif //#define POWER_LOSS_PULLUP // Set pullup / pulldown as appropriate for your sensor //#define POWER_LOSS_PULLDOWN @@ -1763,6 +1764,7 @@ //#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power-loss #if ENABLED(BACKUP_POWER_SUPPLY) //#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail + //#define PLR_REBOOT_TIMEOUT 60 // (seconds) Restart after power loss if it returned while UPS still had power. #endif // Enable if Z homing is needed for proper recovery. 99.9% of the time this should be disabled! diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 53a74871efbb..66c958371405 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -938,9 +938,15 @@ void minkill(const bool steppers_off/*=false*/) { hal.reboot(); #else - - for (;;) hal.watchdog_refresh(); // Wait for RESET button or power-cycle - + #if defined(PLR_REBOOT_TIMEOUT) + for (uint16_t i = 0; i < PLR_REBOOT_TIMEOUT; i++) { + hal.watchdog_refresh(); + delayMicroseconds(1000000UL); + } + hal.reboot(); + #else + for (;;) hal.watchdog_refresh(); // Wait for RESET button or power-cycle + #endif #endif } From e95f1d9acc97acc118a5d85c805e0ab20c4ef358 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 19 Jan 2024 13:43:34 -0600 Subject: [PATCH 2/4] tweak --- Marlin/src/MarlinCore.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 66c958371405..16a07918f8e0 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -937,16 +937,18 @@ void minkill(const bool steppers_off/*=false*/) { // Reboot the board hal.reboot(); + #elif defined(PLR_REBOOT_TIMEOUT) + + for (uint16_t i = 0; i < PLR_REBOOT_TIMEOUT; i++) { + hal.watchdog_refresh(); + delay(1000); + } + hal.reboot(); + #else - #if defined(PLR_REBOOT_TIMEOUT) - for (uint16_t i = 0; i < PLR_REBOOT_TIMEOUT; i++) { - hal.watchdog_refresh(); - delayMicroseconds(1000000UL); - } - hal.reboot(); - #else - for (;;) hal.watchdog_refresh(); // Wait for RESET button or power-cycle - #endif + + for (;;) hal.watchdog_refresh(); // Wait for RESET button or power-cycle + #endif } From 935b3c669cc9da12eedafa43339e69fc62369bfb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 19 Jan 2024 13:46:08 -0600 Subject: [PATCH 3/4] clarify ? --- Marlin/Configuration_adv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 558a2b357dfa..323471133073 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1764,7 +1764,7 @@ //#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power-loss #if ENABLED(BACKUP_POWER_SUPPLY) //#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail - //#define PLR_REBOOT_TIMEOUT 60 // (seconds) Restart after power loss if it returned while UPS still had power. + //#define PLR_REBOOT_TIMEOUT 60 // (seconds) Restart after power loss if UPS never lost power #endif // Enable if Z homing is needed for proper recovery. 99.9% of the time this should be disabled! From ca7752acc8b5de7f1c0021851405c9e430d4bd5d Mon Sep 17 00:00:00 2001 From: vovodroid Date: Sat, 20 Jan 2024 14:44:04 +0200 Subject: [PATCH 4/4] Auto reboot only on power loss. --- Marlin/Configuration_adv.h | 1 - Marlin/src/MarlinCore.cpp | 19 ++++++++++--------- Marlin/src/feature/powerloss.cpp | 4 ++++ Marlin/src/feature/powerloss.h | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 323471133073..470fb46fcaca 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1750,7 +1750,6 @@ //#define POWER_LOSS_PIN 44 // Pin to detect power-loss. Set to -1 to disable default pin on boards without module, or comment to use board default. //#define POWER_LOSS_STATE HIGH // State of pin indicating power-loss - #endif //#define POWER_LOSS_PULLUP // Set pullup / pulldown as appropriate for your sensor //#define POWER_LOSS_PULLDOWN diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 16a07918f8e0..2dacd1c0e0df 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -936,17 +936,18 @@ void minkill(const bool steppers_off/*=false*/) { // Reboot the board hal.reboot(); - - #elif defined(PLR_REBOOT_TIMEOUT) - - for (uint16_t i = 0; i < PLR_REBOOT_TIMEOUT; i++) { - hal.watchdog_refresh(); - delay(1000); - } - hal.reboot(); - #else + #if defined(PLR_REBOOT_TIMEOUT) + if (PrintJobRecovery::outage_counter > 0) { + for (uint16_t i = 0; i < PLR_REBOOT_TIMEOUT; i++) { + hal.watchdog_refresh(); + delay(1000); + } + hal.reboot(); + } + #endif + for (;;) hal.watchdog_refresh(); // Wait for RESET button or power-cycle #endif diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index 70fac66fce39..def4ea8c1327 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -41,6 +41,10 @@ bool PrintJobRecovery::enabled; // Initialized by settings.load() celsius_t PrintJobRecovery::bed_temp_threshold; // Initialized by settings.load() #endif +#if PIN_EXISTS(POWER_LOSS) + uint8_t PrintJobRecovery::outage_counter; // = 0 +#endif + MediaFile PrintJobRecovery::file; job_recovery_info_t PrintJobRecovery::info; const char PrintJobRecovery::filename[5] = "/PLR"; diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index 579731ffddcb..ac6a61e49d6f 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -199,9 +199,9 @@ class PrintJobRecovery { static void save(const bool force=ENABLED(SAVE_EACH_CMD_MODE), const float zraise=POWER_LOSS_ZRAISE, const bool raised=false); #if PIN_EXISTS(POWER_LOSS) + static uint8_t outage_counter; static void outage() { static constexpr uint8_t OUTAGE_THRESHOLD = 3; - static uint8_t outage_counter = 0; if (enabled && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE) { outage_counter++; if (outage_counter >= OUTAGE_THRESHOLD) _outage();