Skip to content

Commit b664b1f

Browse files
committed
Add fallback for undefined FAN pin
1 parent d27f793 commit b664b1f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

esp32/src/fan.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Fan &Fan::Instance()
1515

1616
void Fan::setup(uint32_t frequency, float duty)
1717
{
18+
#ifdef APB_PWM_FAN_PIN
1819
pinMode(APB_PWM_FAN_PIN, OUTPUT);
1920
for(channel=0; channel < 16; ++channel) {
2021
if(ledcSetup(channel, frequency, 8) != 0) {
@@ -26,18 +27,27 @@ void Fan::setup(uint32_t frequency, float duty)
2627
}
2728
ledcAttachPin(APB_PWM_FAN_PIN, channel);
2829
setDuty(duty);
30+
#endif
2931
}
3032

3133
void Fan::setDuty(float duty) {
34+
#ifdef APB_PWM_FAN_PIN
3235
_duty = duty;
3336
int analogValue = static_cast<int>(duty * 255.0);
3437
Log.infoln(LOG_SCOPE "Setting fan duty to %F (analog value %d) to channel %d", duty, analogValue, channel);
3538
ledcWrite(channel, analogValue);
39+
#endif
3640
}
3741
float Fan::duty() const {
42+
#ifdef APB_PWM_FAN_PIN
3843
return _duty;
44+
#else
45+
return 0;
46+
#endif
3947
}
4048

4149
Fan::~Fan() {
50+
#ifdef APB_PWM_FAN_PIN
4251
ledcWrite(channel, 0);
43-
}
52+
#endif
53+
}

0 commit comments

Comments
 (0)