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

A simple timer class that does not rely on component architecture. More...

#include <ksSimpleTimer.h>

Public Member Functions

 ksSimpleTimer (uint32_t intervalMs)
 Constructs timer with interval (milliseconds).
 
virtual ~ksSimpleTimer ()
 Destructs timer.
 
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

A simple timer class that does not rely on component architecture.

Used to trigger events periodically by internally checking if the timer interval has passed. If the interval is set to 0, the timer will never trigger.

There are two ways to use this timer:

  • By using the ksSimpleTimer::triggered() method, which returns true if the timer interval has just passed and updates the last trigger time.
  • By using the ksSimpleTimer::hasTimePassed() method, which returns true if the timer interval has just passed without updating the last trigger time.

Constructor & Destructor Documentation

◆ ksSimpleTimer()

ksf::misc::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::misc::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::misc::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::misc::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: