M81 D / S - Power-off Delay (#23396, #23455)

This commit is contained in:
John Lagonikas 2022-01-03 18:11:39 +02:00 committed by Scott Lahteine
parent b6c37960e8
commit 2690bb1bc2
9 changed files with 134 additions and 42 deletions

View file

@ -374,6 +374,9 @@
//#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80 //#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_DELAY 250 // (ms) Delay for the PSU to warm up to full power
//#define POWER_OFF_TIMER // Enable M81 D<seconds> to power off after a delay
//#define POWER_OFF_WAIT_FOR_COOLDOWN // Enable M81 S to power off only after cooldown
//#define PSU_POWERUP_GCODE "M355 S1" // G-code to run after power-on (e.g., case light on) //#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 PSU_POWEROFF_GCODE "M355 S0" // G-code to run before power-off (e.g., case light off)
@ -384,12 +387,14 @@
#define AUTO_POWER_CONTROLLERFAN #define AUTO_POWER_CONTROLLERFAN
#define AUTO_POWER_CHAMBER_FAN #define AUTO_POWER_CHAMBER_FAN
#define AUTO_POWER_COOLER_FAN #define AUTO_POWER_COOLER_FAN
//#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 AUTO_POWER_COOLER_TEMP 26 // (°C) Turn on PSU if the cooler is over this temperature
#define POWER_TIMEOUT 30 // (s) Turn off power if the machine is idle for this duration #define POWER_TIMEOUT 30 // (s) Turn off power if the machine is idle for this duration
//#define POWER_OFF_DELAY 60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time. //#define POWER_OFF_DELAY 60 // (s) Delay of poweroff after M81 command. Useful to let fans run for extra time.
#endif #endif
#if EITHER(AUTO_POWER_CONTROL, POWER_OFF_WAIT_FOR_COOLDOWN)
//#define AUTO_POWER_E_TEMP 50 // (°C) PSU on if any extruder is over this temperature
//#define AUTO_POWER_CHAMBER_TEMP 30 // (°C) PSU on if the chamber is over this temperature
//#define AUTO_POWER_COOLER_TEMP 26 // (°C) PSU on if the cooler is over this temperature
#endif
#endif #endif
//=========================================================================== //===========================================================================

View file

@ -1648,6 +1648,10 @@ void loop() {
queue.advance(); queue.advance();
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
powerManager.checkAutoPowerOff();
#endif
endstops.event_handler(); endstops.event_handler();
TERN_(HAS_TFT_LVGL_UI, printer_state_polling()); TERN_(HAS_TFT_LVGL_UI, printer_state_polling());

View file

@ -27,7 +27,9 @@
#include "../inc/MarlinConfig.h" #include "../inc/MarlinConfig.h"
#include "power.h" #include "power.h"
#include "../module/planner.h"
#include "../module/stepper.h" #include "../module/stepper.h"
#include "../module/temperature.h"
#include "../MarlinCore.h" #include "../MarlinCore.h"
#if ENABLED(PS_OFF_SOUND) #if ENABLED(PS_OFF_SOUND)
@ -75,6 +77,10 @@ void Power::power_on() {
if (psu_on) return; if (psu_on) return;
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
cancelAutoPowerOff();
#endif
OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE); OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE);
psu_on = true; psu_on = true;
safe_delay(PSU_POWERUP_DELAY); safe_delay(PSU_POWERUP_DELAY);
@ -89,7 +95,6 @@ void Power::power_on() {
/** /**
* Power off if the power is currently on. * Power off if the power is currently on.
* Processes any PSU_POWEROFF_GCODE and makes a PS_OFF_SOUND if enabled. * Processes any PSU_POWEROFF_GCODE and makes a PS_OFF_SOUND if enabled.
*
*/ */
void Power::power_off() { void Power::power_off() {
if (!psu_on) return; if (!psu_on) return;
@ -104,8 +109,57 @@ void Power::power_off() {
OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE);
psu_on = false; psu_on = false;
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
cancelAutoPowerOff();
#endif
} }
#if EITHER(AUTO_POWER_CONTROL, POWER_OFF_WAIT_FOR_COOLDOWN)
bool Power::is_cooling_needed() {
#if HAS_HOTEND && AUTO_POWER_E_TEMP
HOTEND_LOOP() if (thermalManager.degHotend(e) >= (AUTO_POWER_E_TEMP)) return true;
#endif
#if HAS_HEATED_CHAMBER && AUTO_POWER_CHAMBER_TEMP
if (thermalManager.degChamber() >= (AUTO_POWER_CHAMBER_TEMP)) return true;
#endif
#if HAS_COOLER && AUTO_POWER_COOLER_TEMP
if (thermalManager.degCooler() >= (AUTO_POWER_COOLER_TEMP)) return true;
#endif
return false;
}
#endif
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
#if ENABLED(POWER_OFF_TIMER)
millis_t Power::power_off_time = 0;
void Power::setPowerOffTimer(const millis_t delay_ms) { power_off_time = millis() + delay_ms; }
#endif
#if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
bool Power::power_off_on_cooldown = false;
void Power::setPowerOffOnCooldown(const bool ena) { power_off_on_cooldown = ena; }
#endif
void Power::cancelAutoPowerOff() {
TERN_(POWER_OFF_TIMER, power_off_time = 0);
TERN_(POWER_OFF_WAIT_FOR_COOLDOWN, power_off_on_cooldown = false);
}
void Power::checkAutoPowerOff() {
if (TERN1(POWER_OFF_TIMER, !power_off_time) && TERN1(POWER_OFF_WAIT_FOR_COOLDOWN, !power_off_on_cooldown)) return;
if (TERN0(POWER_OFF_WAIT_FOR_COOLDOWN, power_off_on_cooldown && is_cooling_needed())) return;
if (TERN0(POWER_OFF_TIMER, power_off_time && PENDING(millis(), power_off_time))) return;
power_off();
}
#endif // POWER_OFF_TIMER || POWER_OFF_WAIT_FOR_COOLDOWN
#if ENABLED(AUTO_POWER_CONTROL) #if ENABLED(AUTO_POWER_CONTROL)
@ -149,19 +203,7 @@ void Power::power_off() {
if (TERN0(HAS_HEATED_BED, thermalManager.degTargetBed() > 0 || thermalManager.temp_bed.soft_pwm_amount > 0)) return true; if (TERN0(HAS_HEATED_BED, thermalManager.degTargetBed() > 0 || thermalManager.temp_bed.soft_pwm_amount > 0)) return true;
#if HAS_HOTEND && AUTO_POWER_E_TEMP return is_cooling_needed();
HOTEND_LOOP() if (thermalManager.degHotend(e) >= (AUTO_POWER_E_TEMP)) return true;
#endif
#if HAS_HEATED_CHAMBER && AUTO_POWER_CHAMBER_TEMP
if (thermalManager.degChamber() >= (AUTO_POWER_CHAMBER_TEMP)) return true;
#endif
#if HAS_COOLER && AUTO_POWER_COOLER_TEMP
if (thermalManager.degCooler() >= (AUTO_POWER_COOLER_TEMP)) return true;
#endif
return false;
} }
/** /**
@ -193,7 +235,6 @@ void Power::power_off() {
/** /**
* Power off with a delay. Power off is triggered by check() after the delay. * Power off with a delay. Power off is triggered by check() after the delay.
*
*/ */
void Power::power_off_soon() { void Power::power_off_soon() {
lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY); lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY);

View file

@ -36,21 +36,37 @@ class Power {
static void init(); static void init();
static void power_on(); static void power_on();
static void power_off(); static void power_off();
#if EITHER(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
#if ENABLED(POWER_OFF_TIMER)
static millis_t power_off_time;
static void setPowerOffTimer(const millis_t delay_ms);
#endif
#if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
static bool power_off_on_cooldown;
static void setPowerOffOnCooldown(const bool ena);
#endif
static void cancelAutoPowerOff();
static void checkAutoPowerOff();
#endif
#if ENABLED(AUTO_POWER_CONTROL) && POWER_OFF_DELAY > 0 #if ENABLED(AUTO_POWER_CONTROL) && POWER_OFF_DELAY > 0
static void power_off_soon(); static void power_off_soon();
#else #else
static void power_off_soon() { power_off(); } static void power_off_soon() { power_off(); }
#endif #endif
#if ENABLED(AUTO_POWER_CONTROL) #if ENABLED(AUTO_POWER_CONTROL)
static void check(const bool pause); static void check(const bool pause);
private: private:
static millis_t lastPowerOn; static millis_t lastPowerOn;
static bool is_power_needed(); static bool is_power_needed();
static bool is_cooling_needed();
#endif #elif ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
private:
static bool is_cooling_needed();
#endif
}; };
extern Power powerManager; extern Power powerManager;

