Skip to content

Commit

Permalink
Fix _FANOVERLAP macros
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 23, 2023
1 parent 97afc7e commit 9ba7b7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
22 changes: 13 additions & 9 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2564,17 +2564,21 @@

#if ANY(HAS_AUTO_FAN_0, HAS_AUTO_FAN_1, HAS_AUTO_FAN_2, HAS_AUTO_FAN_3, HAS_AUTO_FAN_4, HAS_AUTO_FAN_5, HAS_AUTO_FAN_6, HAS_AUTO_FAN_7, HAS_AUTO_CHAMBER_FAN, HAS_AUTO_COOLER_FAN)
#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
#define _FANOVERLAP(I,T) (T##_AUTO_FAN_PIN == E##I##_AUTO_FAN_PIN)
#if HAS_AUTO_CHAMBER_FAN
#define _CHFANOVERLAP(I) || _FANOVERLAP(I,CHAMBER)
#if (0 REPEAT(8, _CHFANOVERLAP))
#define AUTO_CHAMBER_IS_E 1
#endif
#undef _CHFANOVERLAP
#endif
#if HAS_AUTO_FAN && (0 REPEAT(8, _COFANOVERLAP))
#define AUTO_COOLER_IS_E 1
#if HAS_AUTO_COOLER_FAN
#define _COFANOVERLAP(I) || _FANOVERLAP(I,COOLER)
#if (0 REPEAT(8, _COFANOVERLAP))
#define AUTO_COOLER_IS_E 1
#endif
#undef _COFANOVERLAP
#endif
#undef _CHFANOVERLAP
#undef _COFANOVERLAP
#endif

// Fans check
Expand Down
23 changes: 12 additions & 11 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) {

#if HAS_AUTO_FAN

#define _EFANOVERLAP(A,B) _FANOVERLAP(E##A,B)
#define _EFANOVERLAP(I,N) ((I != N) && _FANOVERLAP(I,E##N))

#define _IS_FAN_PIN(I,P) || (P == FAN##I##_PIN)
#if EXTRUDER_AUTO_FAN_SPEED != 255
Expand All @@ -1220,7 +1220,7 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) {
#endif

void Temperature::update_autofans() {
#define _EFAN(B,A) _EFANOVERLAP(A,B) ? B :
#define _EFAN(I,N) _EFANOVERLAP(I,N) ? I :
static const uint8_t fanBit[] PROGMEM = {
0
#if HAS_MULTI_HOTEND
Expand All @@ -1229,13 +1229,13 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) {
#endif
#define _NFAN HOTENDS
#if HAS_AUTO_CHAMBER_FAN
#define _CHFAN(B) _FANOVERLAP(CHAMBER,B) ? B :
#define _CHFAN(I) _FANOVERLAP(I,CHAMBER) ? I :
, (REPEAT(HOTENDS,_CHFAN) (_NFAN))
#undef _NFAN
#define _NFAN INCREMENT(HOTENDS)
#endif
#if HAS_AUTO_COOLER_FAN
#define _COFAN(B) _FANOVERLAP(COOLER,B) ? B :
#define _COFAN(I) _FANOVERLAP(I,COOLER) ? I :
, (REPEAT(HOTENDS,_COFAN) (_NFAN))
#endif
};
Expand Down Expand Up @@ -2736,28 +2736,29 @@ void Temperature::init() {
ENABLE_TEMPERATURE_INTERRUPT();

#if HAS_AUTO_FAN
#define _OREFAN(I,N) || _EFANOVERLAP(I,N)
#if HAS_AUTO_FAN_0
INIT_E_AUTO_FAN_PIN(E0_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_FAN_1 && !_EFANOVERLAP(1,0)
#if HAS_AUTO_FAN_1 && !_EFANOVERLAP(0,1)
INIT_E_AUTO_FAN_PIN(E1_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_FAN_2 && !(_EFANOVERLAP(2,0) || _EFANOVERLAP(2,1))
#if HAS_AUTO_FAN_2 && !(0 REPEAT2(2, _OREFAN, 2))
INIT_E_AUTO_FAN_PIN(E2_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_FAN_3 && !(_EFANOVERLAP(3,0) || _EFANOVERLAP(3,1) || _EFANOVERLAP(3,2))
#if HAS_AUTO_FAN_3 && !(0 REPEAT2(3, _OREFAN, 3))
INIT_E_AUTO_FAN_PIN(E3_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_FAN_4 && !(_EFANOVERLAP(4,0) || _EFANOVERLAP(4,1) || _EFANOVERLAP(4,2) || _EFANOVERLAP(4,3))
#if HAS_AUTO_FAN_4 && !(0 REPEAT2(4, _OREFAN, 4))
INIT_E_AUTO_FAN_PIN(E4_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_FAN_5 && !(_EFANOVERLAP(5,0) || _EFANOVERLAP(5,1) || _EFANOVERLAP(5,2) || _EFANOVERLAP(5,3) || _EFANOVERLAP(5,4))
#if HAS_AUTO_FAN_5 && !(0 REPEAT2(5, _OREFAN, 5))
INIT_E_AUTO_FAN_PIN(E5_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_FAN_6 && !(_EFANOVERLAP(6,0) || _EFANOVERLAP(6,1) || _EFANOVERLAP(6,2) || _EFANOVERLAP(6,3) || _EFANOVERLAP(6,4) || _EFANOVERLAP(6,5))
#if HAS_AUTO_FAN_6 && !(0 REPEAT2(6, _OREFAN, 6))
INIT_E_AUTO_FAN_PIN(E6_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_FAN_7 && !(_EFANOVERLAP(7,0) || _EFANOVERLAP(7,1) || _EFANOVERLAP(7,2) || _EFANOVERLAP(7,3) || _EFANOVERLAP(7,4) || _EFANOVERLAP(7,5) || _EFANOVERLAP(7,6))
#if HAS_AUTO_FAN_7 && !(0 REPEAT2(7, _OREFAN, 7))
INIT_E_AUTO_FAN_PIN(E7_AUTO_FAN_PIN);
#endif
#if HAS_AUTO_CHAMBER_FAN && !AUTO_CHAMBER_IS_E
Expand Down

0 comments on commit 9ba7b7a

Please sign in to comment.