From 44118ff8270f46c658f0eb1afda6d6e0f58aac45 Mon Sep 17 00:00:00 2001 From: InsanityAutomation Date: Sun, 14 Jan 2024 15:17:45 -0500 Subject: [PATCH 1/6] Redundant Power control with EDM - First Pass --- Marlin/Configuration.h | 11 ++++++++++- Marlin/src/MarlinCore.cpp | 19 +++++++++++++++++++ Marlin/src/feature/power.cpp | 25 +++++++++++++++++++++++++ Marlin/src/feature/power.h | 6 +++++- Marlin/src/inc/SanityCheck.h | 2 ++ Marlin/src/lcd/language/language_en.h | 2 ++ Marlin/src/pins/pinsDebug_list.h | 3 +++ Marlin/src/pins/pins_postprocess.h | 4 ++++ 8 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 6e4afa16c6a5..709a63f101c5 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -392,7 +392,7 @@ * Enable and connect the power supply to the PS_ON_PIN. * Specify whether the power supply is active HIGH or active LOW. */ -//#define PSU_CONTROL +#define PSU_CONTROL //#define PSU_NAME "Power Supply" #if ENABLED(PSU_CONTROL) @@ -405,6 +405,15 @@ //#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power //#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay + #define PSU_OFF_REDUNDANT // Second pin for redundant power control + //#define PSU_OFF_REDUNDANT_OPPOSING // Redundant pin works opposite standard pin + + #define PS_ON1_PIN 6 // Redundant Pin + + #define PS_ON_EDM_PIN 8 // EDM Pins to monitor feedback on external power control relay. Fault on mismatch. + #define PS_ON1_EDM_PIN 8 + #define PS_EDM_RESPONSE 250 // Time in MS to allow for relay action + //#define POWER_OFF_TIMER // Enable M81 D to power off after a delay //#define POWER_OFF_WAIT_FOR_COOLDOWN // Enable M81 S to power off only after cooldown diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 91496b1c5c50..e571d3ce9ab5 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -671,6 +671,25 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) { TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check()); + #if ANY(PSU_CONTROL, AUTO_POWER_CONTROL) + #if defined(PS_ON_EDM_PIN) + if(ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)) + { + if(READ(PS_ON_PIN)!=READ(PS_ON_EDM_PIN)) + kill(GET_TEXT_F(PS_ON_EDM_FAIL)); + } + #endif + + #if defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT) + if(ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)) + { + if(READ(PS_ON1_PIN)!=READ(PS_ON1_EDM_PIN)) + kill(GET_TEXT_F(PS_ON1_EDM_FAIL)); + } + + #endif + #endif + #if ENABLED(EXTRUDER_RUNOUT_PREVENT) if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP) && ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS)) diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp index e908c8292fd6..c003be136369 100644 --- a/Marlin/src/feature/power.cpp +++ b/Marlin/src/feature/power.cpp @@ -60,6 +60,10 @@ bool Power::psu_on; millis_t Power::lastPowerOn; #endif +#if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) + static millis_t Power::last_state_change_ms = 0; +#endif + /** * Initialize pins & state for the power manager. * @@ -87,6 +91,16 @@ void Power::power_on() { #endif OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE); + #if ENABLED(PSU_OFF_REDUNDANT) + #if (ENABLED(PSU_OFF_REDUNDANT_OPPOSING)) + OUT_WRITE(PS_ON1_PIN, !PSU_ACTIVE_STATE); + #else + OUT_WRITE(PS_ON1_PIN, PSU_ACTIVE_STATE); + #endif + #endif + #if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) + last_state_change_ms = millis(); + #endif psu_on = true; safe_delay(PSU_POWERUP_DELAY); restore_stepper_drivers(); @@ -117,6 +131,17 @@ void Power::power_off() { #endif OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); + #if ENABLED(PSU_OFF_REDUNDANT) + #if (ENABLED(PSU_OFF_REDUNDANT_OPPOSING)) + OUT_WRITE(PS_ON1_PIN, PSU_ACTIVE_STATE); + #else + OUT_WRITE(PS_ON1_PIN, !PSU_ACTIVE_STATE); + #endif + #endif + #if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) + last_state_change_ms = millis(); + #endif + psu_on = false; #if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN) diff --git a/Marlin/src/feature/power.h b/Marlin/src/feature/power.h index fdbb7126ceae..480c6e8a5b35 100644 --- a/Marlin/src/feature/power.h +++ b/Marlin/src/feature/power.h @@ -25,7 +25,7 @@ * power.h - power control */ -#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER) +#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER) || defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) #include "../core/millis_t.h" #endif @@ -37,6 +37,10 @@ class Power { static void power_on(); static void power_off(); + #if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) + static millis_t last_state_change_ms; + #endif + #if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN) #if ENABLED(POWER_OFF_TIMER) static millis_t power_off_time; diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index a60ead1d08e4..796a3d78ded0 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -3641,6 +3641,8 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive." #error "POWER_OFF_DELAY must be a positive value." #elif ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN) && !(defined(AUTO_POWER_E_TEMP) || defined(AUTO_POWER_CHAMBER_TEMP) || defined(AUTO_POWER_COOLER_TEMP)) #error "POWER_OFF_WAIT_FOR_COOLDOWN requires AUTO_POWER_E_TEMP, AUTO_POWER_CHAMBER_TEMP, and/or AUTO_POWER_COOLER_TEMP." + #elif ENABLED(PSU_OFF_REDUNDANT) && !PIN_EXISTS(PS_ON1) + #error "PSU_OFF_REDUNDANT requires PS_ON1_PIN." #endif #endif diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index 553d9013a243..6ccb76de4394 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -155,6 +155,8 @@ namespace LanguageNarrow_en { LSTR MSG_SPINDLE_REVERSE = _UxGT("Spindle Reverse"); LSTR MSG_SWITCH_PS_ON = _UxGT("Switch Power On"); LSTR MSG_SWITCH_PS_OFF = _UxGT("Switch Power Off"); + LSTR PS_ON_EDM_FAIL = _UxGT("PS_ON EDM Fault"); + LSTR PS_ON1_EDM_FAIL = _UxGT("PS_ON1 EDM Fault"); LSTR MSG_EXTRUDE = _UxGT("Extrude"); LSTR MSG_RETRACT = _UxGT("Retract"); LSTR MSG_MOVE_AXIS = _UxGT("Move Axis"); diff --git a/Marlin/src/pins/pinsDebug_list.h b/Marlin/src/pins/pinsDebug_list.h index fa6cbf49b945..58f42598a06f 100644 --- a/Marlin/src/pins/pinsDebug_list.h +++ b/Marlin/src/pins/pinsDebug_list.h @@ -901,6 +901,9 @@ #if PIN_EXISTS(PS_ON) REPORT_NAME_DIGITAL(__LINE__, PS_ON_PIN) #endif +#if PIN_EXISTS(PS_ON1) + REPORT_NAME_DIGITAL(__LINE__, PS_ON1_PIN) +#endif // // LCD diff --git a/Marlin/src/pins/pins_postprocess.h b/Marlin/src/pins/pins_postprocess.h index e97b6ceaa440..e8c77a08cd82 100644 --- a/Marlin/src/pins/pins_postprocess.h +++ b/Marlin/src/pins/pins_postprocess.h @@ -477,6 +477,10 @@ #undef PS_ON_PIN #define PS_ON_PIN -1 #endif +#if DISABLED(PSU_OFF_REDUNDANT) || DISABLED(PSU_CONTROL) || !defined(PS_ON1_PIN) + #undef PS_ON1_PIN + #define PS_ON1_PIN -1 +#endif #ifndef KILL_PIN #define KILL_PIN -1 #endif From 455aa475c685c5932f8b4ef7b9f91cb2203769c9 Mon Sep 17 00:00:00 2001 From: InsanityAutomation Date: Sun, 14 Jan 2024 15:39:53 -0500 Subject: [PATCH 2/6] Default configs, fix extra static --- Marlin/Configuration.h | 10 +++++----- Marlin/src/feature/power.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 709a63f101c5..b5c67e23948a 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -392,7 +392,7 @@ * Enable and connect the power supply to the PS_ON_PIN. * Specify whether the power supply is active HIGH or active LOW. */ -#define PSU_CONTROL +//#define PSU_CONTROL //#define PSU_NAME "Power Supply" #if ENABLED(PSU_CONTROL) @@ -405,13 +405,13 @@ //#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power //#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay - #define PSU_OFF_REDUNDANT // Second pin for redundant power control + //#define PSU_OFF_REDUNDANT // Second pin for redundant power control //#define PSU_OFF_REDUNDANT_OPPOSING // Redundant pin works opposite standard pin - #define PS_ON1_PIN 6 // Redundant Pin + //#define PS_ON1_PIN 6 // Redundant Pin - #define PS_ON_EDM_PIN 8 // EDM Pins to monitor feedback on external power control relay. Fault on mismatch. - #define PS_ON1_EDM_PIN 8 + //#define PS_ON_EDM_PIN 8 // EDM Pins to monitor feedback on external power control relay. Fault on mismatch. + //#define PS_ON1_EDM_PIN 9 #define PS_EDM_RESPONSE 250 // Time in MS to allow for relay action //#define POWER_OFF_TIMER // Enable M81 D to power off after a delay diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp index c003be136369..6fa91b3826c9 100644 --- a/Marlin/src/feature/power.cpp +++ b/Marlin/src/feature/power.cpp @@ -61,7 +61,7 @@ bool Power::psu_on; #endif #if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) - static millis_t Power::last_state_change_ms = 0; + millis_t Power::last_state_change_ms = 0; #endif /** From 8486329d1251a96a996acd2112d81fa85deb49c1 Mon Sep 17 00:00:00 2001 From: InsanityAutomation Date: Tue, 30 Jan 2024 11:53:50 -0500 Subject: [PATCH 3/6] Use extended read function instead --- Marlin/src/MarlinCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index e571d3ce9ab5..9d7bada97ff1 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -683,7 +683,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) { #if defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT) if(ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)) { - if(READ(PS_ON1_PIN)!=READ(PS_ON1_EDM_PIN)) + if(extDigitalRead(PS_ON1_PIN)!=extDigitalRead(PS_ON1_EDM_PIN)) kill(GET_TEXT_F(PS_ON1_EDM_FAIL)); } From acf36e8812fb6fe2726691c11c0390a14c1c0ce2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 31 Jan 2024 19:57:38 -0600 Subject: [PATCH 4/6] clean up --- Marlin/Configuration.h | 18 +++++++++--------- Marlin/src/MarlinCore.cpp | 21 ++++----------------- Marlin/src/feature/power.cpp | 18 +++++------------- Marlin/src/feature/power.h | 4 ++-- Marlin/src/lcd/language/language_en.h | 3 +-- Marlin/src/pins/pins_postprocess.h | 2 +- 6 files changed, 22 insertions(+), 44 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index b5c67e23948a..a14812192d2b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -401,18 +401,18 @@ //#define PS_OFF_SOUND // Beep 1s when power off #define PSU_ACTIVE_STATE LOW // Set 'LOW' for ATX, 'HIGH' for X-Box - //#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80 - //#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power - //#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay + //#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80 + //#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power + //#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay - //#define PSU_OFF_REDUNDANT // Second pin for redundant power control - //#define PSU_OFF_REDUNDANT_OPPOSING // Redundant pin works opposite standard pin + //#define PSU_OFF_REDUNDANT // Second pin for redundant power control + //#define PSU_OFF_REDUNDANT_INVERTED // Redundant pin works opposite standard pin - //#define PS_ON1_PIN 6 // Redundant Pin + //#define PS_ON1_PIN 6 // Redundant pin required to enable power in combination with PS_ON_PIN - //#define PS_ON_EDM_PIN 8 // EDM Pins to monitor feedback on external power control relay. Fault on mismatch. - //#define PS_ON1_EDM_PIN 9 - #define PS_EDM_RESPONSE 250 // Time in MS to allow for relay action + //#define PS_ON_EDM_PIN 8 // EDM Pins to monitor feedback on external power control relay. Fault on mismatch. + //#define PS_ON1_EDM_PIN 9 + #define PS_EDM_RESPONSE 250 // (ms) Time to allow for relay action //#define POWER_OFF_TIMER // Enable M81 D to power off after a delay //#define POWER_OFF_WAIT_FOR_COOLDOWN // Enable M81 S to power off only after cooldown diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 9d7bada97ff1..9c943eb3fcc8 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -671,23 +671,10 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) { TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check()); - #if ANY(PSU_CONTROL, AUTO_POWER_CONTROL) - #if defined(PS_ON_EDM_PIN) - if(ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)) - { - if(READ(PS_ON_PIN)!=READ(PS_ON_EDM_PIN)) - kill(GET_TEXT_F(PS_ON_EDM_FAIL)); - } - #endif - - #if defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT) - if(ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)) - { - if(extDigitalRead(PS_ON1_PIN)!=extDigitalRead(PS_ON1_EDM_PIN)) - kill(GET_TEXT_F(PS_ON1_EDM_FAIL)); - } - - #endif + #if ANY(PSU_CONTROL, AUTO_POWER_CONTROL) && PIN_EXISTS(PS_ON_EDM) + if ( ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE) + && (READ(PS_ON_PIN) != READ(PS_ON_EDM_PIN) || TERN0(PSU_OFF_REDUNDANT, extDigitalRead(PS_ON1_PIN) != extDigitalRead(PS_ON1_EDM_PIN))) + ) kill(GET_TEXT_F(MSG_POWER_EDM_FAULT)); #endif #if ENABLED(EXTRUDER_RUNOUT_PREVENT) diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp index 6fa91b3826c9..c339d51aec72 100644 --- a/Marlin/src/feature/power.cpp +++ b/Marlin/src/feature/power.cpp @@ -60,7 +60,7 @@ bool Power::psu_on; millis_t Power::lastPowerOn; #endif -#if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) +#if PIN_EXISTS(PS_ON_EDM) millis_t Power::last_state_change_ms = 0; #endif @@ -92,13 +92,9 @@ void Power::power_on() { OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE); #if ENABLED(PSU_OFF_REDUNDANT) - #if (ENABLED(PSU_OFF_REDUNDANT_OPPOSING)) - OUT_WRITE(PS_ON1_PIN, !PSU_ACTIVE_STATE); - #else - OUT_WRITE(PS_ON1_PIN, PSU_ACTIVE_STATE); - #endif + OUT_WRITE(PS_ON1_PIN, TERN_(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE); #endif - #if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) + #if PIN_EXISTS(PS_ON_EDM) last_state_change_ms = millis(); #endif psu_on = true; @@ -132,13 +128,9 @@ void Power::power_off() { OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); #if ENABLED(PSU_OFF_REDUNDANT) - #if (ENABLED(PSU_OFF_REDUNDANT_OPPOSING)) - OUT_WRITE(PS_ON1_PIN, PSU_ACTIVE_STATE); - #else - OUT_WRITE(PS_ON1_PIN, !PSU_ACTIVE_STATE); - #endif + OUT_WRITE(PS_ON1_PIN, IF_DISABLED(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE); #endif - #if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) + #if PIN_EXISTS(PS_ON_EDM) last_state_change_ms = millis(); #endif diff --git a/Marlin/src/feature/power.h b/Marlin/src/feature/power.h index 480c6e8a5b35..37812315d5c4 100644 --- a/Marlin/src/feature/power.h +++ b/Marlin/src/feature/power.h @@ -25,7 +25,7 @@ * power.h - power control */ -#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER) || defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) +#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER) || PIN_EXISTS(PS_ON_EDM) #include "../core/millis_t.h" #endif @@ -37,7 +37,7 @@ class Power { static void power_on(); static void power_off(); - #if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)) + #if PIN_EXISTS(PS_ON_EDM) static millis_t last_state_change_ms; #endif diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index 6ccb76de4394..82fd637aa124 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -155,8 +155,7 @@ namespace LanguageNarrow_en { LSTR MSG_SPINDLE_REVERSE = _UxGT("Spindle Reverse"); LSTR MSG_SWITCH_PS_ON = _UxGT("Switch Power On"); LSTR MSG_SWITCH_PS_OFF = _UxGT("Switch Power Off"); - LSTR PS_ON_EDM_FAIL = _UxGT("PS_ON EDM Fault"); - LSTR PS_ON1_EDM_FAIL = _UxGT("PS_ON1 EDM Fault"); + LSTR MSG_POWER_EDM_FAULT = _UxGT("Power EDM Fault"); LSTR MSG_EXTRUDE = _UxGT("Extrude"); LSTR MSG_RETRACT = _UxGT("Retract"); LSTR MSG_MOVE_AXIS = _UxGT("Move Axis"); diff --git a/Marlin/src/pins/pins_postprocess.h b/Marlin/src/pins/pins_postprocess.h index e8c77a08cd82..c384af476ef1 100644 --- a/Marlin/src/pins/pins_postprocess.h +++ b/Marlin/src/pins/pins_postprocess.h @@ -477,7 +477,7 @@ #undef PS_ON_PIN #define PS_ON_PIN -1 #endif -#if DISABLED(PSU_OFF_REDUNDANT) || DISABLED(PSU_CONTROL) || !defined(PS_ON1_PIN) +#if DISABLED(PSU_OFF_REDUNDANT) || !defined(PS_ON1_PIN) #undef PS_ON1_PIN #define PS_ON1_PIN -1 #endif From 13542c3017ab39f8ee6a6dcc6741c6f09f077611 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 31 Jan 2024 20:02:58 -0600 Subject: [PATCH 5/6] spell out --- Marlin/Configuration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index a14812192d2b..bd3c024dbfd4 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -406,11 +406,11 @@ //#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay //#define PSU_OFF_REDUNDANT // Second pin for redundant power control - //#define PSU_OFF_REDUNDANT_INVERTED // Redundant pin works opposite standard pin + //#define PSU_OFF_REDUNDANT_INVERTED // Redundant pin state is the inverse of PSU_ACTIVE_STATE //#define PS_ON1_PIN 6 // Redundant pin required to enable power in combination with PS_ON_PIN - //#define PS_ON_EDM_PIN 8 // EDM Pins to monitor feedback on external power control relay. Fault on mismatch. + //#define PS_ON_EDM_PIN 8 // External Device Monitoring pins for external power control relay feedback. Fault on mismatch. //#define PS_ON1_EDM_PIN 9 #define PS_EDM_RESPONSE 250 // (ms) Time to allow for relay action From a35feea06ba691af5cc868c7bf2f48f622af54e6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 28 Feb 2024 18:50:24 -0600 Subject: [PATCH 6/6] shorthand flag --- Marlin/src/feature/power.cpp | 12 +++++------- Marlin/src/feature/power.h | 7 +++++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp index c339d51aec72..fe018a724eab 100644 --- a/Marlin/src/feature/power.cpp +++ b/Marlin/src/feature/power.cpp @@ -60,7 +60,7 @@ bool Power::psu_on; millis_t Power::lastPowerOn; #endif -#if PIN_EXISTS(PS_ON_EDM) +#if PSU_TRACK_STATE_MS millis_t Power::last_state_change_ms = 0; #endif @@ -94,11 +94,11 @@ void Power::power_on() { #if ENABLED(PSU_OFF_REDUNDANT) OUT_WRITE(PS_ON1_PIN, TERN_(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE); #endif - #if PIN_EXISTS(PS_ON_EDM) - last_state_change_ms = millis(); - #endif + TERN_(PSU_TRACK_STATE_MS, last_state_change_ms = millis()); + psu_on = true; safe_delay(PSU_POWERUP_DELAY); + restore_stepper_drivers(); TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY)); @@ -130,9 +130,7 @@ void Power::power_off() { #if ENABLED(PSU_OFF_REDUNDANT) OUT_WRITE(PS_ON1_PIN, IF_DISABLED(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE); #endif - #if PIN_EXISTS(PS_ON_EDM) - last_state_change_ms = millis(); - #endif + TERN_(PSU_TRACK_STATE_MS, last_state_change_ms = millis()); psu_on = false; diff --git a/Marlin/src/feature/power.h b/Marlin/src/feature/power.h index 37812315d5c4..16f9dbcef54f 100644 --- a/Marlin/src/feature/power.h +++ b/Marlin/src/feature/power.h @@ -24,8 +24,11 @@ /** * power.h - power control */ +#if PIN_EXISTS(PS_ON_EDM) || (PIN_EXISTS(PS_ON1_EDM) && ENABLED(PSU_OFF_REDUNDANT)) + #define PSU_TRACK_STATE_MS 1 +#endif -#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER) || PIN_EXISTS(PS_ON_EDM) +#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER, PSU_TRACK_STATE_MS) #include "../core/millis_t.h" #endif @@ -37,7 +40,7 @@ class Power { static void power_on(); static void power_off(); - #if PIN_EXISTS(PS_ON_EDM) + #if PSU_TRACK_STATE_MS static millis_t last_state_change_ms; #endif