diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp
index a5bc0d2433..ccd32a465c 100644
--- a/Marlin/src/Marlin.cpp
+++ b/Marlin/src/Marlin.cpp
@@ -138,6 +138,10 @@
#include "module/tool_change.h"
#endif
+#if ENABLED(USE_CONTROLLER_FAN)
+ #include "feature/controllerfan.h"
+#endif
+
bool Running = true;
/**
@@ -320,46 +324,6 @@ void quickstop_stepper() {
SYNC_PLAN_POSITION_KINEMATIC();
}
-#if ENABLED(USE_CONTROLLER_FAN)
-
- void controllerFan() {
- 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
- if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_amount_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
- #if E_STEPPERS > 4
- || E4_ENABLE_READ == E_ENABLE_ON
- #endif // E_STEPPERS > 4
- #endif // E_STEPPERS > 3
- #endif // E_STEPPERS > 2
- #endif // E_STEPPERS > 1
- ) {
- 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;
-
- // 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
-
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
void handle_filament_runout() {
@@ -510,7 +474,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
#endif
#if ENABLED(USE_CONTROLLER_FAN)
- controllerFan(); // Check if fan should be turned on to cool stepper drivers down
+ controllerfan_update(); // Check if fan should be turned on to cool stepper drivers down
#endif
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
diff --git a/Marlin/src/feature/controllerfan.cpp b/Marlin/src/feature/controllerfan.cpp
new file mode 100644
index 0000000000..f13ce18fca
--- /dev/null
+++ b/Marlin/src/feature/controllerfan.cpp
@@ -0,0 +1,63 @@
+/**
+ * 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 .
+ *
+ */
+
+#include "../inc/MarlinConfig.h"
+
+#if ENABLED(USE_CONTROLLER_FAN)
+
+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
+ if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_amount_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
+ #if E_STEPPERS > 4
+ || E4_ENABLE_READ == E_ENABLE_ON
+ #endif // E_STEPPERS > 4
+ #endif // E_STEPPERS > 3
+ #endif // E_STEPPERS > 2
+ #endif // E_STEPPERS > 1
+ ) {
+ 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;
+
+ // 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
diff --git a/Marlin/src/feature/controllerfan.h b/Marlin/src/feature/controllerfan.h
new file mode 100644
index 0000000000..8a7b393c33
--- /dev/null
+++ b/Marlin/src/feature/controllerfan.h
@@ -0,0 +1,28 @@
+/**
+ * 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 .
+ *
+ */
+
+#ifndef __CONTROLLERFAN_H__
+#define __CONTROLLERFAN_H__
+
+void controllerfan_update();
+
+#endif // __CONTROLLERFAN_H__