2017-09-18 06:44:59 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 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
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-09-18 06:44:59 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfig.h"
|
|
|
|
|
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
|
|
|
|
2020-03-18 18:41:12 +00:00
|
|
|
#include "controllerfan.h"
|
2021-09-28 06:07:51 +00:00
|
|
|
#include "../module/stepper.h"
|
2017-10-07 12:26:36 +00:00
|
|
|
#include "../module/temperature.h"
|
|
|
|
|
2020-03-18 18:41:12 +00:00
|
|
|
ControllerFan controllerFan;
|
2018-02-16 08:18:50 +00:00
|
|
|
|
2020-03-18 18:41:12 +00:00
|
|
|
uint8_t ControllerFan::speed;
|
|
|
|
|
|
|
|
#if ENABLED(CONTROLLER_FAN_EDITABLE)
|
|
|
|
controllerFan_settings_t ControllerFan::settings; // {0}
|
2020-11-10 09:32:08 +00:00
|
|
|
#else
|
|
|
|
const controllerFan_settings_t &ControllerFan::settings = controllerFan_defaults;
|
2020-03-18 18:41:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void ControllerFan::setup() {
|
|
|
|
SET_OUTPUT(CONTROLLER_FAN_PIN);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerFan::set_fan_speed(const uint8_t s) {
|
|
|
|
speed = s < (CONTROLLERFAN_SPEED_MIN) ? 0 : s; // Fan OFF below minimum
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerFan::update() {
|
|
|
|
static millis_t lastMotorOn = 0, // Last time a motor was turned on
|
2017-09-18 06:44:59 +00:00
|
|
|
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
|
|
|
|
2021-08-19 01:12:41 +00:00
|
|
|
// If any triggers for the controller fan are true...
|
|
|
|
// - At least one stepper driver is enabled
|
|
|
|
// - The heated bed is enabled
|
|
|
|
// - TEMP_SENSOR_BOARD is reporting >= CONTROLLER_FAN_MIN_BOARD_TEMP
|
2021-10-18 07:40:47 +00:00
|
|
|
const ena_mask_t axis_mask = TERN(CONTROLLER_FAN_USE_Z_ONLY, _BV(Z_AXIS), (ena_mask_t)~TERN0(CONTROLLER_FAN_IGNORE_Z, _BV(Z_AXIS)));
|
2021-09-28 06:07:51 +00:00
|
|
|
if ( (stepper.axis_enabled.bits & axis_mask)
|
2021-08-19 01:12:41 +00:00
|
|
|
|| TERN0(HAS_HEATED_BED, thermalManager.temp_bed.soft_pwm_amount > 0)
|
|
|
|
|| TERN0(HAS_CONTROLLER_FAN_MIN_BOARD_TEMP, thermalManager.wholeDegBoard() >= CONTROLLER_FAN_MIN_BOARD_TEMP)
|
|
|
|
) lastMotorOn = ms; //... set time to NOW so the fan will turn on
|
2017-09-18 06:44:59 +00:00
|
|
|
|
2020-03-18 18:41:12 +00:00
|
|
|
// Fan Settings. Set fan > 0:
|
|
|
|
// - If AutoMode is on and steppers have been enabled for CONTROLLERFAN_IDLE_TIME seconds.
|
|
|
|
// - If System is on idle and idle fan speed settings is activated.
|
|
|
|
set_fan_speed(
|
2020-04-04 00:49:45 +00:00
|
|
|
settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + SEC_TO_MS(settings.duration))
|
2020-03-18 18:41:12 +00:00
|
|
|
? settings.active_speed : settings.idle_speed
|
2019-08-17 02:57:19 +00:00
|
|
|
);
|
2017-09-18 06:44:59 +00:00
|
|
|
|
2021-11-14 11:55:31 +00:00
|
|
|
#if ENABLED(FAN_SOFT_PWM)
|
|
|
|
thermalManager.soft_pwm_controller_speed = speed;
|
|
|
|
#else
|
|
|
|
if (PWM_PIN(CONTROLLER_FAN_PIN))
|
|
|
|
set_pwm_duty(pin_t(CONTROLLER_FAN_PIN), speed);
|
|
|
|
else
|
|
|
|
WRITE(CONTROLLER_FAN_PIN, speed > 0);
|
|
|
|
#endif
|
2017-09-18 06:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_CONTROLLER_FAN
|