Skip to content

Commit

Permalink
use POWER_TIMEOUT only if available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eltonlaw committed May 2, 2021
1 parent 05c25b8 commit 1022f36
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Marlin/src/feature/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1022f36

Please sign in to comment.