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 2eb420b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 46 deletions.
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
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 2eb420b

Please sign in to comment.