23 #ifndef ETCPAL_CPP_TIMER_H_
24 #define ETCPAL_CPP_TIMER_H_
29 #include "etcpal/timer.h"
112 constexpr uint32_t
value() const noexcept;
183 explicit Timer(uint32_t interval) noexcept;
184 template <
typename Rep,
typename Period>
185 explicit Timer(
const std::chrono::duration<Rep, Period>& interval) noexcept;
196 void Start(uint32_t interval) noexcept;
197 template <typename Rep, typename Period>
198 void Start(const std::chrono::duration<Rep, Period>& interval) noexcept;
199 void Reset() noexcept;
226 template <
typename Rep,
typename Period>
227 Timer::Timer(
const std::chrono::duration<Rep, Period>& interval) noexcept
285 template <
typename Rep,
typename Period>
286 void Timer::Start(
const std::chrono::duration<Rep, Period>& interval) noexcept
288 uint32_t interval_clamped =
static_cast<uint32_t
>(
289 std::min(std::chrono::milliseconds(interval).count(),
290 static_cast<std::chrono::milliseconds::rep
>(std::numeric_limits<uint32_t>::max())));
308 return static_cast<int32_t
>(a.value() - b.value());
311 constexpr
bool operator==(
const TimePoint& a,
const TimePoint& b) noexcept
313 return (a.value() == b.value());
316 constexpr
bool operator!=(
const TimePoint& a,
const TimePoint& b) noexcept
321 constexpr
bool operator<(
const TimePoint& a,
const TimePoint& b) noexcept
326 constexpr
bool operator>(
const TimePoint& a,
const TimePoint& b) noexcept
331 constexpr
bool operator<=(
const TimePoint& a,
const TimePoint& b) noexcept
336 constexpr
bool operator>=(
const TimePoint& a,
const TimePoint& b) noexcept
Represents a point in time.
Definition: timer.h:102
ETCPAL_CONSTEXPR_14 TimePoint & operator-=(uint32_t duration) noexcept
Subtract a millisecond duration from a TimePoint.
Definition: timer.h:142
constexpr uint32_t value() const noexcept
Get the raw millisecond value from a TimePoint.
Definition: timer.h:129
ETCPAL_CONSTEXPR_14 TimePoint & operator+=(uint32_t duration) noexcept
Add a millisecond duration to a TimePoint.
Definition: timer.h:135
TimePoint()=default
Construct a TimePoint with a value of 0 by default.
static TimePoint Now() noexcept
Get a TimePoint representing the current time.
Definition: timer.h:149
A wrapper class for the EtcPal timer type.
Definition: timer.h:175
Timer()=default
Creates an expired timer with an interval of 0.
TimePoint GetStartTime() const noexcept
Get the time when this timer was started or reset.
Definition: timer.h:245
bool IsExpired() const noexcept
Whether the timer's interval is expired.
Definition: timer.h:269
Timer & operator=(const EtcPalTimer &c_timer) noexcept
Assign an instance of the C EtcPalTimer type to an instance of this class.
Definition: timer.h:211
void Reset() noexcept
Reset the timer while keeping the same interval.
Definition: timer.h:295
constexpr const EtcPalTimer & get() const noexcept
Get a const reference to the underlying C type.
Definition: timer.h:233
uint32_t GetElapsed() const noexcept
Get the time since the timer was reset.
Definition: timer.h:257
uint32_t GetInterval() const noexcept
Get the current interval being timed by the timer.
Definition: timer.h:251
void Start(uint32_t interval) noexcept
Start the timer with a new interval.
Definition: timer.h:277
uint32_t GetRemaining() const noexcept
Get the amount of time remaining in the timer's interval (returns 0 if the timer is expired).
Definition: timer.h:263
Common definitions used by EtcPal C++ wrappers.
#define ETCPAL_CONSTEXPR_14
Stand-in for "constexpr" on entities that can only be defined "constexpr" in C++14 or later.
Definition: common.h:53
#define ETCPAL_CONSTEXPR_14_OR_INLINE
Defined to "constexpr" in C++14 or later, "inline" earlier.
Definition: common.h:54
uint32_t etcpal_timer_elapsed(const EtcPalTimer *timer)
Get the time since a timer was reset.
Definition: timer.c:56
void etcpal_timer_start(EtcPalTimer *timer, uint32_t interval)
Start a timer.
Definition: timer.c:30
uint32_t etcpal_timer_remaining(const EtcPalTimer *timer)
Get the amount of time remaining in a timer.
Definition: timer.c:87
bool etcpal_timer_is_expired(const EtcPalTimer *timer)
Check to see if a timer is expired.
Definition: timer.c:73
uint32_t etcpal_getms(void)
Get a monotonically-increasing millisecond value.
void etcpal_timer_reset(EtcPalTimer *timer)
Reset a timer while keeping the same interval.
Definition: timer.c:43
A millisecond-resolution timer.
Definition: timer.h:102
uint32_t reset_time
The time at which this timer was reset.
Definition: timer.h:103
uint32_t interval
This timer's timeout interval.
Definition: timer.h:104