Doxygen with github
Loading...
Searching...
No Matches
ksf::ksSimpleTimer Class Reference

Simple timer class, without using component architecture. More...

#include <ksSimpleTimer.h>

Public Member Functions

 ksSimpleTimer (uint32_t intervalMs)
 Constructs timer with interval (milliseconds).
 
void setInterval (uint32_t intervalMs)
 Sets timer interval (milliseconds) and restarts the timer.
 
void restart ()
 Restarts timer. Will set last trigger time to current time w/o triggering the timer).
 
bool triggered ()
 Checks if timer interval just passed and resets the timer in this case. If timer interval is 0 then always returns false.
 
bool hasTimePassed () const
 Checks if timer interval just passed. Restarting timer relies on user. If timer interval is 0 then always returns false.
 

Protected Attributes

uint32_t intervalMs {0}
 Timer interval (milliseconds).
 
uint32_t lastTriggerTimeMs {0}
 Last trigger time (milliseconds).
 

Detailed Description

Simple timer class, without using component architecture.

Used to trigger events periodically. Internally checks if timer interval just passed. When interval is 0, never triggers the timer.

There are two ways to use it:

Constructor & Destructor Documentation

◆ ksSimpleTimer()

ksf::ksSimpleTimer::ksSimpleTimer ( uint32_t intervalMs)

Constructs timer with interval (milliseconds).

Parameters
intervalMsInitial timer interval in milliseconds.

References intervalMs, and setInterval().

Member Function Documentation

◆ hasTimePassed()

bool ksf::ksSimpleTimer::hasTimePassed ( ) const

Checks if timer interval just passed. Restarting timer relies on user. If timer interval is 0 then always returns false.

Returns
True if timer interval just passed, otherwise false.

References intervalMs, and lastTriggerTimeMs.

Referenced by ksf::comps::ksMqttConnector::loop(), ksf::comps::ksWifiConnector::loop(), and triggered().

◆ setInterval()

void ksf::ksSimpleTimer::setInterval ( uint32_t intervalMs)

Sets timer interval (milliseconds) and restarts the timer.

Parameters
intervalMsTimer interval in milliseconds. If 0 then timer is disabled.

References intervalMs, and restart().

Referenced by ksSimpleTimer().

◆ triggered()

bool ksf::ksSimpleTimer::triggered ( )

Checks if timer interval just passed and resets the timer in this case. If timer interval is 0 then always returns false.

Returns
True if timer just triggered, otherwise false.

References hasTimePassed(), and restart().

Referenced by ksf::comps::ksDevStatMqttReporter::loop(), ksf::comps::ksWifiConfigurator::loop(), and ksf::comps::ksWifiConnector::loop().


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