Skip to content

Commit 9df6a60

Browse files
thinkyheadsenseisimple
authored andcommitted
Add power-on/off G-code options (MarlinFirmware#19837)
Co-authored-by: Chris <chris@chrisnovoa.com>
1 parent 7693e93 commit 9df6a60

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Marlin/Configuration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@
335335
//#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80
336336
//#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power
337337

338+
//#define PSU_POWERUP_GCODE "M355 S1" // G-code to run after power-on (e.g., case light on)
339+
//#define PSU_POWEROFF_GCODE "M355 S0" // G-code to run before power-off (e.g., case light off)
340+
338341
//#define AUTO_POWER_CONTROL // Enable automatic control of the PS_ON pin
339342
#if ENABLED(AUTO_POWER_CONTROL)
340343
#define AUTO_POWER_FANS // Turn on PSU if fans need power

Marlin/src/feature/power.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include "../module/stepper/indirection.h"
3434
#include "../MarlinCore.h"
3535

36+
#if defined(PSU_POWERUP_GCODE) || defined(PSU_POWEROFF_GCODE)
37+
#include "../gcode/gcode.h"
38+
#endif
39+
3640
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
3741
#include "controllerfan.h"
3842
#endif
@@ -107,11 +111,19 @@ void Power::power_on() {
107111
safe_delay(PSU_POWERUP_DELAY);
108112
restore_stepper_drivers();
109113
TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));
114+
#ifdef PSU_POWERUP_GCODE
115+
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWERUP_GCODE));
116+
#endif
110117
}
111118
}
112119

113120
void Power::power_off() {
114-
if (powersupply_on) PSU_PIN_OFF();
121+
if (powersupply_on) {
122+
#ifdef PSU_POWEROFF_GCODE
123+
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWEROFF_GCODE));
124+
#endif
125+
PSU_PIN_OFF();
126+
}
115127
}
116128

117129
#endif // AUTO_POWER_CONTROL

0 commit comments

Comments
 (0)