From e602c28ad975f2c0cb575509c99d13dcd35dff69 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 9 Jun 2015 16:54:28 -0700 Subject: [PATCH 1/2] Set auto fan pins to OUTPUT during init Fixes the problem of these pins being left in INPUT state, as described in #1497 --- Marlin/temperature.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index edbab7f19d..25ec3887c8 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -374,7 +374,6 @@ 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); } @@ -918,6 +917,19 @@ void tp_init() { ANALOG_SELECT(FILWIDTH_PIN); #endif + #if HAS_AUTO_FAN_0 + pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT); + #endif + #if HAS_AUTO_FAN_1 && (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) + pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT); + #endif + #if HAS_AUTO_FAN_2 && (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) && (EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) + pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT); + #endif + #if HAS_AUTO_FAN_3 && (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) && (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN) && (EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_2_AUTO_FAN_PIN) + pinMode(EXTRUDER_3_AUTO_FAN_PIN, OUTPUT); + #endif + // Use timer0 for temperature measurement // Interleave temperature interrupt with millies interrupt OCR0B = 128; From 1d94d098bf27bdfcaf18988e20bb18507acb50ce Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 9 Jun 2015 17:01:47 -0700 Subject: [PATCH 2/2] Formatting tweaks as part of fixing issue 1497 --- Marlin/temperature.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 25ec3887c8..48a3085068 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -370,16 +370,14 @@ int getHeaterPower(int heater) { #if HAS_AUTO_FAN -void setExtruderAutoFanState(int pin, bool state) -{ +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). digitalWrite(pin, newFanSpeed); analogWrite(pin, newFanSpeed); } -void checkExtruderAutoFans() -{ +void checkExtruderAutoFans() { uint8_t fanState = 0; // which fan pins need to be turned on? @@ -442,7 +440,7 @@ void checkExtruderAutoFans() #endif } -#endif // any extruder auto fan pins set +#endif // HAS_AUTO_FAN // // Temperature Error Handlers @@ -916,7 +914,7 @@ void tp_init() { #if HAS_FILAMENT_SENSOR ANALOG_SELECT(FILWIDTH_PIN); #endif - + #if HAS_AUTO_FAN_0 pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT); #endif