1 |
ron |
1 |
/**
|
|
|
2 |
* Marlin 3D Printer Firmware
|
|
|
3 |
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
4 |
*
|
|
|
5 |
* Based on Sprinter and grbl.
|
|
|
6 |
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
7 |
*
|
|
|
8 |
* This program is free software: you can redistribute it and/or modify
|
|
|
9 |
* it under the terms of the GNU General Public License as published by
|
|
|
10 |
* the Free Software Foundation, either version 3 of the License, or
|
|
|
11 |
* (at your option) any later version.
|
|
|
12 |
*
|
|
|
13 |
* This program is distributed in the hope that it will be useful,
|
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 |
* GNU General Public License for more details.
|
|
|
17 |
*
|
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
|
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
*
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* power.cpp - power control
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
#include "MarlinConfig.h"
|
|
|
28 |
|
|
|
29 |
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
30 |
|
|
|
31 |
#include "power.h"
|
|
|
32 |
#include "temperature.h"
|
|
|
33 |
#include "stepper_indirection.h"
|
|
|
34 |
|
|
|
35 |
Power powerManager;
|
|
|
36 |
|
|
|
37 |
millis_t Power::lastPowerOn;
|
|
|
38 |
|
|
|
39 |
bool Power::is_power_needed() {
|
|
|
40 |
#if ENABLED(AUTO_POWER_FANS)
|
|
|
41 |
for (uint8_t i = 0; i < FAN_COUNT; i++) if (fanSpeeds[i] > 0) return true;
|
|
|
42 |
#endif
|
|
|
43 |
|
|
|
44 |
#if ENABLED(AUTO_POWER_E_FANS)
|
|
|
45 |
HOTEND_LOOP() if (thermalManager.autofan_speed[e] > 0) return true;
|
|
|
46 |
#endif
|
|
|
47 |
|
|
|
48 |
#if ENABLED(AUTO_POWER_CONTROLLERFAN) && HAS_CONTROLLER_FAN && ENABLED(USE_CONTROLLER_FAN)
|
|
|
49 |
if (controllerFanSpeed > 0) return true;
|
|
|
50 |
#endif
|
|
|
51 |
|
|
|
52 |
// If any of the drivers or the bed are enabled...
|
|
|
53 |
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON
|
|
|
54 |
#if HAS_HEATED_BED
|
|
|
55 |
|| thermalManager.soft_pwm_amount_bed > 0
|
|
|
56 |
#endif
|
|
|
57 |
#if HAS_X2_ENABLE
|
|
|
58 |
|| X2_ENABLE_READ == X_ENABLE_ON
|
|
|
59 |
#endif
|
|
|
60 |
#if HAS_Y2_ENABLE
|
|
|
61 |
|| Y2_ENABLE_READ == Y_ENABLE_ON
|
|
|
62 |
#endif
|
|
|
63 |
#if HAS_Z2_ENABLE
|
|
|
64 |
|| Z2_ENABLE_READ == Z_ENABLE_ON
|
|
|
65 |
#endif
|
|
|
66 |
|| E0_ENABLE_READ == E_ENABLE_ON
|
|
|
67 |
#if E_STEPPERS > 1
|
|
|
68 |
|| E1_ENABLE_READ == E_ENABLE_ON
|
|
|
69 |
#if E_STEPPERS > 2
|
|
|
70 |
|| E2_ENABLE_READ == E_ENABLE_ON
|
|
|
71 |
#if E_STEPPERS > 3
|
|
|
72 |
|| E3_ENABLE_READ == E_ENABLE_ON
|
|
|
73 |
#if E_STEPPERS > 4
|
|
|
74 |
|| E4_ENABLE_READ == E_ENABLE_ON
|
|
|
75 |
#endif
|
|
|
76 |
#endif
|
|
|
77 |
#endif
|
|
|
78 |
#endif
|
|
|
79 |
) return true;
|
|
|
80 |
|
|
|
81 |
HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0) return true;
|
|
|
82 |
#if HAS_HEATED_BED
|
|
|
83 |
if (thermalManager.degTargetBed() > 0) return true;
|
|
|
84 |
#endif
|
|
|
85 |
|
|
|
86 |
return false;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
void Power::check() {
|
|
|
90 |
static millis_t nextPowerCheck = 0;
|
|
|
91 |
millis_t ms = millis();
|
|
|
92 |
if (ELAPSED(ms, nextPowerCheck)) {
|
|
|
93 |
nextPowerCheck = ms + 2500UL;
|
|
|
94 |
if (is_power_needed())
|
|
|
95 |
power_on();
|
|
|
96 |
else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + (POWER_TIMEOUT) * 1000UL))
|
|
|
97 |
power_off();
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
void Power::power_on() {
|
|
|
102 |
lastPowerOn = millis();
|
|
|
103 |
if (!powersupply_on) {
|
|
|
104 |
PSU_PIN_ON();
|
|
|
105 |
|
|
|
106 |
#if HAS_TRINAMIC
|
|
|
107 |
delay(100); // Wait for power to settle
|
|
|
108 |
restore_stepper_drivers();
|
|
|
109 |
#endif
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
void Power::power_off() {
|
|
|
114 |
if (powersupply_on) PSU_PIN_OFF();
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
#endif // AUTO_POWER_CONTROL
|