From 1292ff76b34c15cf6bc78259985440e13b5cb1f8 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 7 May 2021 22:37:31 -0500 Subject: [PATCH] Debounce for Power-Loss pin --- Marlin/src/feature/powerloss.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index 03e467432c..df3ae222a2 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -186,8 +186,14 @@ class PrintJobRecovery { #if PIN_EXISTS(POWER_LOSS) static inline void outage() { - if (enabled && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE) - _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; } #endif