M81 D / S - Power-off Delay (#23396, #23455)

This commit is contained in:
John Lagonikas
2022-01-03 18:11:39 +02:00
committed by Scott Lahteine
parent b6c37960e8
commit 2690bb1bc2
9 changed files with 134 additions and 42 deletions

View File

@ -27,7 +27,9 @@
#include "../inc/MarlinConfig.h"
#include "power.h"
#include "../module/planner.h"
#include "../module/stepper.h"
#include "../module/temperature.h"
#include "../MarlinCore.h"
#if ENABLED(PS_OFF_SOUND)
@ -75,6 +77,10 @@ void Power::power_on() {
if (psu_on) return;
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
cancelAutoPowerOff();
#endif
OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE);
psu_on = true;
safe_delay(PSU_POWERUP_DELAY);
@ -89,7 +95,6 @@ void Power::power_on() {
/**
* Power off if the power is currently on.
* Processes any PSU_POWEROFF_GCODE and makes a PS_OFF_SOUND if enabled.
*
*/
void Power::power_off() {
if (!psu_on) return;
@ -104,8 +109,57 @@ void Power::power_off() {
OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE);
psu_on = false;
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
cancelAutoPowerOff();
#endif
}
#if EITHER(AUTO_POWER_CONTROL, POWER_OFF_WAIT_FOR_COOLDOWN)
bool Power::is_cooling_needed() {
#if HAS_HOTEND && AUTO_POWER_E_TEMP
HOTEND_LOOP() if (thermalManager.degHotend(e) >= (AUTO_POWER_E_TEMP)) return true;
#endif
#if HAS_HEATED_CHAMBER && AUTO_POWER_CHAMBER_TEMP
if (thermalManager.degChamber() >= (AUTO_POWER_CHAMBER_TEMP)) return true;
#endif
#if HAS_COOLER && AUTO_POWER_COOLER_TEMP
if (thermalManager.degCooler() >= (AUTO_POWER_COOLER_TEMP)) return true;
#endif
return false;
}
#endif
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
#if ENABLED(POWER_OFF_TIMER)
millis_t Power::power_off_time = 0;
void Power::setPowerOffTimer(const millis_t delay_ms) { power_off_time = millis() + delay_ms; }
#endif
#if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
bool Power::power_off_on_cooldown = false;
void Power::setPowerOffOnCooldown(const bool ena) { power_off_on_cooldown = ena; }
#endif
void Power::cancelAutoPowerOff() {
TERN_(POWER_OFF_TIMER, power_off_time = 0);
TERN_(POWER_OFF_WAIT_FOR_COOLDOWN, power_off_on_cooldown = false);
}
void Power::checkAutoPowerOff() {
if (TERN1(POWER_OFF_TIMER, !power_off_time) && TERN1(POWER_OFF_WAIT_FOR_COOLDOWN, !power_off_on_cooldown)) return;
if (TERN0(POWER_OFF_WAIT_FOR_COOLDOWN, power_off_on_cooldown && is_cooling_needed())) return;
if (TERN0(POWER_OFF_TIMER, power_off_time && PENDING(millis(), power_off_time))) return;
power_off();
}
#endif // POWER_OFF_TIMER || POWER_OFF_WAIT_FOR_COOLDOWN
#if ENABLED(AUTO_POWER_CONTROL)
@ -149,19 +203,7 @@ void Power::power_off() {
if (TERN0(HAS_HEATED_BED, thermalManager.degTargetBed() > 0 || thermalManager.temp_bed.soft_pwm_amount > 0)) return true;
#if HAS_HOTEND && AUTO_POWER_E_TEMP
HOTEND_LOOP() if (thermalManager.degHotend(e) >= (AUTO_POWER_E_TEMP)) return true;
#endif
#if HAS_HEATED_CHAMBER && AUTO_POWER_CHAMBER_TEMP
if (thermalManager.degChamber() >= (AUTO_POWER_CHAMBER_TEMP)) return true;
#endif
#if HAS_COOLER && AUTO_POWER_COOLER_TEMP
if (thermalManager.degCooler() >= (AUTO_POWER_COOLER_TEMP)) return true;
#endif
return false;
return is_cooling_needed();
}
/**
@ -193,7 +235,6 @@ void Power::power_off() {
/**
* Power off with a delay. Power off is triggered by check() after the delay.
*
*/
void Power::power_off_soon() {
lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY);

View File

@ -36,21 +36,37 @@ class Power {
static void init();
static void power_on();
static void power_off();
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
#if ENABLED(POWER_OFF_TIMER)
static millis_t power_off_time;
static void setPowerOffTimer(const millis_t delay_ms);
#endif
#if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
static bool power_off_on_cooldown;
static void setPowerOffOnCooldown(const bool ena);
#endif
static void cancelAutoPowerOff();
static void checkAutoPowerOff();
#endif
#if ENABLED(AUTO_POWER_CONTROL) && POWER_OFF_DELAY > 0
static void power_off_soon();
#else
static void power_off_soon() { power_off(); }
#endif
#if ENABLED(AUTO_POWER_CONTROL) && POWER_OFF_DELAY > 0
static void power_off_soon();
#else
static void power_off_soon() { power_off(); }
#endif
#if ENABLED(AUTO_POWER_CONTROL)
static void check(const bool pause);
#if ENABLED(AUTO_POWER_CONTROL)
static void check(const bool pause);
private:
static millis_t lastPowerOn;
static bool is_power_needed();
#endif
private:
static millis_t lastPowerOn;
static bool is_power_needed();
static bool is_cooling_needed();
#elif ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
private:
static bool is_cooling_needed();
#endif
};
extern Power powerManager;