2018-02-06 00:22:30 -06:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-02-06 00:22:30 -06:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2018-02-06 00:22:30 -06:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* power.cpp - power control
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
|
|
|
|
#include "power.h"
|
2018-02-10 15:41:18 -06:00
|
|
|
#include "../module/temperature.h"
|
2019-08-31 19:44:45 -05:00
|
|
|
#include "../module/stepper/indirection.h"
|
2020-01-02 19:01:38 -06:00
|
|
|
#include "../MarlinCore.h"
|
2018-02-06 00:22:30 -06:00
|
|
|
|
|
|
|
Power powerManager;
|
|
|
|
|
|
|
|
millis_t Power::lastPowerOn;
|
|
|
|
|
|
|
|
bool Power::is_power_needed() {
|
|
|
|
#if ENABLED(AUTO_POWER_FANS)
|
2019-01-12 00:41:48 -06:00
|
|
|
FANS_LOOP(i) if (thermalManager.fan_speed[i]) return true;
|
2018-02-06 00:22:30 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_E_FANS)
|
2018-10-07 15:34:41 -05:00
|
|
|
HOTEND_LOOP() if (thermalManager.autofan_speed[e]) return true;
|
2018-02-06 00:22:30 -06:00
|
|
|
#endif
|
|
|
|
|
2020-03-18 13:41:12 -05:00
|
|
|
#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
|
|
|
|
if (controllerFan.state()) return true;
|
2018-02-06 00:22:30 -06:00
|
|
|
#endif
|
|
|
|
|
2019-05-04 22:51:47 -05:00
|
|
|
#if ENABLED(AUTO_POWER_CHAMBER_FAN)
|
|
|
|
if (thermalManager.chamberfan_speed) return true;
|
|
|
|
#endif
|
|
|
|
|
2018-08-27 02:25:47 -05:00
|
|
|
// If any of the drivers or the bed are enabled...
|
2019-08-16 21:57:19 -05:00
|
|
|
if (X_ENABLE_READ() == X_ENABLE_ON || Y_ENABLE_READ() == Y_ENABLE_ON || Z_ENABLE_READ() == Z_ENABLE_ON
|
2018-05-04 00:15:31 -05:00
|
|
|
#if HAS_HEATED_BED
|
2019-03-07 02:09:39 -06:00
|
|
|
|| thermalManager.temp_bed.soft_pwm_amount > 0
|
2018-05-04 00:15:31 -05:00
|
|
|
#endif
|
2019-11-09 17:59:04 -06:00
|
|
|
#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
|
2018-02-06 00:22:30 -06:00
|
|
|
) return true;
|
|
|
|
|
|
|
|
HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0) return true;
|
2018-08-06 23:20:51 -05:00
|
|
|
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
if (thermalManager.degTargetBed() > 0) return true;
|
|
|
|
#endif
|
2018-02-06 00:22:30 -06:00
|
|
|
|
2019-06-27 16:28:07 -05:00
|
|
|
#if HOTENDS && 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
|
|
|
|
|
2018-02-06 00:22:30 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Power::check() {
|
|
|
|
static millis_t nextPowerCheck = 0;
|
|
|
|
millis_t ms = millis();
|
|
|
|
if (ELAPSED(ms, nextPowerCheck)) {
|
|
|
|
nextPowerCheck = ms + 2500UL;
|
|
|
|
if (is_power_needed())
|
|
|
|
power_on();
|
2020-04-03 19:49:45 -05:00
|
|
|
else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT)))
|
2018-02-06 00:22:30 -06:00
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Power::power_on() {
|
|
|
|
lastPowerOn = millis();
|
2018-04-17 04:34:31 -05:00
|
|
|
if (!powersupply_on) {
|
|
|
|
PSU_PIN_ON();
|
2018-03-18 19:01:42 -05:00
|
|
|
|
2020-03-02 12:03:43 -06:00
|
|
|
#if HAS_TRINAMIC_CONFIG
|
2019-12-01 17:36:49 -06:00
|
|
|
delay(PSU_POWERUP_DELAY); // Wait for power to settle
|
2018-04-17 04:34:31 -05:00
|
|
|
restore_stepper_drivers();
|
|
|
|
#endif
|
|
|
|
}
|
2018-02-06 00:22:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void Power::power_off() {
|
2018-04-17 04:34:31 -05:00
|
|
|
if (powersupply_on) PSU_PIN_OFF();
|
2018-02-06 00:22:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // AUTO_POWER_CONTROL
|