Skip to content

Commit

Permalink
Add power-on/off G-code options (MarlinFirmware#19837)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris <[email protected]>
  • Loading branch information
thinkyhead and senseisimple committed Apr 26, 2021
1 parent af8ee65 commit 472b798
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@
//#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 PSU_POWERUP_GCODE "M355 S1" // G-code to run after power-on (e.g., case light on)
//#define PSU_POWEROFF_GCODE "M355 S0" // G-code to run before power-off (e.g., case light off)

//#define AUTO_POWER_CONTROL // Enable automatic control of the PS_ON pin
#if ENABLED(AUTO_POWER_CONTROL)
#define AUTO_POWER_FANS // Turn on PSU if fans need power
Expand Down
14 changes: 13 additions & 1 deletion Marlin/src/feature/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include "../module/stepper/indirection.h"
#include "../MarlinCore.h"

#if defined(PSU_POWERUP_GCODE) || defined(PSU_POWEROFF_GCODE)
#include "../gcode/gcode.h"
#endif

#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
#include "controllerfan.h"
#endif
Expand Down Expand Up @@ -107,11 +111,19 @@ void Power::power_on() {
safe_delay(PSU_POWERUP_DELAY);
restore_stepper_drivers();
TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));
#ifdef PSU_POWERUP_GCODE
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWERUP_GCODE));
#endif
}
}

void Power::power_off() {
if (powersupply_on) PSU_PIN_OFF();
if (powersupply_on) {
#ifdef PSU_POWEROFF_GCODE
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWEROFF_GCODE));
#endif
PSU_PIN_OFF();
}
}

#endif // AUTO_POWER_CONTROL

0 comments on commit 472b798

Please sign in to comment.