|
|
@ -99,8 +99,8 @@ static volatile bool temp_meas_ready = false; |
|
|
|
#ifdef FAN_SOFT_PWM |
|
|
|
static unsigned char soft_pwm_fan; |
|
|
|
#endif |
|
|
|
#if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1 |
|
|
|
static uint8_t extruderAutoFanState = 0; // extruder auto fan state stored as bitmap
|
|
|
|
#if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0 |
|
|
|
static unsigned long extruder_autofan_last_check; |
|
|
|
#endif |
|
|
|
|
|
|
|
#if EXTRUDERS > 3 |
|
|
@ -307,6 +307,73 @@ int getHeaterPower(int heater) { |
|
|
|
return soft_pwm[heater]; |
|
|
|
} |
|
|
|
|
|
|
|
#if EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0 |
|
|
|
|
|
|
|
void setExtruderAutoFanState(int pin, bool state) |
|
|
|
{ |
|
|
|
unsigned char newFanSpeed = (state != 0) ? EXTRUDER_AUTO_FAN_SPEED : 0; |
|
|
|
// this idiom allows both digital and PWM fan outputs (see M42 handling).
|
|
|
|
pinMode(pin, OUTPUT); |
|
|
|
digitalWrite(pin, newFanSpeed); |
|
|
|
analogWrite(pin, newFanSpeed); |
|
|
|
} |
|
|
|
|
|
|
|
void checkExtruderAutoFans() |
|
|
|
{ |
|
|
|
uint8_t fanState = 0; |
|
|
|
|
|
|
|
// which fan pins need to be turned on?
|
|
|
|
#if EXTRUDER_0_AUTO_FAN_PIN > 0 |
|
|
|
#if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN |
|
|
|
#error "You cannot set EXTRUDER_0_AUTO_FAN_PIN equal to FAN_PIN" |
|
|
|
#endif |
|
|
|
if (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) |
|
|
|
fanState |= 1; |
|
|
|
#endif |
|
|
|
#if EXTRUDER_1_AUTO_FAN_PIN > 0 |
|
|
|
#if EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN |
|
|
|
#error "You cannot set EXTRUDER_1_AUTO_FAN_PIN equal to FAN_PIN" |
|
|
|
#endif |
|
|
|
if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) |
|
|
|
{ |
|
|
|
if (EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) |
|
|
|
fanState |= 1; |
|
|
|
else |
|
|
|
fanState |= 2; |
|
|
|
} |
|
|
|
#endif |
|
|
|
#if EXTRUDER_2_AUTO_FAN_PIN > 0 |
|
|
|
#if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN |
|
|
|
#error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" |
|
|
|
#endif |
|
|
|
if (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE) |
|
|
|
{ |
|
|
|
if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_0_AUTO_FAN_PIN) |
|
|
|
fanState |= 1; |
|
|
|
else if (EXTRUDER_2_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN) |
|
|
|
fanState |= 2; |
|
|
|
else |
|
|
|
fanState |= 4; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// update extruder auto fan states
|
|
|
|
#if EXTRUDER_0_AUTO_FAN_PIN > 0 |
|
|
|
setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); |
|
|
|
#endif |
|
|
|
#if EXTRUDER_1_AUTO_FAN_PIN > 0 |
|
|
|
if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) |
|
|
|
setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); |
|
|
|
#endif |
|
|
|
#if EXTRUDER_2_AUTO_FAN_PIN > 0 |
|
|
|
if (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN |
|
|
|
&& EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) |
|
|
|
setExtruderAutoFanState(EXTRUDER_2_AUTO_FAN_PIN, (fanState & 4) != 0); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
#endif // any extruder auto fan pins set
|
|
|
|
|
|
|
|
void manage_heater() |
|
|
|
{ |
|
|
|
float pid_input; |
|
|
@ -400,54 +467,13 @@ void manage_heater() |
|
|
|
|
|
|
|
} // 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 |
|
|
|
// check the extruder 0 setting (and any ganged auto fan outputs)
|
|
|
|
newFanState = (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_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)); |
|
|
|
if ((extruderAutoFanState & 1) != newFanState) // store state in first bit
|
|
|
|
{ |
|
|
|
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); |
|
|
|
if (EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN) |
|
|
|
fanSpeed = newFanSpeed; |
|
|
|
pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT); |
|
|
|
digitalWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); |
|
|
|
analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed); |
|
|
|
extruderAutoFanState = newFanState | (extruderAutoFanState & ~1); |
|
|
|
} |
|
|
|
#endif //EXTRUDER_0_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)
|
|
|
|
newFanState = (current_temperature[1] > 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 EXTRUDER_0_AUTO_FAN_PIN > 0 || EXTRUDER_1_AUTO_FAN_PIN > 0 || EXTRUDER_2_AUTO_FAN_PIN > 0 |
|
|
|
if(millis() - extruder_autofan_last_check > 2500) // only need to check fan state very infrequently
|
|
|
|
{ |
|
|
|
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); |
|
|
|
if (EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN) |
|
|
|
fanSpeed = newFanSpeed; |
|
|
|
pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT); |
|
|
|
digitalWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); |
|
|
|
analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed); |
|
|
|
extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2); |
|
|
|
} |
|
|
|
#endif //EXTRUDER_1_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)
|
|
|
|
newFanState = (current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE); |
|
|
|
if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit
|
|
|
|
{ |
|
|
|
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0); |
|
|
|
if (EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN) |
|
|
|
fanSpeed = newFanSpeed; |
|
|
|
pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT); |
|
|
|
digitalWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); |
|
|
|
analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed); |
|
|
|
extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4); |
|
|
|
} |
|
|
|
#endif //EXTRUDER_2_AUTO_FAN_PIN > -1
|
|
|
|
#endif // any AUTO_FAN_PIN enabled
|
|
|
|
checkExtruderAutoFans(); |
|
|
|
extruder_autofan_last_check = millis(); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifndef PIDTEMPBED |
|
|
|
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) |
|
|
|