Further reduce code by using precompiler logic

master
Robert F-C 12 years ago
parent 372e12f83f
commit f1263d3f88

@ -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

@ -400,12 +400,13 @@ void manage_heater()
} // End extruder for loop } // End extruder for loop
#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 #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);
@ -417,11 +418,10 @@ void manage_heater()
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);
@ -433,11 +433,9 @@ void manage_heater()
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);
@ -449,6 +447,7 @@ void manage_heater()
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)

Loading…
Cancel
Save