Simplified fan handling code

This commit is contained in:
Scott Lahteine
2019-06-28 17:03:43 -05:00
parent a8d68b7c8a
commit 4d5a1984e2
6 changed files with 61 additions and 91 deletions

View File

@ -2392,8 +2392,9 @@ void Temperature::isr() {
#if ENABLED(FAN_SOFT_PWM)
#define _FAN_PWM(N) do{ \
soft_pwm_count_fan[N] = (soft_pwm_count_fan[N] & pwm_mask) + (soft_pwm_amount_fan[N] >> 1); \
WRITE_FAN_N(N, soft_pwm_count_fan[N] > pwm_mask ? HIGH : LOW); \
uint8_t &spcf = soft_pwm_count_fan[N]; \
spcf = (spcf & pwm_mask) + (soft_pwm_amount_fan[N] >> 1); \
WRITE_FAN(N, spcf > pwm_mask ? HIGH : LOW); \
}while(0)
#if HAS_FAN0
_FAN_PWM(0);
@ -2438,13 +2439,13 @@ void Temperature::isr() {
#if ENABLED(FAN_SOFT_PWM)
#if HAS_FAN0
if (soft_pwm_count_fan[0] <= pwm_count_tmp) WRITE_FAN(LOW);
if (soft_pwm_count_fan[0] <= pwm_count_tmp) WRITE_FAN(0, LOW);
#endif
#if HAS_FAN1
if (soft_pwm_count_fan[1] <= pwm_count_tmp) WRITE_FAN1(LOW);
if (soft_pwm_count_fan[1] <= pwm_count_tmp) WRITE_FAN(1, LOW);
#endif
#if HAS_FAN2
if (soft_pwm_count_fan[2] <= pwm_count_tmp) WRITE_FAN2(LOW);
if (soft_pwm_count_fan[2] <= pwm_count_tmp) WRITE_FAN(2, LOW);
#endif
#endif
}
@ -2525,28 +2526,28 @@ void Temperature::isr() {
#if ENABLED(FAN_SOFT_PWM)
if (pwm_count_tmp >= 127) {
pwm_count_tmp = 0;
#define _PWM_FAN(N,I) do{ \
soft_pwm_count_fan[I] = soft_pwm_amount_fan[I] >> 1; \
WRITE_FAN##N(soft_pwm_count_fan[I] > 0 ? HIGH : LOW); \
#define _PWM_FAN(N) do{ \
soft_pwm_count_fan[N] = soft_pwm_amount_fan[N] >> 1; \
WRITE_FAN(N, soft_pwm_count_fan[N] > 0 ? HIGH : LOW); \
}while(0)
#if HAS_FAN0
_PWM_FAN(,0);
_PWM_FAN(0);
#endif
#if HAS_FAN1
_PWM_FAN(1,1);
_PWM_FAN(1);
#endif
#if HAS_FAN2
_PWM_FAN(2,2);
_PWM_FAN(2);
#endif
}
#if HAS_FAN0
if (soft_pwm_count_fan[0] <= pwm_count_tmp) WRITE_FAN(LOW);
if (soft_pwm_count_fan[0] <= pwm_count_tmp) WRITE_FAN(0, LOW);
#endif
#if HAS_FAN1
if (soft_pwm_count_fan[1] <= pwm_count_tmp) WRITE_FAN1(LOW);
if (soft_pwm_count_fan[1] <= pwm_count_tmp) WRITE_FAN(1, LOW);
#endif
#if HAS_FAN2
if (soft_pwm_count_fan[2] <= pwm_count_tmp) WRITE_FAN2(LOW);
if (soft_pwm_count_fan[2] <= pwm_count_tmp) WRITE_FAN(2, LOW);
#endif
#endif // FAN_SOFT_PWM