diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index ffd457db41b9..c2eba215770b 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2566,10 +2566,15 @@ #define HAS_AUTO_FAN 1 #define _FANOVERLAP(A,B) (A##_AUTO_FAN_PIN == E##B##_AUTO_FAN_PIN) #define _CHFANOVERLAP(A) || _FANOVERLAP(CHAMBER,B) + #define _COFANOVERLAP(A) || _FANOVERLAP(COOLER,B) #if HAS_AUTO_FAN && (0 REPEAT(8, _CHFANOVERLAP)) #define AUTO_CHAMBER_IS_E 1 #endif + #if HAS_AUTO_FAN && (0 REPEAT(8, _COFANOVERLAP)) + #define AUTO_COOLER_IS_E 1 + #endif #undef _CHFANOVERLAP + #undef _COFANOVERLAP #endif // Fans check diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 0cf9cb252f2a..6b1fa03dab1b 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -1209,6 +1209,11 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) { #else #define INIT_CHAMBER_AUTO_FAN_PIN(P) SET_OUTPUT(P) #endif + #if COOLER_AUTO_FAN_SPEED != 255 + #define INIT_COOLER_AUTO_FAN_PIN(P) do{ if (0 REPEAT2(FAN_COUNT, _IS_FAN_PIN, P)) { SET_PWM(P); SET_FAST_PWM_FREQ(P); } else SET_OUTPUT(P); }while(0) + #else + #define INIT_COOLER_AUTO_FAN_PIN(P) SET_OUTPUT(P) + #endif #ifndef CHAMBER_FAN_INDEX #define CHAMBER_FAN_INDEX HOTENDS @@ -1222,9 +1227,16 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) { #define _NEXT_FAN(N) , REPEAT2(N,_EFAN,N) N RREPEAT_S(1, HOTENDS, _NEXT_FAN) #endif + #define _NFAN HOTENDS #if HAS_AUTO_CHAMBER_FAN - #define _CFAN(B) _FANOVERLAP(CHAMBER,B) ? B : - , REPEAT(HOTENDS,_CFAN) (HOTENDS) + #define _CHFAN(B) _FANOVERLAP(CHAMBER,B) ? B : + , (REPEAT(HOTENDS,_CHFAN) (_NFAN)) + #undef _NFAN + #define _NFAN INCREMENT(HOTENDS) + #endif + #if HAS_AUTO_COOLER_FAN + #define _COFAN(B) _FANOVERLAP(COOLER,B) ? B : + , (REPEAT(HOTENDS,_COFAN) (_NFAN)) #endif }; @@ -1282,6 +1294,9 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) { #if HAS_AUTO_CHAMBER_FAN && !AUTO_CHAMBER_IS_E case CHAMBER_FAN_INDEX: _UPDATE_AUTO_FAN(CHAMBER, fan_on, CHAMBER_AUTO_FAN_SPEED); break; #endif + #if HAS_AUTO_COOLER_FAN && !AUTO_COOLER_IS_E + case COOLER_FAN_INDEX: _UPDATE_AUTO_FAN(COOLER, fan_on, COOLER_AUTO_FAN_SPEED); break; + #endif } SBI(fanDone, realFan); } @@ -2743,6 +2758,9 @@ void Temperature::init() { #if HAS_AUTO_CHAMBER_FAN && !AUTO_CHAMBER_IS_E INIT_CHAMBER_AUTO_FAN_PIN(CHAMBER_AUTO_FAN_PIN); #endif + #if HAS_AUTO_COOLER_FAN && !AUTO_COOLER_IS_E + INIT_COOLER_AUTO_FAN_PIN(COOLER_AUTO_FAN_PIN); + #endif #endif // HAS_AUTO_FAN #if HAS_HOTEND