EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
Timer Class Reference

Overview

A wrapper class for the EtcPal timer type.

See the description for timer (Timers) for details about the time points and intervals used by this class.

Use this class to time an interval.

etcpal::Timer timer(100); // Start a 100-millisecond timer.
// Some time later...
uint32_t elapsed = timer.GetElapsed(); // How many milliseconds since the timer was started
uint32_t remaining = timer.GetRemaining(); // How much time is remaining in the interval.
bool is_expired = timer.IsExpired(); // Whether the interval has expired
timer.Reset(); // Reset the timer for another 100-millisecond interval
// Or
timer.Start(1000); // Reuse the timer for a different interval, in this case 1 second.
A wrapper class for the EtcPal timer type.
Definition: timer.h:208

Public Member Functions

 Timer ()=default
 Creates an expired timer with an interval of 0.
 
constexpr Timer (const EtcPalTimer &c_timer) noexcept
 Construct a timer copied from an instance of the C EtcPalTimer type.
 
Timeroperator= (const EtcPalTimer &c_timer) noexcept
 Assign an instance of the C EtcPalTimer type to an instance of this class.
 
 Timer (uint32_t interval) noexcept
 Create and start a timer with the given interval in milliseconds.
 
template<typename Rep , typename Period >
 Timer (const std::chrono::duration< Rep, Period > &interval) noexcept
 Create and start a timer with the given interval. More...
 
constexpr const EtcPalTimerget () const noexcept
 Get a const reference to the underlying C type.
 
ETCPAL_CONSTEXPR_14 EtcPalTimerget () noexcept
 Get a mutable reference to the underlying C type.
 
TimePoint GetStartTime () const noexcept
 Get the time when this timer was started or reset.
 
uint32_t GetInterval () const noexcept
 Get the current interval being timed by the timer.
 
uint32_t GetElapsed () const noexcept
 Get the time since the timer was reset.
 
uint32_t GetRemaining () const noexcept
 Get the amount of time remaining in the timer's interval (returns 0 if the timer is expired).
 
bool IsExpired () const noexcept
 Whether the timer's interval is expired.
 
void Start (uint32_t interval) noexcept
 Start the timer with a new interval. More...
 
template<typename Rep , typename Period >
void Start (const std::chrono::duration< Rep, Period > &interval) noexcept
 Start the timer with a new interval. More...
 
void Reset () noexcept
 Reset the timer while keeping the same interval.
 

Constructor & Destructor Documentation

◆ Timer()

Timer ( const std::chrono::duration< Rep, Period > &  interval)
explicitnoexcept

Create and start a timer with the given interval.

Note: interval will be clamped to [0, UINT32_MAX] milliseconds.

Member Function Documentation

◆ Start() [1/2]

void Start ( const std::chrono::duration< Rep, Period > &  interval)
noexcept

Start the timer with a new interval.

Parameters
intervalInterval to time. Will be clamped to [0, UINT32_MAX] milliseconds. An interval of 0 will result in a timer that is always expired.

◆ Start() [2/2]

void Start ( uint32_t  interval)
inlinenoexcept

Start the timer with a new interval.

Parameters
intervalInterval to time, in milliseconds. An interval of 0 will result in a timer that is always expired.

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