Further reduce code by using precompiler logic

This commit is contained in:
Robert F-C 2013-03-02 16:12:11 +11:00
parent 372e12f83f
commit f1263d3f88
2 changed files with 15 additions and 16 deletions

View file

@ -86,7 +86,7 @@
//=========================================================================== //===========================================================================
// This defines the number of extruders // This defines the number of extruders
#define EXTRUDERS 1 #define EXTRUDERS 2
#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing

View file

@ -400,12 +400,13 @@ void manage_heater()
} // End extruder for loop } // End extruder for loop
#if EXTRUDER_0_AUTO_FAN_PIN > -1 #if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1
bool newFanState;
#if EXTRUDER_0_AUTO_FAN_PIN > -1
// check the extruder 0 setting (and any ganged auto fan outputs) // check the extruder 0 setting (and any ganged auto fan outputs)
bool newFanState = (EXTRUDER_0_AUTO_FAN_PIN > -1 && newFanState = (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE ||
(current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE ||
(EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN && current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) || (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN && current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) ||
(EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE))); (EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE));
if ((extruderAutoFanState & 1) != newFanState) // store state in first bit if ((extruderAutoFanState & 1) != newFanState) // store state in first bit
{ {
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
@ -416,12 +417,11 @@ void manage_heater()
analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed);
extruderAutoFanState = newFanState | (extruderAutoFanState & ~1); extruderAutoFanState = newFanState | (extruderAutoFanState & ~1);
} }
#endif //EXTRUDER_0_AUTO_FAN_PIN > -1 #endif //EXTRUDER_0_AUTO_FAN_PIN > -1
#if EXTRUDER_1_AUTO_FAN_PIN > -1 #if EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN
// check the extruder 1 setting (except when extruder 1 is the same as 0) // check the extruder 1 setting (except when extruder 1 is the same as 0)
newFanState = (EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && newFanState = (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE ||
(current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE || (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE));
(EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)));
if ((extruderAutoFanState & 2) != (newFanState<<1)) // use second bit if ((extruderAutoFanState & 2) != (newFanState<<1)) // use second bit
{ {
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
@ -432,12 +432,10 @@ void manage_heater()
analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed);
extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2); extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2);
} }
#endif //EXTRUDER_1_AUTO_FAN_PIN > -1 #endif //EXTRUDER_1_AUTO_FAN_PIN > -1
#if EXTRUDER_2_AUTO_FAN_PIN > -1 #if EXTRUDER_2_AUTO_FAN_PIN > -1 && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN
// check the extruder 2 setting (except when extruder 2 is the same as 1 or 0) // check the extruder 2 setting (except when extruder 2 is the same as 1 or 0)
newFanState = (EXTRUDER_2_AUTO_FAN_PIN > -1 && newFanState = (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE);
EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN &&
current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE);
if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit
{ {
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
@ -448,7 +446,8 @@ void manage_heater()
analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed);
extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4); extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4);
} }
#endif //EXTRUDER_2_AUTO_FAN_PIN > -1 #endif //EXTRUDER_2_AUTO_FAN_PIN > -1
#endif // any AUTO_FAN_PIN enabled
#ifndef PIDTEMPBED #ifndef PIDTEMPBED
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)