2017-09-18 06:44:59 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-18 06:44:59 +00:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 04:57:50 +00:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-09-18 06:44:59 +00: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
|
|
|
|
2019-09-01 00:44:45 +00:00
|
|
|
#include "../module/stepper/indirection.h"
|
2017-10-07 12:26:36 +00:00
|
|
|
#include "../module/temperature.h"
|
|
|
|
|
2018-10-07 20:34:41 +00:00
|
|
|
uint8_t controllerfan_speed;
|
2018-02-16 08:18:50 +00:00
|
|
|
|
2017-09-18 06:44:59 +00:00
|
|
|
void controllerfan_update() {
|
|
|
|
static millis_t lastMotorOn = 0, // Last time a motor was turned on
|
|
|
|
nextMotorCheck = 0; // Last time the state was checked
|
|
|
|
const millis_t ms = millis();
|
|
|
|
if (ELAPSED(ms, nextMotorCheck)) {
|
|
|
|
nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
|
2018-08-29 06:49:30 +00:00
|
|
|
|
2019-08-17 02:57:19 +00:00
|
|
|
const bool xory = X_ENABLE_READ() == X_ENABLE_ON || Y_ENABLE_READ() == Y_ENABLE_ON;
|
|
|
|
|
2018-08-29 06:49:30 +00:00
|
|
|
// If any of the drivers or the bed are enabled...
|
2019-08-17 02:57:19 +00:00
|
|
|
if (xory || Z_ENABLE_READ() == Z_ENABLE_ON
|
2018-05-04 05:15:31 +00:00
|
|
|
#if HAS_HEATED_BED
|
2019-03-07 08:09:39 +00:00
|
|
|
|| thermalManager.temp_bed.soft_pwm_amount > 0
|
2018-05-04 05:15:31 +00:00
|
|
|
#endif
|
2018-08-29 06:49:30 +00:00
|
|
|
#if HAS_X2_ENABLE
|
2019-08-17 02:57:19 +00:00
|
|
|
|| X2_ENABLE_READ() == X_ENABLE_ON
|
2018-08-29 06:49:30 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_ENABLE
|
2019-08-17 02:57:19 +00:00
|
|
|
|| Y2_ENABLE_READ() == Y_ENABLE_ON
|
2018-08-29 06:49:30 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z2_ENABLE
|
2019-08-17 02:57:19 +00:00
|
|
|
|| Z2_ENABLE_READ() == Z_ENABLE_ON
|
2018-08-29 06:49:30 +00:00
|
|
|
#endif
|
2018-06-19 16:55:49 +00:00
|
|
|
#if HAS_Z3_ENABLE
|
2019-08-17 02:57:19 +00:00
|
|
|
|| Z3_ENABLE_READ() == Z_ENABLE_ON
|
2018-06-19 16:55:49 +00:00
|
|
|
#endif
|
2019-03-01 07:51:24 +00:00
|
|
|
#if E_STEPPERS
|
2019-11-09 23:59:04 +00:00
|
|
|
#define _OR_ENABLED_E(N) || E##N##_ENABLE_READ() == E_ENABLE_ON
|
|
|
|
REPEAT(E_STEPPERS, _OR_ENABLED_E)
|
|
|
|
#endif
|
2017-09-18 06:44:59 +00:00
|
|
|
) {
|
|
|
|
lastMotorOn = ms; //... set time to NOW so the fan will turn on
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
|
2019-08-17 02:57:19 +00:00
|
|
|
controllerfan_speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : (
|
|
|
|
#ifdef CONTROLLERFAN_SPEED_Z_ONLY
|
|
|
|
xory ? CONTROLLERFAN_SPEED : CONTROLLERFAN_SPEED_Z_ONLY
|
|
|
|
#else
|
|
|
|
CONTROLLERFAN_SPEED
|
|
|
|
#endif
|
|
|
|
);
|
2017-09-18 06:44:59 +00:00
|
|
|
|
2019-08-17 02:57:19 +00:00
|
|
|
// Allow digital or PWM fan output (see M42 handling)
|
|
|
|
WRITE(CONTROLLER_FAN_PIN, controllerfan_speed);
|
|
|
|
analogWrite(pin_t(CONTROLLER_FAN_PIN), controllerfan_speed);
|
2017-09-18 06:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_CONTROLLER_FAN
|