Selaa lähdekoodia

Fix controllerFan() code

- Add support for 4th extruder
- Fix parentheses matching
- Apply coding standards
- Address issue mentioned at #1575
Scott Lahteine 10 vuotta sitten
vanhempi
commit
b80ed51fcc
1 muutettua tiedostoa jossa 26 lisäystä ja 33 poistoa
  1. 26
    33
      Marlin/Marlin_main.cpp

+ 26
- 33
Marlin/Marlin_main.cpp Näytä tiedosto

5137
   #endif
5137
   #endif
5138
 #endif
5138
 #endif
5139
 
5139
 
5140
-unsigned long lastMotor = 0; //Save the time for when a motor was turned on last
5141
-unsigned long lastMotorCheck = 0;
5142
-
5143
-void controllerFan()
5144
-{
5145
-  if ((millis() - lastMotorCheck) >= 2500) //Not a time critical function, so we only check every 2500ms
5146
-  {
5147
-    lastMotorCheck = millis();
5148
-	
5149
-    if((X_ENABLE_READ) == (X_ENABLE_ON)) || (Y_ENABLE_READ) == (Y_ENABLE_ON)) || (Z_ENABLE_READ) == (Z_ENABLE_ON)) || (soft_pwm_bed > 0)
5150
-    #if EXTRUDERS > 2
5151
-       || (E2_ENABLE_READ) == (E_ENABLE_ON))
5152
-    #endif
5153
-    #if EXTRUDER > 1
5154
-      #if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
5155
-       || (X2_ENABLE_READ) == (X_ENABLE_ON))
5140
+unsigned long lastMotor = 0; // Last time a motor was turned on
5141
+unsigned long lastMotorCheck = 0; // Last time the state was checked
5142
+
5143
+void controllerFan() {
5144
+  uint32_t ms = millis();
5145
+  if (ms >= lastMotorCheck + 2500) { // Not a time critical function, so we only check every 2500ms
5146
+    lastMotorCheck = ms;
5147
+    if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
5148
+      || E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
5149
+      #if EXTRUDERS > 1
5150
+        || E1_ENABLE_READ == E_ENABLE_ON
5151
+        #if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
5152
+          || X2_ENABLE_READ == X_ENABLE_ON
5153
+        #endif
5154
+        #if EXTRUDERS > 2
5155
+          || E2_ENABLE_READ == E_ENABLE_ON
5156
+          #if EXTRUDERS > 3
5157
+            || E3_ENABLE_READ == E_ENABLE_ON
5158
+          #endif
5159
+        #endif
5156
       #endif
5160
       #endif
5157
-       || (E1_ENABLE_READ) == (E_ENABLE_ON))
5158
-    #endif
5159
-       || (E0_ENABLE_READ) == (E_ENABLE_ON))) //If any of the drivers are enabled...
5160
-    {
5161
-      lastMotor = millis(); //... set time to NOW so the fan will turn on
5162
-    }
5163
-
5164
-    if ((millis() - lastMotor) >= (CONTROLLERFAN_SECS*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC...
5165
-    {
5166
-        digitalWrite(CONTROLLERFAN_PIN, 0);
5167
-        analogWrite(CONTROLLERFAN_PIN, 0);
5168
-    }
5169
-    else
5170
-    {
5171
-        // allows digital or PWM fan output to be used (see M42 handling)
5172
-        digitalWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED);
5173
-        analogWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED);
5161
+    ) {
5162
+      lastMotor = ms; //... set time to NOW so the fan will turn on
5174
     }
5163
     }
5164
+    uint8_t speed = (lastMotor == 0 || ms >= lastMotor + (CONTROLLERFAN_SECS * 1000UL)) ? 0 : CONTROLLERFAN_SPEED;
5165
+    // allows digital or PWM fan output to be used (see M42 handling)
5166
+    digitalWrite(CONTROLLERFAN_PIN, speed);
5167
+    analogWrite(CONTROLLERFAN_PIN, speed);
5175
   }
5168
   }
5176
 }
5169
 }
5177
 #endif
5170
 #endif

Loading…
Peruuta
Tallenna