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
RpmMonitor Class Reference

Measures fan speed from tachometer pulses. More...

#include <rpm_monitor.h>

Public Member Functions

 RpmMonitor (const RpmMonitorConfig &config=kDefaultRpmMonitorConfig)
 Creates an RPM monitor with the supplied tachometer configuration.
 
bool begin ()
 Initializes the tachometer pin and attaches the interrupt handler.
 
void update (uint32_t nowMs)
 Updates the measured RPM after the configured sample window elapses.
 
uint16_t rpm () const
 Returns the most recently calculated fan speed.
 
uint32_t pulseCount () const
 Returns the number of pulses accumulated in the current sample.
 
uint32_t sampleAgeMs (uint32_t nowMs) const
 Calculates the age of the current RPM sample.
 

Detailed Description

Measures fan speed from tachometer pulses.

The monitor attaches an interrupt to the tachometer pin, counts falling edges, and converts each completed sample window to revolutions per minute. Only one active instance is supported because the interrupt trampoline is shared.

RPM is rounded to the nearest integer over the elapsed sample window. Reading and clearing the volatile pulse counter is protected by temporarily disabling interrupts, keeping the ISR simple and the sampling result consistent.

Constructor & Destructor Documentation

◆ RpmMonitor()

RpmMonitor::RpmMonitor ( const RpmMonitorConfig config = kDefaultRpmMonitorConfig)
explicit

Creates an RPM monitor with the supplied tachometer configuration.

Parameters
configTachometer pin, pulses-per-revolution, and sample window.

Member Function Documentation

◆ begin()

bool RpmMonitor::begin ( )

Initializes the tachometer pin and attaches the interrupt handler.

Returns
True when initialization completed.

◆ pulseCount()

uint32_t RpmMonitor::pulseCount ( ) const

Returns the number of pulses accumulated in the current sample.

Returns
Unsampled tachometer pulse count since the last RPM calculation.

◆ rpm()

uint16_t RpmMonitor::rpm ( ) const

Returns the most recently calculated fan speed.

Returns
Last measured RPM, rounded to the nearest integer.

◆ sampleAgeMs()

uint32_t RpmMonitor::sampleAgeMs ( uint32_t  nowMs) const

Calculates the age of the current RPM sample.

Parameters
nowMsCurrent monotonic timestamp in milliseconds.
Returns
Elapsed milliseconds since the last completed sample.

◆ update()

void RpmMonitor::update ( uint32_t  nowMs)

Updates the measured RPM after the configured sample window elapses.

Call this regularly from the main loop with the current millis() value.

Parameters
nowMsCurrent monotonic timestamp in milliseconds.

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