View file

@ -79,20 +79,39 @@ void GcodeSuite::M81() {
print_job_timer.stop(); print_job_timer.stop();
#if HAS_FAN #if BOTH(HAS_FAN, PROBING_FANS_OFF)
#if ENABLED(PROBING_FANS_OFF) thermalManager.fans_paused = false;
thermalManager.fans_paused = false; ZERO(thermalManager.saved_fan_speed);
ZERO(thermalManager.saved_fan_speed);
#endif
#endif #endif
safe_delay(1000); // Wait 1 second before switching off safe_delay(1000); // Wait 1 second before switching off
LCD_MESSAGE_F(MACHINE_NAME " " STR_OFF ".");
bool delayed_power_off = false;
#if ENABLED(POWER_OFF_TIMER)
if (parser.seenval('D')) {
uint16_t delay = parser.value_ushort();
if (delay > 1) { // skip already observed 1s delay
delayed_power_off = true;
powerManager.setPowerOffTimer(SEC_TO_MS(delay - 1));
}
}
#endif
#if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
if (parser.boolval('S')) {
delayed_power_off = true;
powerManager.setPowerOffOnCooldown(true);
}
#endif
if (delayed_power_off) return;
#if HAS_SUICIDE #if HAS_SUICIDE
suicide(); suicide();
#elif ENABLED(PSU_CONTROL) #elif ENABLED(PSU_CONTROL)
powerManager.power_off_soon(); powerManager.power_off_soon();
#endif #endif
LCD_MESSAGE_F(MACHINE_NAME " " STR_OFF ".");
} }

