Browse Source

Add POWER_OFF_DELAY option (#19987)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Hebezo 3 years ago
parent
commit
4ace02f4c2
No account linked to committer's email address

+ 4
- 3
Marlin/Configuration.h View File

@@ -344,9 +344,10 @@
344 344
     #define AUTO_POWER_E_FANS
345 345
     #define AUTO_POWER_CONTROLLERFAN
346 346
     #define AUTO_POWER_CHAMBER_FAN
347
-    //#define AUTO_POWER_E_TEMP        50 // (°C) Turn on PSU over this temperature
348
-    //#define AUTO_POWER_CHAMBER_TEMP  30 // (°C) Turn on PSU over this temperature
349
-    #define POWER_TIMEOUT 30
347
+    //#define AUTO_POWER_E_TEMP        50 // (°C) Turn on PSU if any extruder is over this temperature
348
+    //#define AUTO_POWER_CHAMBER_TEMP  30 // (°C) Turn on PSU if the chamber is over this temperature
349
+    #define POWER_TIMEOUT              30 // (s) Turn off power if the machine is idle for this duration
350
+    //#define POWER_OFF_DELAY          60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time.
350 351
   #endif
351 352
 #endif
352 353
 

+ 6
- 4
Marlin/src/MarlinCore.h View File

@@ -92,11 +92,13 @@ extern bool wait_for_heatup;
92 92
   #define PSU_PIN_ON()  do{ OUT_WRITE(PS_ON_PIN,  PSU_ACTIVE_STATE); powersupply_on = true;  }while(0)
93 93
   #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); powersupply_on = false; }while(0)
94 94
   #if ENABLED(AUTO_POWER_CONTROL)
95
-    #define PSU_ON()  powerManager.power_on()
96
-    #define PSU_OFF() powerManager.power_off()
95
+    #define PSU_ON()       powerManager.power_on()
96
+    #define PSU_OFF()      powerManager.power_off()
97
+    #define PSU_OFF_SOON() powerManager.power_off_soon()
97 98
   #else
98
-    #define PSU_ON()  PSU_PIN_ON()
99
-    #define PSU_OFF() PSU_PIN_OFF()
99
+    #define PSU_ON()     PSU_PIN_ON()
100
+    #define PSU_OFF()    PSU_PIN_OFF()
101
+    #define PSU_OFF_SOON PSU_OFF
100 102
   #endif
101 103
 #endif
102 104
 

+ 8
- 0
Marlin/src/feature/power.cpp View File

@@ -126,4 +126,12 @@ void Power::power_off() {
126 126
   }
127 127
 }
128 128
 
129
+void Power::power_off_soon() {
130
+  #if POWER_OFF_DELAY
131
+    lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY);
132
+  #else
133
+    power_off();
134
+  #endif
135
+}
136
+
129 137
 #endif // AUTO_POWER_CONTROL

+ 1
- 0
Marlin/src/feature/power.h View File

@@ -32,6 +32,7 @@ class Power {
32 32
     static void check();
33 33
     static void power_on();
34 34
     static void power_off();
35
+    static void power_off_soon();
35 36
   private:
36 37
     static millis_t lastPowerOn;
37 38
     static bool is_power_needed();

+ 1
- 1
Marlin/src/gcode/control/M80_M81.cpp View File

@@ -105,7 +105,7 @@ void GcodeSuite::M81() {
105 105
   #if HAS_SUICIDE
106 106
     suicide();
107 107
   #elif ENABLED(PSU_CONTROL)
108
-    PSU_OFF();
108
+    PSU_OFF_SOON();
109 109
   #endif
110 110
 
111 111
   LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF "."));

+ 7
- 2
Marlin/src/inc/Conditionals_post.h View File

@@ -416,8 +416,13 @@
416 416
   #endif
417 417
 #endif
418 418
 
419
-#if !defined(PSU_POWERUP_DELAY) && ENABLED(PSU_CONTROL)
420
-  #define PSU_POWERUP_DELAY 250
419
+#if ENABLED(PSU_CONTROL)
420
+  #ifndef PSU_POWERUP_DELAY
421
+    #define PSU_POWERUP_DELAY 250
422
+  #endif
423
+  #ifndef POWER_OFF_DELAY
424
+    #define POWER_OFF_DELAY   0
425
+  #endif
421 426
 #endif
422 427
 
423 428
 /**

+ 2
- 2
Marlin/src/inc/SanityCheck.h View File

@@ -3016,9 +3016,9 @@ static_assert(   _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
3016 3016
     #error "PSU_CONTROL requires PSU_ACTIVE_STATE to be defined as 'HIGH' or 'LOW'."
3017 3017
   #elif !PIN_EXISTS(PS_ON)
3018 3018
     #error "PSU_CONTROL requires PS_ON_PIN."
3019
+  #elif POWER_OFF_DELAY < 0
3020
+    #error "POWER_OFF_DELAY must be a positive value."
3019 3021
   #endif
3020
-#elif ENABLED(AUTO_POWER_CONTROL)
3021
-  #error "AUTO_POWER_CONTROL requires PSU_CONTROL."
3022 3022
 #endif
3023 3023
 
3024 3024
 #if HAS_CUTTER

Loading…
Cancel
Save