|
|
@ -26,10 +26,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "power.h"
|
|
|
|
#include "power.h"
|
|
|
|
#include "../module/temperature.h"
|
|
|
|
|
|
|
|
#include "../module/stepper/indirection.h"
|
|
|
|
#include "../module/stepper/indirection.h"
|
|
|
|
#include "../MarlinCore.h"
|
|
|
|
#include "../MarlinCore.h"
|
|
|
|
|
|
|
|
|
|
|
@ -41,133 +38,183 @@
|
|
|
|
#include "../gcode/gcode.h"
|
|
|
|
#include "../gcode/gcode.h"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
|
|
|
|
#if EITHER(PSU_CONTROL, AUTO_POWER_CONTROL)
|
|
|
|
#include "controllerfan.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Power powerManager;
|
|
|
|
Power powerManager;
|
|
|
|
|
|
|
|
bool Power::psu_on;
|
|
|
|
|
|
|
|
|
|
|
|
millis_t Power::lastPowerOn;
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
|
|
|
|
#include "../module/temperature.h"
|
|
|
|
bool Power::is_power_needed() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (printJobOngoing() || printingIsPaused()) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_FANS)
|
|
|
|
|
|
|
|
FANS_LOOP(i) if (thermalManager.fan_speed[i]) return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_E_FANS)
|
|
|
|
|
|
|
|
HOTEND_LOOP() if (thermalManager.autofan_speed[e]) return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
|
|
|
|
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
|
|
|
|
if (controllerFan.state()) return true;
|
|
|
|
#include "controllerfan.h"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (TERN0(AUTO_POWER_CHAMBER_FAN, thermalManager.chamberfan_speed))
|
|
|
|
millis_t Power::lastPowerOn;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TERN0(AUTO_POWER_COOLER_FAN, thermalManager.coolerfan_speed))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If any of the drivers or the bed are enabled...
|
|
|
|
|
|
|
|
if (X_ENABLE_READ() == X_ENABLE_ON || Y_ENABLE_READ() == Y_ENABLE_ON || Z_ENABLE_READ() == Z_ENABLE_ON
|
|
|
|
|
|
|
|
#if HAS_X2_ENABLE
|
|
|
|
|
|
|
|
|| X2_ENABLE_READ() == X_ENABLE_ON
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Y2_ENABLE
|
|
|
|
|
|
|
|
|| Y2_ENABLE_READ() == Y_ENABLE_ON
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z2_ENABLE
|
|
|
|
|
|
|
|
|| Z2_ENABLE_READ() == Z_ENABLE_ON
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if E_STEPPERS
|
|
|
|
|
|
|
|
#define _OR_ENABLED_E(N) || E##N##_ENABLE_READ() == E_ENABLE_ON
|
|
|
|
|
|
|
|
REPEAT(E_STEPPERS, _OR_ENABLED_E)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if HAS_HOTEND
|
|
|
|
|
|
|
|
HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0 || thermalManager.temp_hotend[e].soft_pwm_amount > 0) return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TERN0(HAS_HEATED_BED, thermalManager.degTargetBed() > 0 || thermalManager.temp_bed.soft_pwm_amount > 0)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef POWER_TIMEOUT
|
|
|
|
|
|
|
|
#define POWER_TIMEOUT 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void Power::check(const bool pause) {
|
|
|
|
/**
|
|
|
|
static bool _pause = false;
|
|
|
|
* Initialize pins & state for the power manager.
|
|
|
|
static millis_t nextPowerCheck = 0;
|
|
|
|
*
|
|
|
|
const millis_t now = millis();
|
|
|
|
*/
|
|
|
|
#if POWER_TIMEOUT > 0
|
|
|
|
void Power::init(){
|
|
|
|
if (pause != _pause) {
|
|
|
|
psu_on = ENABLED(PSU_DEFAULT_OFF); // Set opposite state to get full power_off/on
|
|
|
|
lastPowerOn = now + !now;
|
|
|
|
TERN(PSU_DEFAULT_OFF, power_off(), power_on());
|
|
|
|
_pause = pause;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pause) return;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ELAPSED(now, nextPowerCheck)) {
|
|
|
|
|
|
|
|
nextPowerCheck = now + 2500UL;
|
|
|
|
|
|
|
|
if (is_power_needed())
|
|
|
|
|
|
|
|
power_on();
|
|
|
|
|
|
|
|
else if (!lastPowerOn || (POWER_TIMEOUT > 0 && ELAPSED(now, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT))))
|
|
|
|
|
|
|
|
power_off();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Power on if the power is currently off.
|
|
|
|
|
|
|
|
* Restores stepper drivers and processes any PSU_POWERUP_GCODE.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
void Power::power_on() {
|
|
|
|
void Power::power_on() {
|
|
|
|
const millis_t now = millis();
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
lastPowerOn = now + !now;
|
|
|
|
const millis_t now = millis();
|
|
|
|
if (!powersupply_on) {
|
|
|
|
lastPowerOn = now + !now;
|
|
|
|
PSU_PIN_ON();
|
|
|
|
#endif
|
|
|
|
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 (psu_on) return;
|
|
|
|
if (powersupply_on) {
|
|
|
|
|
|
|
|
#ifdef PSU_POWEROFF_GCODE
|
|
|
|
|
|
|
|
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWEROFF_GCODE));
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(PS_OFF_SOUND)
|
|
|
|
OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE);
|
|
|
|
BUZZ(1000, 659);
|
|
|
|
psu_on = true;
|
|
|
|
#endif
|
|
|
|
safe_delay(PSU_POWERUP_DELAY);
|
|
|
|
|
|
|
|
restore_stepper_drivers();
|
|
|
|
|
|
|
|
TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));
|
|
|
|
|
|
|
|
|
|
|
|
PSU_PIN_OFF();
|
|
|
|
#ifdef PSU_POWERUP_GCODE
|
|
|
|
}
|
|
|
|
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWERUP_GCODE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Power::power_off_soon() {
|
|
|
|
|
|
|
|
#if POWER_OFF_DELAY
|
|
|
|
|
|
|
|
lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY);
|
|
|
|
|
|
|
|
//if (!lastPowerOn) ++lastPowerOn;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
power_off();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Power off if the power is currently on.
|
|
|
|
|
|
|
|
* Processes any PSU_POWEROFF_GCODE and makes a PS_OFF_SOUND if enabled.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Power::power_off() {
|
|
|
|
|
|
|
|
if (!psu_on) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef PSU_POWEROFF_GCODE
|
|
|
|
|
|
|
|
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWEROFF_GCODE));
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(PS_OFF_SOUND)
|
|
|
|
|
|
|
|
BUZZ(1000, 659);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE);
|
|
|
|
|
|
|
|
psu_on = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef POWER_TIMEOUT
|
|
|
|
|
|
|
|
#define POWER_TIMEOUT 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Check all conditions that would signal power needing to be on.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @returns bool if power is needed
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Power::is_power_needed() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (printJobOngoing() || printingIsPaused()) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_FANS)
|
|
|
|
|
|
|
|
FANS_LOOP(i) if (thermalManager.fan_speed[i]) return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_E_FANS)
|
|
|
|
|
|
|
|
HOTEND_LOOP() if (thermalManager.autofan_speed[e]) return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
|
|
|
|
|
|
|
|
if (controllerFan.state()) return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TERN0(AUTO_POWER_CHAMBER_FAN, thermalManager.chamberfan_speed))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TERN0(AUTO_POWER_COOLER_FAN, thermalManager.coolerfan_speed))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If any of the drivers or the bed are enabled...
|
|
|
|
|
|
|
|
if (X_ENABLE_READ() == X_ENABLE_ON || Y_ENABLE_READ() == Y_ENABLE_ON || Z_ENABLE_READ() == Z_ENABLE_ON
|
|
|
|
|
|
|
|
#if HAS_X2_ENABLE
|
|
|
|
|
|
|
|
|| X2_ENABLE_READ() == X_ENABLE_ON
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Y2_ENABLE
|
|
|
|
|
|
|
|
|| Y2_ENABLE_READ() == Y_ENABLE_ON
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z2_ENABLE
|
|
|
|
|
|
|
|
|| Z2_ENABLE_READ() == Z_ENABLE_ON
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if E_STEPPERS
|
|
|
|
|
|
|
|
#define _OR_ENABLED_E(N) || E##N##_ENABLE_READ() == E_ENABLE_ON
|
|
|
|
|
|
|
|
REPEAT(E_STEPPERS, _OR_ENABLED_E)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if HAS_HOTEND
|
|
|
|
|
|
|
|
HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0 || thermalManager.temp_hotend[e].soft_pwm_amount > 0) return true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TERN0(HAS_HEATED_BED, thermalManager.degTargetBed() > 0 || thermalManager.temp_bed.soft_pwm_amount > 0)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Check if we should power off automatically (POWER_TIMEOUT elapsed, !is_power_needed).
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param pause pause the 'timer'
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Power::check(const bool pause) {
|
|
|
|
|
|
|
|
static millis_t nextPowerCheck = 0;
|
|
|
|
|
|
|
|
const millis_t now = millis();
|
|
|
|
|
|
|
|
#if POWER_TIMEOUT > 0
|
|
|
|
|
|
|
|
static bool _pause = false;
|
|
|
|
|
|
|
|
if (pause != _pause) {
|
|
|
|
|
|
|
|
lastPowerOn = now + !now;
|
|
|
|
|
|
|
|
_pause = pause;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pause) return;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ELAPSED(now, nextPowerCheck)) {
|
|
|
|
|
|
|
|
nextPowerCheck = now + 2500UL;
|
|
|
|
|
|
|
|
if (is_power_needed())
|
|
|
|
|
|
|
|
power_on();
|
|
|
|
|
|
|
|
else if (!lastPowerOn || (POWER_TIMEOUT > 0 && ELAPSED(now, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT))))
|
|
|
|
|
|
|
|
power_off();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if POWER_OFF_DELAY > 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Power off with a delay. Power off is triggered by check() after the delay.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Power::power_off_soon() {
|
|
|
|
|
|
|
|
lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif // AUTO_POWER_CONTROL
|
|
|
|
#endif // AUTO_POWER_CONTROL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PSU_CONTROL || AUTO_POWER_CONTROL
|
|
|
|