2018-02-06 06:22:30 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 21:06:53 +00:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-02-06 06:22:30 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* 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 21:41:18 +00:00
|
|
|
#include "../module/temperature.h"
|
|
|
|
#include "../module/stepper_indirection.h"
|
|
|
|
#include "../Marlin.h"
|
2018-02-06 06:22:30 +00:00
|
|
|
|
|
|
|
Power powerManager;
|
|
|
|
|
|
|
|
millis_t Power::lastPowerOn;
|
|
|
|
|
|
|
|
bool Power::is_power_needed() {
|
|
|
|
#if ENABLED(AUTO_POWER_FANS)
|
2019-01-12 06:41:48 +00:00
|
|
|
FANS_LOOP(i) if (thermalManager.fan_speed[i]) return true;
|
2018-02-06 06:22:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(AUTO_POWER_E_FANS)
|
2018-10-07 20:34:41 +00:00
|
|
|
HOTEND_LOOP() if (thermalManager.autofan_speed[e]) return true;
|
2018-02-06 06:22:30 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-16 08:18:50 +00:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROLLERFAN) && HAS_CONTROLLER_FAN && ENABLED(USE_CONTROLLER_FAN)
|
2018-10-07 20:34:41 +00:00
|
|
|
if (controllerfan_speed) return true;
|
2018-02-06 06:22:30 +00:00
|
|
|
#endif
|
|
|
|
|
2018-08-27 07:25:47 +00:00
|
|
|
// If any of the drivers or the bed are enabled...
|
2018-05-04 05:15:31 +00:00
|
|
|
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
|| thermalManager.soft_pwm_amount_bed > 0
|
|
|
|
#endif
|
2018-08-27 07:25:47 +00: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
|
2019-03-01 07:51:24 +00:00
|
|
|
#if E_STEPPERS
|
|
|
|
|| E0_ENABLE_READ == E_ENABLE_ON
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
|| E1_ENABLE_READ == E_ENABLE_ON
|
|
|
|
#if E_STEPPERS > 2
|
|
|
|
|| E2_ENABLE_READ == E_ENABLE_ON
|
|
|
|
#if E_STEPPERS > 3
|
|
|
|
|| E3_ENABLE_READ == E_ENABLE_ON
|
|
|
|
#if E_STEPPERS > 4
|
|
|
|
|| E4_ENABLE_READ == E_ENABLE_ON
|
|
|
|
#if E_STEPPERS > 5
|
|
|
|
|| E5_ENABLE_READ == E_ENABLE_ON
|
|
|
|
#endif // E_STEPPERS > 5
|
|
|
|
#endif // E_STEPPERS > 4
|
|
|
|
#endif // E_STEPPERS > 3
|
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
|
|
|
#endif // E_STEPPERS
|
2018-02-06 06:22:30 +00:00
|
|
|
) return true;
|
|
|
|
|
|
|
|
HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0) return true;
|
2018-08-07 04:20:51 +00:00
|
|
|
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
if (thermalManager.degTargetBed() > 0) return true;
|
|
|
|
#endif
|
2018-02-06 06:22:30 +00: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();
|
|
|
|
else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + (POWER_TIMEOUT) * 1000UL))
|
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Power::power_on() {
|
|
|
|
lastPowerOn = millis();
|
2018-04-17 09:34:31 +00:00
|
|
|
if (!powersupply_on) {
|
|
|
|
PSU_PIN_ON();
|
2018-03-19 00:01:42 +00:00
|
|
|
|
2018-04-17 09:34:31 +00:00
|
|
|
#if HAS_TRINAMIC
|
|
|
|
delay(100); // Wait for power to settle
|
|
|
|
restore_stepper_drivers();
|
|
|
|
#endif
|
|
|
|
}
|
2018-02-06 06:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Power::power_off() {
|
2018-04-17 09:34:31 +00:00
|
|
|
if (powersupply_on) PSU_PIN_OFF();
|
2018-02-06 06:22:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // AUTO_POWER_CONTROL
|