Fix controllerFan() code

- Add support for 4th extruder
- Fix parentheses matching
- Apply coding standards
- Address issue mentioned at #1575
master
Scott Lahteine 10 years ago
parent bb4cb1b15a
commit b80ed51fcc

@ -5137,41 +5137,34 @@ void prepare_arc_move(char isclockwise) {
#endif #endif
#endif #endif
unsigned long lastMotor = 0; //Save the time for when a motor was turned on last unsigned long lastMotor = 0; // Last time a motor was turned on
unsigned long lastMotorCheck = 0; unsigned long lastMotorCheck = 0; // Last time the state was checked
void controllerFan() void controllerFan() {
{ uint32_t ms = millis();
if ((millis() - lastMotorCheck) >= 2500) //Not a time critical function, so we only check every 2500ms if (ms >= lastMotorCheck + 2500) { // Not a time critical function, so we only check every 2500ms
{ lastMotorCheck = ms;
lastMotorCheck = millis(); if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || soft_pwm_bed > 0
|| E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
if((X_ENABLE_READ) == (X_ENABLE_ON)) || (Y_ENABLE_READ) == (Y_ENABLE_ON)) || (Z_ENABLE_READ) == (Z_ENABLE_ON)) || (soft_pwm_bed > 0) #if EXTRUDERS > 1
|| E1_ENABLE_READ == E_ENABLE_ON
#if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
|| X2_ENABLE_READ == X_ENABLE_ON
#endif
#if EXTRUDERS > 2 #if EXTRUDERS > 2
|| (E2_ENABLE_READ) == (E_ENABLE_ON)) || E2_ENABLE_READ == E_ENABLE_ON
#if EXTRUDERS > 3
|| E3_ENABLE_READ == E_ENABLE_ON
#endif #endif
#if EXTRUDER > 1
#if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
|| (X2_ENABLE_READ) == (X_ENABLE_ON))
#endif #endif
|| (E1_ENABLE_READ) == (E_ENABLE_ON))
#endif #endif
|| (E0_ENABLE_READ) == (E_ENABLE_ON))) //If any of the drivers are enabled... ) {
{ lastMotor = ms; //... set time to NOW so the fan will turn on
lastMotor = millis(); //... set time to NOW so the fan will turn on
}
if ((millis() - lastMotor) >= (CONTROLLERFAN_SECS*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC...
{
digitalWrite(CONTROLLERFAN_PIN, 0);
analogWrite(CONTROLLERFAN_PIN, 0);
} }
else uint8_t speed = (lastMotor == 0 || ms >= lastMotor + (CONTROLLERFAN_SECS * 1000UL)) ? 0 : CONTROLLERFAN_SPEED;
{
// allows digital or PWM fan output to be used (see M42 handling) // allows digital or PWM fan output to be used (see M42 handling)
digitalWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED); digitalWrite(CONTROLLERFAN_PIN, speed);
analogWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED); analogWrite(CONTROLLERFAN_PIN, speed);
}
} }
} }
#endif #endif

Loading…
Cancel
Save