Fix controllerFan() code

- Add support for 4th extruder
- Fix parentheses matching
- Apply coding standards
- Address issue mentioned at #1575
This commit is contained in:
Scott Lahteine 2015-03-15 06:55:31 -07:00
parent bb4cb1b15a
commit b80ed51fcc

View File

@ -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
#if EXTRUDERS > 2 || E1_ENABLE_READ == E_ENABLE_ON
|| (E2_ENABLE_READ) == (E_ENABLE_ON)) #if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
#endif || X2_ENABLE_READ == X_ENABLE_ON
#if EXTRUDER > 1 #endif
#if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1 #if EXTRUDERS > 2
|| (X2_ENABLE_READ) == (X_ENABLE_ON)) || E2_ENABLE_READ == E_ENABLE_ON
#if EXTRUDERS > 3
|| E3_ENABLE_READ == E_ENABLE_ON
#endif
#endif
#endif #endif
|| (E1_ENABLE_READ) == (E_ENABLE_ON)) ) {
#endif lastMotor = ms; //... set time to NOW so the fan will turn on
|| (E0_ENABLE_READ) == (E_ENABLE_ON))) //If any of the drivers are enabled...
{
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
{
// allows digital or PWM fan output to be used (see M42 handling)
digitalWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED);
analogWrite(CONTROLLERFAN_PIN, CONTROLLERFAN_SPEED);
} }
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)
digitalWrite(CONTROLLERFAN_PIN, speed);
analogWrite(CONTROLLERFAN_PIN, speed);
} }
} }
#endif #endif