[2.0.x] Enable / disable PSU automatically (#9503)
parent
db1ace5e82
commit
b5e92f4f90
@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
#include "temperature.h"
|
||||||
|
#include "stepper_indirection.h"
|
||||||
|
|
||||||
|
Power powerManager;
|
||||||
|
|
||||||
|
millis_t Power::lastPowerOn;
|
||||||
|
|
||||||
|
bool Power::is_power_needed() {
|
||||||
|
#if ENABLED(AUTO_POWER_FANS)
|
||||||
|
for (uint8_t i = 0; i < FAN_COUNT; i++) if (fanSpeeds[i] > 0) return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(AUTO_POWER_E_FANS)
|
||||||
|
HOTEND_LOOP() if (thermalManager.autofan_speed[e] > 0) return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLED(AUTO_POWER_CONTROLLERFAN) && HAS_CONTROLLERFAN
|
||||||
|
if (controllerFanSpeed > 0) return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON ||
|
||||||
|
thermalManager.soft_pwm_bed > 0
|
||||||
|
|| E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
|
||||||
|
#if E_STEPPERS > 1
|
||||||
|
|| E1_ENABLE_READ == E_ENABLE_ON
|
||||||
|
#if HAS_X2_ENABLE
|
||||||
|
|| X2_ENABLE_READ == X_ENABLE_ON
|
||||||
|
#endif
|
||||||
|
#if E_STEPPERS > 2
|
||||||
|
|| E2_ENABLE_READ == E_ENABLE_ON
|
||||||
|
#if E_STEPPERS > 3
|
||||||
|
|| E3_ENABLE_READ == E_ENABLE_ON
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
) return true;
|
||||||
|
|
||||||
|
HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0) return true;
|
||||||
|
if (thermalManager.degTargetBed() > 0) return true;
|
||||||
|
|
||||||
|
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();
|
||||||
|
OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Power::power_off() {
|
||||||
|
OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // AUTO_POWER_CONTROL
|
@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* Marlin 3D Printer Firmware
|
||||||
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||||
|
*
|
||||||
|
* 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.h - power control
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef POWER_H
|
||||||
|
#define POWER_H
|
||||||
|
|
||||||
|
class Power {
|
||||||
|
public:
|
||||||
|
static void check();
|
||||||
|
static void power_on();
|
||||||
|
static void power_off();
|
||||||
|
private:
|
||||||
|
static millis_t lastPowerOn;
|
||||||
|
static bool is_power_needed();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Power powerManager;
|
||||||
|
|
||||||
|
#endif // POWER_H
|
Loading…
Reference in New Issue