2017-09-18 01:44:59 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2019-02-12 15:06:53 -06:00
|
|
|
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-09-18 01:44:59 -05: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
|
|
|
|
2017-10-07 07:26:36 -05:00
|
|
|
#include "../module/stepper_indirection.h"
|
|
|
|
#include "../module/temperature.h"
|
|
|
|
|
2018-10-07 15:34:41 -05:00
|
|
|
uint8_t controllerfan_speed;
|
2018-02-16 02:18:50 -06:00
|
|
|
|
2017-09-18 01:44:59 -05: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 01:49:30 -05:00
|
|
|
|
|
|
|
// If any of the drivers or the bed are enabled...
|
2018-05-04 00:15:31 -05: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-29 01:49:30 -05: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
|
2018-06-19 11:55:49 -05:00
|
|
|
#if HAS_Z3_ENABLE
|
|
|
|
|| Z3_ENABLE_READ == Z_ENABLE_ON
|
|
|
|
#endif
|
2019-03-01 01:51:24 -06: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
|
2017-09-18 01:44:59 -05: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
|
|
|
|
uint8_t speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : CONTROLLERFAN_SPEED;
|
2018-10-07 15:34:41 -05:00
|
|
|
controllerfan_speed = speed;
|
2017-09-18 01:44:59 -05:00
|
|
|
|
|
|
|
// allows digital or PWM fan output to be used (see M42 handling)
|
|
|
|
WRITE(CONTROLLER_FAN_PIN, speed);
|
|
|
|
analogWrite(CONTROLLER_FAN_PIN, speed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_CONTROLLER_FAN
|