diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 9a6661e97e..82cd3489b9 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1881,6 +1881,8 @@ //#define POWER_LOSS_RETRACT_LEN 10 // (mm) Length of filament to retract on fail #endif + //#define POWER_LOSS_TIMEOUT 10 // (ms) Power loss duration to raise event, three idle() calls otherwise + // Enable if Z homing is needed for proper recovery. 99.9% of the time this should be disabled! //#define POWER_LOSS_RECOVER_ZHOME #if ENABLED(POWER_LOSS_RECOVER_ZHOME) diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index df17f956ed..0e652b8770 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -216,14 +216,23 @@ class PrintJobRecovery { #if PIN_EXISTS(POWER_LOSS) 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(); - } - else - outage_counter = 0; + #if defined(POWER_LOSS_TIMEOUT) + static unsigned long last_power_on; + if ( enabled && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE) { + if (millis() - last_power_on >= POWER_LOSS_TIMEOUT) _outage(); + } + else + last_power_on = millis(); + #else + 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(); + } + else + outage_counter = 0; + #endif } #endif