Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» Apply REPEAT to AUTO_FAN
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 23, 2023
1 parent 724ba4b commit 1a6e93f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 50 deletions.
15 changes: 11 additions & 4 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2562,12 +2562,19 @@
#define HAS_AUTO_COOLER_FAN 1
#endif

#define _FANOVERLAP(A,B) (A##_AUTO_FAN_PIN == E##B##_AUTO_FAN_PIN)
#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
#endif
#define _FANOVERLAP(A,B) (A##_AUTO_FAN_PIN == E##B##_AUTO_FAN_PIN)
#if HAS_AUTO_FAN && (_FANOVERLAP(CHAMBER,0) || _FANOVERLAP(CHAMBER,1) || _FANOVERLAP(CHAMBER,2) || _FANOVERLAP(CHAMBER,3) || _FANOVERLAP(CHAMBER,4) || _FANOVERLAP(CHAMBER,5) || _FANOVERLAP(CHAMBER,6) || _FANOVERLAP(CHAMBER,7))
#define AUTO_CHAMBER_IS_E 1
#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
Expand Down
21 changes: 3 additions & 18 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3039,24 +3039,9 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
* Auto Fan check for PWM pins
*/
#if HAS_AUTO_FAN && EXTRUDER_AUTO_FAN_SPEED != 255
#define AF_ERR_SUFF "_AUTO_FAN_PIN is not a PWM pin. Set EXTRUDER_AUTO_FAN_SPEED to 255."
#if HAS_AUTO_FAN_0
static_assert(_TEST_PWM(E0_AUTO_FAN_PIN), "E0" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_1
static_assert(_TEST_PWM(E1_AUTO_FAN_PIN), "E1" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_2
static_assert(_TEST_PWM(E2_AUTO_FAN_PIN), "E2" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_3
static_assert(_TEST_PWM(E3_AUTO_FAN_PIN), "E3" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_4
static_assert(_TEST_PWM(E4_AUTO_FAN_PIN), "E4" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_5
static_assert(_TEST_PWM(E5_AUTO_FAN_PIN), "E5" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_6
static_assert(_TEST_PWM(E6_AUTO_FAN_PIN), "E6" AF_ERR_SUFF);
#elif HAS_AUTO_FAN_7
static_assert(_TEST_PWM(E7_AUTO_FAN_PIN), "E7" AF_ERR_SUFF);
#endif
#define AF_ASSERT(N) OPTCODE(HAS_AUTO_FAN_##N, static_assert(_TEST_PWM(E##N##_AUTO_FAN_PIN), "E" #N# "_AUTO_FAN_PIN is not a PWM pin. Set EXTRUDER_AUTO_FAN_SPEED to 255."))
REPEAT(8, AF_ASSERT)
#undef AF_ASSERT
#endif

/**
Expand Down
43 changes: 15 additions & 28 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,17 +1221,23 @@ 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
};

uint8_t fanState = 0;
HOTEND_LOOP() {
if (temp_hotend[e].celsius >= EXTRUDER_AUTO_FAN_TEMPERATURE) {
if (temp_hotend[e].celsius >= EXTRUDER_AUTO_FAN_TEMPERATURE)
SBI(fanState, pgm_read_byte(&fanBit[e]));
}
}

#if HAS_AUTO_CHAMBER_FAN
Expand Down Expand Up @@ -1275,35 +1281,16 @@ int16_t Temperature::getHeaterPower(const heater_id_t heater_id) {
#define _AUTOFAN_SPEED() EXTRUDER_AUTO_FAN_SPEED
#endif
#define _AUTOFAN_CASE(N) case N: _UPDATE_AUTO_FAN(E##N, fan_on, _AUTOFAN_SPEED()); break
#define AUTOFAN_CASE(N) OPTCODE(HAS_AUTO_FAN_##N, _AUTOFAN_CASE(N))

switch (f) {
#if HAS_AUTO_FAN_0
_AUTOFAN_CASE(0);
#endif
#if HAS_AUTO_FAN_1
_AUTOFAN_CASE(1);
#endif
#if HAS_AUTO_FAN_2
_AUTOFAN_CASE(2);
#endif
#if HAS_AUTO_FAN_3
_AUTOFAN_CASE(3);
#endif
#if HAS_AUTO_FAN_4
_AUTOFAN_CASE(4);
#endif
#if HAS_AUTO_FAN_5
_AUTOFAN_CASE(5);
#endif
#if HAS_AUTO_FAN_6
_AUTOFAN_CASE(6);
#endif
#if HAS_AUTO_FAN_7
_AUTOFAN_CASE(7);
#endif
REPEAT(8, AUTOFAN_CASE)
#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);
}
Expand Down

0 comments on commit 1a6e93f

Please sign in to comment.