From 399a240f846842bb0b0e72db9b1a3b2d85ccb29b Mon Sep 17 00:00:00 2001 From: Cytown Date: Wed, 30 Jun 2021 01:58:11 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Retain=20power=20during=20Pause?= =?UTF-8?q?=20(#22227)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/MarlinCore.cpp | 2 +- Marlin/src/MarlinCore.h | 6 +++++- Marlin/src/feature/power.cpp | 19 ++++++++++++++++--- Marlin/src/feature/power.h | 2 +- Marlin/src/lcd/marlinui.h | 7 +++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 1c2002f795..be1fabfd6e 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -668,7 +668,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) { TERN_(USE_CONTROLLER_FAN, controllerFan.update()); // Check if fan should be turned on to cool stepper drivers down - TERN_(AUTO_POWER_CONTROL, powerManager.check()); + TERN_(AUTO_POWER_CONTROL, powerManager.check(!ui.on_status_screen() || printJobOngoing() || printingIsPaused())); TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check()); diff --git a/Marlin/src/MarlinCore.h b/Marlin/src/MarlinCore.h index 01a1be4d59..243811d7fb 100644 --- a/Marlin/src/MarlinCore.h +++ b/Marlin/src/MarlinCore.h @@ -91,7 +91,11 @@ extern bool wait_for_heatup; #define PSU_OFF_SOON() powerManager.power_off_soon() #else #define PSU_ON() PSU_PIN_ON() - #define PSU_OFF() PSU_PIN_OFF() + #if ENABLED(PS_OFF_SOUND) + #define PSU_OFF() do{ BUZZ(1000, 659); PSU_PIN_OFF(); }while(0) + #else + #define PSU_OFF() PSU_PIN_OFF() + #endif #define PSU_OFF_SOON PSU_OFF #endif #endif diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp index 87f0e9a7a1..f48856db41 100644 --- a/Marlin/src/feature/power.cpp +++ b/Marlin/src/feature/power.cpp @@ -46,6 +46,9 @@ Power powerManager; millis_t Power::lastPowerOn; bool Power::is_power_needed() { + + if (printJobOngoing() || printingIsPaused()) return true; + #if ENABLED(AUTO_POWER_FANS) FANS_LOOP(i) if (thermalManager.fan_speed[i]) return true; #endif @@ -106,9 +109,17 @@ bool Power::is_power_needed() { #define POWER_TIMEOUT 0 #endif -void Power::check() { +void Power::check(const bool pause) { + static bool _pause = false; static millis_t nextPowerCheck = 0; - millis_t now = millis(); + const millis_t now = millis(); + #if POWER_TIMEOUT > 0 + if (pause != _pause) { + lastPowerOn = now + !now; + _pause = pause; + } + if (pause) return; + #endif if (ELAPSED(now, nextPowerCheck)) { nextPowerCheck = now + 2500UL; if (is_power_needed()) @@ -119,7 +130,8 @@ void Power::check() { } void Power::power_on() { - lastPowerOn = millis(); + const millis_t now = millis(); + lastPowerOn = now + !now; if (!powersupply_on) { PSU_PIN_ON(); safe_delay(PSU_POWERUP_DELAY); @@ -143,6 +155,7 @@ 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); + //if (!lastPowerOn) ++lastPowerOn; #else power_off(); #endif diff --git a/Marlin/src/feature/power.h b/Marlin/src/feature/power.h index 2462b9231b..bca5432946 100644 --- a/Marlin/src/feature/power.h +++ b/Marlin/src/feature/power.h @@ -29,7 +29,7 @@ class Power { public: - static void check(); + static void check(const bool pause); static void power_on(); static void power_off(); static void power_off_soon(); diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 79c6f305e8..5b4e88ed5b 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -525,10 +525,13 @@ public: static void draw_select_screen_prompt(PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr); - #elif HAS_WIRED_LCD + #else static constexpr bool on_status_screen() { return true; } - FORCE_INLINE static void run_current_screen() { status_screen(); } + + #if HAS_WIRED_LCD + FORCE_INLINE static void run_current_screen() { status_screen(); } + #endif #endif