EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
timer (Timers)

Overview

C++ utilities for the timer (Timers) module.

WARNING: This module must be explicitly initialized before use. Initialize the module by calling etcpal_init() with the relevant feature mask:

etcpal_error_t etcpal_init(etcpal_features_t features)
Initialize the EtcPal library.
Definition: common.c:112
#define ETCPAL_FEATURE_TIMERS
Use the etcpal/timer module.
Definition: common.h:139

NOTE: This module is intended to provide a platform-neutral time layer that is similar to the C++ standard library <chrono>. The advantage over <chrono> is that this module supports all EtcPal ports – including embedded RTOS platform with native tick counts.

Provides a class for representing points in time (TimePoint) and one which implements a passive monotonic timer (Timer).

Data Structures

class  TimePoint
 Represents a point in time. More...
 
class  Timer
 A wrapper class for the EtcPal timer type. More...
 

Functions

std::string DurationToString (int32_t duration_ms) noexcept
 Get a string represention of a millisecond duration. More...
 

TimePoint operators

constexpr int32_t operator- (const TimePoint &a, const TimePoint &b) noexcept
 
constexpr bool operator== (const TimePoint &a, const TimePoint &b) noexcept
 
constexpr bool operator!= (const TimePoint &a, const TimePoint &b) noexcept
 
constexpr bool operator< (const TimePoint &a, const TimePoint &b) noexcept
 
constexpr bool operator> (const TimePoint &a, const TimePoint &b) noexcept
 
constexpr bool operator<= (const TimePoint &a, const TimePoint &b) noexcept
 
constexpr bool operator>= (const TimePoint &a, const TimePoint &b) noexcept
 

Function Documentation

◆ DurationToString()

std::string etcpal::DurationToString ( int32_t  duration_ms)
inlinenoexcept

Get a string represention of a millisecond duration.

Parameters
duration_msThe millisecond duration (can be obtained by substracting two TimePoints, e.g. etcpal::TimePoint::Now() - tp).
Returns
A string representing the duration, in the format of "_ hr _ min _ sec _ ms" (with zeroes being omitted up to the first non-zero value or 0 ms).