Aquarium Cooling Controller
ESP32 firmware for aquarium cooling fan control, monitoring, telemetry, and fault handling.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FanDriver Class Reference

Drives the cooling fan with an ESP32 LEDC PWM output. More...

#include <fan_driver.h>

Public Member Functions

 FanDriver (const FanDriverConfig &config=kDefaultFanDriverConfig)
 Creates a fan driver using the supplied PWM configuration.
 
bool begin ()
 Attaches the PWM channel and initializes the fan output to off.
 
void setCommandedPwmPercent (uint8_t pwmPercent, uint32_t nowMs)
 Sets the desired fan PWM command.
 
void update (uint32_t nowMs)
 Ends the start boost when its configured duration has elapsed.
 
uint8_t commandedPwmPercent () const
 Returns the requested fan PWM command.
 
uint8_t appliedPwmPercent () const
 Returns the PWM value currently applied to the hardware.
 
bool isStartBoostActive () const
 Indicates whether the temporary fan start boost is active.
 

Detailed Description

Drives the cooling fan with an ESP32 LEDC PWM output.

Commands are expressed in percent so the rest of the controller does not need to know the PWM resolution. The class also keeps the last commanded value separate from the applied value because start boost can temporarily apply a higher PWM than the steady-state command.

Constructor & Destructor Documentation

◆ FanDriver()

FanDriver::FanDriver ( const FanDriverConfig config = kDefaultFanDriverConfig)
explicit

Creates a fan driver using the supplied PWM configuration.

Parameters
configFan PWM pin, frequency, resolution, and start-boost settings.

Member Function Documentation

◆ appliedPwmPercent()

uint8_t FanDriver::appliedPwmPercent ( ) const

Returns the PWM value currently applied to the hardware.

Returns
Applied PWM percentage from 0 to 100.

◆ begin()

bool FanDriver::begin ( )

Attaches the PWM channel and initializes the fan output to off.

Returns
True when ESP32 LEDC setup succeeded.

◆ commandedPwmPercent()

uint8_t FanDriver::commandedPwmPercent ( ) const

Returns the requested fan PWM command.

Returns
Commanded PWM percentage from 0 to 100.

◆ isStartBoostActive()

bool FanDriver::isStartBoostActive ( ) const

Indicates whether the temporary fan start boost is active.

Returns
True while the boost PWM is being applied.

◆ setCommandedPwmPercent()

void FanDriver::setCommandedPwmPercent ( uint8_t  pwmPercent,
uint32_t  nowMs 
)

Sets the desired fan PWM command.

A start boost is applied automatically when a stopped fan is commanded to a low nonzero PWM value. Commands are clamped to the 0 to 100 percent range before they are stored or written to the hardware.

Parameters
pwmPercentDesired fan command from 0 to 100 percent.
nowMsCurrent monotonic timestamp in milliseconds.

◆ update()

void FanDriver::update ( uint32_t  nowMs)

Ends the start boost when its configured duration has elapsed.

Parameters
nowMsCurrent monotonic timestamp in milliseconds.

The documentation for this class was generated from the following files: