Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add POWER_OFF_DELAY option #19987

Merged
merged 8 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,10 @@
#define AUTO_POWER_E_FANS
#define AUTO_POWER_CONTROLLERFAN
#define AUTO_POWER_CHAMBER_FAN
//#define AUTO_POWER_E_TEMP 50 // (°C) Turn on PSU over this temperature
//#define AUTO_POWER_CHAMBER_TEMP 30 // (°C) Turn on PSU over this temperature
#define POWER_TIMEOUT 30
//#define AUTO_POWER_E_TEMP 50 // (°C) Turn on PSU if any extruder is over this temperature
//#define AUTO_POWER_CHAMBER_TEMP 30 // (°C) Turn on PSU if the chamber is over this temperature
#define POWER_TIMEOUT 30 // (s) Turn off power if the machine is idle for this duration
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
//#define POWER_OFF_TIMEOUT 60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time.
#endif
#endif

Expand Down
10 changes: 6 additions & 4 deletions Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ extern bool wait_for_heatup;
#define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE); powersupply_on = true; }while(0)
#define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); powersupply_on = false; }while(0)
#if ENABLED(AUTO_POWER_CONTROL)
#define PSU_ON() powerManager.power_on()
#define PSU_OFF() powerManager.power_off()
#define PSU_ON() powerManager.power_on()
#define PSU_OFF() powerManager.power_off()
#define PSU_OFF_SOON() powerManager.power_off_soon()
#else
#define PSU_ON() PSU_PIN_ON()
#define PSU_OFF() PSU_PIN_OFF()
#define PSU_ON() PSU_PIN_ON()
#define PSU_OFF() PSU_PIN_OFF()
#define PSU_OFF_SOON PSU_OFF
#endif
#endif

Expand Down
8 changes: 8 additions & 0 deletions Marlin/src/feature/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,12 @@ void Power::power_off() {
}
}

void Power::power_off_soon() {
#if POWER_OFF_TIMEOUT
lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_TIMEOUT);
#else
power_off();
#endif
}

#endif // AUTO_POWER_CONTROL
1 change: 1 addition & 0 deletions Marlin/src/feature/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Power {
static void check();
static void power_on();
static void power_off();
static void power_off_soon();
private:
static millis_t lastPowerOn;
static bool is_power_needed();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/control/M80_M81.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void GcodeSuite::M81() {
#if HAS_SUICIDE
suicide();
#elif ENABLED(PSU_CONTROL)
PSU_OFF();
PSU_OFF_SOON();
#endif

LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF "."));
Expand Down
9 changes: 7 additions & 2 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,13 @@
#endif
#endif

#if !defined(PSU_POWERUP_DELAY) && ENABLED(PSU_CONTROL)
#define PSU_POWERUP_DELAY 250
#if ENABLED(PSU_CONTROL)
#ifndef PSU_POWERUP_DELAY
#define PSU_POWERUP_DELAY 250
#endif
#ifndef POWER_OFF_TIMEOUT
#define POWER_OFF_TIMEOUT 0
#endif
#endif

/**
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2999,9 +2999,9 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#error "PSU_CONTROL requires PSU_ACTIVE_STATE to be defined as 'HIGH' or 'LOW'."
#elif !PIN_EXISTS(PS_ON)
#error "PSU_CONTROL requires PS_ON_PIN."
#elif POWER_OFF_TIMEOUT < 0
#error "POWER_OFF_TIMEOUT must be a positive value."
#endif
#elif ENABLED(AUTO_POWER_CONTROL)
#error "AUTO_POWER_CONTROL requires PSU_CONTROL."
#endif

#if HAS_CUTTER
Expand Down