Aquarium Cooling Controller
ESP32 firmware for aquarium cooling fan control, monitoring, telemetry, and fault handling.
Loading...
Searching...
No Matches
fan_driver.h
Go to the documentation of this file.
1#pragma once
2
13#include <Arduino.h>
14
29
34 25,
35 25000,
36 8,
37 40,
38 2000,
39};
40
49class FanDriver {
50 public:
56 explicit FanDriver(const FanDriverConfig& config = kDefaultFanDriverConfig);
57
63 bool begin();
64
75 void setCommandedPwmPercent(uint8_t pwmPercent, uint32_t nowMs);
76
82 void update(uint32_t nowMs);
83
89 uint8_t commandedPwmPercent() const;
90
96 uint8_t appliedPwmPercent() const;
97
103 bool isStartBoostActive() const;
104
105 private:
111 void applyPwmPercent(uint8_t pwmPercent);
112
113 FanDriverConfig config_;
114 uint8_t commandedPwmPercent_;
115 uint8_t appliedPwmPercent_;
116 bool startBoostActive_;
117 uint32_t startBoostUntilMs_;
118 bool initialized_;
119};
Drives the cooling fan with an ESP32 LEDC PWM output.
Definition fan_driver.h:49
bool isStartBoostActive() const
Indicates whether the temporary fan start boost is active.
Definition fan_driver.cpp:76
uint8_t appliedPwmPercent() const
Returns the PWM value currently applied to the hardware.
Definition fan_driver.cpp:72
void setCommandedPwmPercent(uint8_t pwmPercent, uint32_t nowMs)
Sets the desired fan PWM command.
Definition fan_driver.cpp:27
uint8_t commandedPwmPercent() const
Returns the requested fan PWM command.
Definition fan_driver.cpp:68
void update(uint32_t nowMs)
Ends the start boost when its configured duration has elapsed.
Definition fan_driver.cpp:56
bool begin()
Attaches the PWM channel and initializes the fan output to off.
Definition fan_driver.cpp:16
constexpr FanDriverConfig kDefaultFanDriverConfig
Default PWM settings for the configured cooling fan.
Definition fan_driver.h:33
PWM output settings for the cooling fan.
Definition fan_driver.h:22
uint32_t pwmFrequencyHz
PWM carrier frequency in hertz.
Definition fan_driver.h:24
uint8_t pwmPin
GPIO used for fan PWM output.
Definition fan_driver.h:23
uint8_t pwmResolutionBits
PWM resolution passed to ledcAttach().
Definition fan_driver.h:25
uint32_t startBoostDurationMs
Duration of the start boost in milliseconds.
Definition fan_driver.h:27
uint8_t startBoostPwmPercent
Temporary PWM applied to start a stopped fan.
Definition fan_driver.h:26