From 1022f3670ad4b92d0136a14df4c20888334580a2 Mon Sep 17 00:00:00 2001 From: Elton Law Date: Sun, 2 May 2021 01:05:01 -0400 Subject: [PATCH] use POWER_TIMEOUT only if available When it's not set... - Power::check won't call power_off() after some elapsed time - Calculation of lastPowerOn Power::power_off_soon uses a POWER_TIMEOUT of 0 --- Marlin/src/feature/power.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp index 2f19dae7a6b4..ede62ba89be2 100644 --- a/Marlin/src/feature/power.cpp +++ b/Marlin/src/feature/power.cpp @@ -106,8 +106,12 @@ void Power::check() { nextPowerCheck = ms + 2500UL; if (is_power_needed()) power_on(); - else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT))) + else if (!lastPowerOn) power_off(); + #ifdef POWER_TIMEOUT + else if (ELAPSED(ms, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT))) + power_off(); + #endif } } @@ -135,7 +139,11 @@ void Power::power_off() { void Power::power_off_soon() { #if POWER_OFF_DELAY - lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY); + #ifdef POWER_TIMEOUT + lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY); + #else + lastPowerOn = millis() + SEC_TO_MS(POWER_OFF_DELAY); + #endif #else power_off(); #endif