View file

@ -3564,6 +3564,8 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");
#error "PSU_CONTROL requires PS_ON_PIN." #error "PSU_CONTROL requires PS_ON_PIN."
#elif POWER_OFF_DELAY < 0 #elif POWER_OFF_DELAY < 0
#error "POWER_OFF_DELAY must be a positive value." #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."
#endif #endif
#endif #endif

View file

@ -485,7 +485,7 @@ void Popup_window_PauseOrStop() {
Draw_Select_Highlight(true); Draw_Select_Highlight(true);
DWIN_UpdateLCD(); DWIN_UpdateLCD();
} }
else else
DWIN_Popup_ConfirmCancel(ICON_BLTouch, select_print.now == PRINT_PAUSE_RESUME ? GET_TEXT_F(MSG_PAUSE_PRINT) : GET_TEXT_F(MSG_STOP_PRINT)); DWIN_Popup_ConfirmCancel(ICON_BLTouch, select_print.now == PRINT_PAUSE_RESUME ? GET_TEXT_F(MSG_PAUSE_PRINT) : GET_TEXT_F(MSG_STOP_PRINT));
} }
@ -2019,7 +2019,7 @@ void HMI_LockScreen() {
#endif #endif
//============================================================================= //=============================================================================
// NEW MENU SUBSYSTEM // NEW MENU SUBSYSTEM
//============================================================================= //=============================================================================
// On click functions // On click functions

View file

@ -994,7 +994,12 @@ class Temperature {
static int16_t read_max_tc(TERN_(HAS_MULTI_MAX_TC, const uint8_t hindex=0)); static int16_t read_max_tc(TERN_(HAS_MULTI_MAX_TC, const uint8_t hindex=0));
#endif #endif
static void update_autofans(); #if HAS_AUTO_FAN
#if ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN)
static bool autofans_on;
#endif
static void update_autofans();
#endif
#if HAS_HOTEND #if HAS_HOTEND
static float get_pid_output_hotend(const uint8_t e); static float get_pid_output_hotend(const uint8_t e);

View file

@ -14,7 +14,7 @@ opt_set MOTHERBOARD BOARD_RAMBO \
EXTRUDERS 2 TEMP_SENSOR_0 -2 TEMP_SENSOR_1 1 TEMP_SENSOR_BED 2 \ EXTRUDERS 2 TEMP_SENSOR_0 -2 TEMP_SENSOR_1 1 TEMP_SENSOR_BED 2 \
TEMP_SENSOR_PROBE 1 TEMP_PROBE_PIN 12 \ TEMP_SENSOR_PROBE 1 TEMP_PROBE_PIN 12 \
TEMP_SENSOR_CHAMBER 3 TEMP_CHAMBER_PIN 3 HEATER_CHAMBER_PIN 45 \ TEMP_SENSOR_CHAMBER 3 TEMP_CHAMBER_PIN 3 HEATER_CHAMBER_PIN 45 \
GRID_MAX_POINTS_X 16 \ GRID_MAX_POINTS_X 16 AUTO_POWER_E_TEMP 80 \
FANMUX0_PIN 53 FANMUX0_PIN 53
opt_disable Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN USE_WATCHDOG opt_disable Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN USE_WATCHDOG
opt_enable USE_ZMAX_PLUG REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \ opt_enable USE_ZMAX_PLUG REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \
@ -32,7 +32,7 @@ opt_enable USE_ZMAX_PLUG REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_P
SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE \ SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE \
BACKLASH_COMPENSATION BACKLASH_GCODE BAUD_RATE_GCODE BEZIER_CURVE_SUPPORT \ BACKLASH_COMPENSATION BACKLASH_GCODE BAUD_RATE_GCODE BEZIER_CURVE_SUPPORT \
FWRETRACT ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS \ FWRETRACT ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS \
PSU_CONTROL PS_OFF_CONFIRM PS_OFF_SOUND AUTO_POWER_CONTROL \ PSU_CONTROL PS_OFF_CONFIRM PS_OFF_SOUND POWER_OFF_WAIT_FOR_COOLDOWN \
POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE POWER_LOSS_RECOVER_ZHOME POWER_LOSS_ZHOME_POS \ POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE POWER_LOSS_RECOVER_ZHOME POWER_LOSS_ZHOME_POS \
SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER LIN_ADVANCE EXTRA_LIN_ADVANCE_K \ SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER LIN_ADVANCE EXTRA_LIN_ADVANCE_K \
HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL