This commit is contained in:
Vovodroid 2026-02-28 21:33:17 -08:00 committed by GitHub
commit bcce87cadb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 8 deletions

View file

@ -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)

View file

@ -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