@@ -61,7 +61,7 @@ bool Power::psu_on;
6161 #include " spindle_laser.h"
6262 #endif
6363
64- millis_t Power::lastPowerOn;
64+ millis_t Power::lastPowerOn; // = 0
6565#endif
6666
6767#if PSU_TRACK_STATE_MS
@@ -169,8 +169,9 @@ void Power::power_off() {
169169#if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
170170
171171 #if ENABLED(POWER_OFF_TIMER)
172- millis_t Power::power_off_time = 0 ;
173- void Power::setPowerOffTimer (const millis_t delay_ms) { power_off_time = millis () + delay_ms; }
172+ millis_t Power::power_off_start_ms = 0 ;
173+ uint16_t power_off_secs = 0 ;
174+ void Power::setPowerOffTimer (const uint16_t delay_sec) { power_off_start_ms = millis (); power_off_secs = delay_sec; }
174175 #endif
175176
176177 #if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
@@ -179,14 +180,14 @@ void Power::power_off() {
179180 #endif
180181
181182 void Power::cancelAutoPowerOff () {
182- TERN_ (POWER_OFF_TIMER, power_off_time = 0 );
183+ TERN_ (POWER_OFF_TIMER, power_off_secs = 0 );
183184 TERN_ (POWER_OFF_WAIT_FOR_COOLDOWN, power_off_on_cooldown = false );
184185 }
185186
186187 void Power::checkAutoPowerOff () {
187- if (TERN1 (POWER_OFF_TIMER, !power_off_time ) && TERN1 (POWER_OFF_WAIT_FOR_COOLDOWN, !power_off_on_cooldown)) return ;
188+ if (TERN1 (POWER_OFF_TIMER, !power_off_secs ) && TERN1 (POWER_OFF_WAIT_FOR_COOLDOWN, !power_off_on_cooldown)) return ;
188189 if (TERN0 (POWER_OFF_WAIT_FOR_COOLDOWN, power_off_on_cooldown && is_cooling_needed ())) return ;
189- if (TERN0 (POWER_OFF_TIMER, power_off_time && PENDING (millis (), power_off_time ))) return ;
190+ if (TERN0 (POWER_OFF_TIMER, power_off_secs && PENDING (millis (), power_off_start_ms, SEC_TO_MS (power_off_secs) ))) return ;
190191 power_off ();
191192 }
192193
@@ -247,8 +248,9 @@ void Power::power_off() {
247248 * @param pause pause the 'timer'
248249 */
249250 void Power::check (const bool pause) {
250- static millis_t nextPowerCheck = 0 ;
251+ static MTimeout24 lastPowerCheck ;
251252 const millis_t now = millis ();
253+
252254 #if POWER_TIMEOUT > 0
253255 static bool _pause = false ;
254256 if (pause != _pause) {
@@ -257,8 +259,9 @@ void Power::power_off() {
257259 }
258260 if (pause) return ;
259261 #endif
260- if (ELAPSED (now, nextPowerCheck)) {
261- nextPowerCheck = now + 2500UL ;
262+
263+ if (lastPowerCheck.elapsed (now)) {
264+ lastPowerCheck.start (2500 );
262265 if (is_power_needed ())
263266 power_on ();
264267 else if (!lastPowerOn || (POWER_TIMEOUT > 0 && ELAPSED (now, lastPowerOn, SEC_TO_MS (POWER_TIMEOUT))))
0 commit comments