|
@ -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,15 +38,87 @@ |
|
|
#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) |
|
|
|
|
|
|
|
|
|
|
|
Power powerManager; |
|
|
|
|
|
bool Power::psu_on; |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL) |
|
|
|
|
|
#include "../module/temperature.h" |
|
|
|
|
|
|
|
|
|
|
|
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN) |
|
|
#include "controllerfan.h" |
|
|
#include "controllerfan.h" |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
millis_t Power::lastPowerOn; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
Power powerManager; |
|
|
/**
|
|
|
|
|
|
* Initialize pins & state for the power manager. |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
void Power::init(){ |
|
|
|
|
|
psu_on = ENABLED(PSU_DEFAULT_OFF); // Set opposite state to get full power_off/on
|
|
|
|
|
|
TERN(PSU_DEFAULT_OFF, power_off(), power_on()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Power on if the power is currently off. |
|
|
|
|
|
* Restores stepper drivers and processes any PSU_POWERUP_GCODE. |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
void Power::power_on() { |
|
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL) |
|
|
|
|
|
const millis_t now = millis(); |
|
|
|
|
|
lastPowerOn = now + !now; |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (psu_on) return; |
|
|
|
|
|
|
|
|
|
|
|
OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE); |
|
|
|
|
|
psu_on = true; |
|
|
|
|
|
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 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 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 |
|
|
|
|
|
|
|
|
millis_t Power::lastPowerOn; |
|
|
OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); |
|
|
|
|
|
psu_on = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL) |
|
|
|
|
|
|
|
|
|
|
|
#ifndef POWER_TIMEOUT |
|
|
|
|
|
#define POWER_TIMEOUT 0 |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
bool Power::is_power_needed() { |
|
|
/**
|
|
|
|
|
|
* 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 (printJobOngoing() || printingIsPaused()) return true; |
|
|
|
|
|
|
|
@ -107,17 +176,18 @@ bool Power::is_power_needed() { |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#ifndef POWER_TIMEOUT |
|
|
|
|
|
#define POWER_TIMEOUT 0 |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
void Power::check(const bool pause) { |
|
|
/**
|
|
|
static bool _pause = 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; |
|
|
static millis_t nextPowerCheck = 0; |
|
|
const millis_t now = millis(); |
|
|
const millis_t now = millis(); |
|
|
#if POWER_TIMEOUT > 0 |
|
|
#if POWER_TIMEOUT > 0 |
|
|
|
|
|
static bool _pause = false; |
|
|
if (pause != _pause) { |
|
|
if (pause != _pause) { |
|
|
lastPowerOn = now + !now; |
|
|
lastPowerOn = now + !now; |
|
|
_pause = pause; |
|
|
_pause = pause; |
|
@ -131,43 +201,20 @@ void Power::check(const bool pause) { |
|
|
else if (!lastPowerOn || (POWER_TIMEOUT > 0 && ELAPSED(now, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT)))) |
|
|
else if (!lastPowerOn || (POWER_TIMEOUT > 0 && ELAPSED(now, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT)))) |
|
|
power_off(); |
|
|
power_off(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Power::power_on() { |
|
|
|
|
|
const millis_t now = millis(); |
|
|
|
|
|
lastPowerOn = now + !now; |
|
|
|
|
|
if (!powersupply_on) { |
|
|
|
|
|
PSU_PIN_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 POWER_OFF_DELAY > 0 |
|
|
if (powersupply_on) { |
|
|
|
|
|
#ifdef PSU_POWEROFF_GCODE |
|
|
|
|
|
GcodeSuite::process_subcommands_now_P(PSTR(PSU_POWEROFF_GCODE)); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(PS_OFF_SOUND) |
|
|
/**
|
|
|
BUZZ(1000, 659); |
|
|
* Power off with a delay. Power off is triggered by check() after the delay. |
|
|
#endif |
|
|
* |
|
|
|
|
|
*/ |
|
|
PSU_PIN_OFF(); |
|
|
void Power::power_off_soon() { |
|
|
|
|
|
lastPowerOn = millis() - SEC_TO_MS(POWER_TIMEOUT) + SEC_TO_MS(POWER_OFF_DELAY); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // AUTO_POWER_CONTROL
|
|
|
#endif // AUTO_POWER_CONTROL
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PSU_CONTROL || AUTO_POWER_CONTROL
|
|
|