Browse Source

Move Controller Fan to feature

Scott Lahteine 7 years ago
parent
commit
6f92ab7eed
3 changed files with 96 additions and 41 deletions
  1. 5
    41
      Marlin/src/Marlin.cpp
  2. 63
    0
      Marlin/src/feature/controllerfan.cpp
  3. 28
    0
      Marlin/src/feature/controllerfan.h

+ 5
- 41
Marlin/src/Marlin.cpp View File

138
   #include "module/tool_change.h"
138
   #include "module/tool_change.h"
139
 #endif
139
 #endif
140
 
140
 
141
+#if ENABLED(USE_CONTROLLER_FAN)
142
+  #include "feature/controllerfan.h"
143
+#endif
144
+
141
 bool Running = true;
145
 bool Running = true;
142
 
146
 
143
 /**
147
 /**
320
   SYNC_PLAN_POSITION_KINEMATIC();
324
   SYNC_PLAN_POSITION_KINEMATIC();
321
 }
325
 }
322
 
326
 
323
-#if ENABLED(USE_CONTROLLER_FAN)
324
-
325
-  void controllerFan() {
326
-    static millis_t lastMotorOn = 0, // Last time a motor was turned on
327
-                    nextMotorCheck = 0; // Last time the state was checked
328
-    const millis_t ms = millis();
329
-    if (ELAPSED(ms, nextMotorCheck)) {
330
-      nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
331
-      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
332
-          || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
333
-          #if E_STEPPERS > 1
334
-            || E1_ENABLE_READ == E_ENABLE_ON
335
-            #if HAS_X2_ENABLE
336
-              || X2_ENABLE_READ == X_ENABLE_ON
337
-            #endif
338
-            #if E_STEPPERS > 2
339
-              || E2_ENABLE_READ == E_ENABLE_ON
340
-              #if E_STEPPERS > 3
341
-                || E3_ENABLE_READ == E_ENABLE_ON
342
-                #if E_STEPPERS > 4
343
-                  || E4_ENABLE_READ == E_ENABLE_ON
344
-                #endif // E_STEPPERS > 4
345
-              #endif // E_STEPPERS > 3
346
-            #endif // E_STEPPERS > 2
347
-          #endif // E_STEPPERS > 1
348
-      ) {
349
-        lastMotorOn = ms; //... set time to NOW so the fan will turn on
350
-      }
351
-
352
-      // Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
353
-      uint8_t speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : CONTROLLERFAN_SPEED;
354
-
355
-      // allows digital or PWM fan output to be used (see M42 handling)
356
-      WRITE(CONTROLLER_FAN_PIN, speed);
357
-      analogWrite(CONTROLLER_FAN_PIN, speed);
358
-    }
359
-  }
360
-
361
-#endif // USE_CONTROLLER_FAN
362
-
363
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
327
 #if ENABLED(FILAMENT_RUNOUT_SENSOR)
364
 
328
 
365
   void handle_filament_runout() {
329
   void handle_filament_runout() {
510
   #endif
474
   #endif
511
 
475
 
512
   #if ENABLED(USE_CONTROLLER_FAN)
476
   #if ENABLED(USE_CONTROLLER_FAN)
513
-    controllerFan(); // Check if fan should be turned on to cool stepper drivers down
477
+    controllerfan_update(); // Check if fan should be turned on to cool stepper drivers down
514
   #endif
478
   #endif
515
 
479
 
516
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
480
   #if ENABLED(EXTRUDER_RUNOUT_PREVENT)

+ 63
- 0
Marlin/src/feature/controllerfan.cpp View File

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
+#include "../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(USE_CONTROLLER_FAN)
26
+
27
+void controllerfan_update() {
28
+  static millis_t lastMotorOn = 0, // Last time a motor was turned on
29
+                  nextMotorCheck = 0; // Last time the state was checked
30
+  const millis_t ms = millis();
31
+  if (ELAPSED(ms, nextMotorCheck)) {
32
+    nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
33
+    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
34
+        || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
35
+        #if E_STEPPERS > 1
36
+          || E1_ENABLE_READ == E_ENABLE_ON
37
+          #if HAS_X2_ENABLE
38
+            || X2_ENABLE_READ == X_ENABLE_ON
39
+          #endif
40
+          #if E_STEPPERS > 2
41
+            || E2_ENABLE_READ == E_ENABLE_ON
42
+            #if E_STEPPERS > 3
43
+              || E3_ENABLE_READ == E_ENABLE_ON
44
+              #if E_STEPPERS > 4
45
+                || E4_ENABLE_READ == E_ENABLE_ON
46
+              #endif // E_STEPPERS > 4
47
+            #endif // E_STEPPERS > 3
48
+          #endif // E_STEPPERS > 2
49
+        #endif // E_STEPPERS > 1
50
+    ) {
51
+      lastMotorOn = ms; //... set time to NOW so the fan will turn on
52
+    }
53
+
54
+    // Fan off if no steppers have been enabled for CONTROLLERFAN_SECS seconds
55
+    uint8_t speed = (!lastMotorOn || ELAPSED(ms, lastMotorOn + (CONTROLLERFAN_SECS) * 1000UL)) ? 0 : CONTROLLERFAN_SPEED;
56
+
57
+    // allows digital or PWM fan output to be used (see M42 handling)
58
+    WRITE(CONTROLLER_FAN_PIN, speed);
59
+    analogWrite(CONTROLLER_FAN_PIN, speed);
60
+  }
61
+}
62
+
63
+#endif // USE_CONTROLLER_FAN

+ 28
- 0
Marlin/src/feature/controllerfan.h View File

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
+#ifndef __CONTROLLERFAN_H__
24
+#define __CONTROLLERFAN_H__
25
+
26
+void controllerfan_update();
27
+
28
+#endif // __CONTROLLERFAN_H__

Loading…
Cancel
Save