FastLED 3.9.15
Loading...
Searching...
No Matches
timeout.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "fl/stl/stdint.h"
13#include "fl/stl/noexcept.h"
14
15namespace fl {
16
39class Timeout {
40public:
43
47 Timeout(u32 start_time, u32 duration)
48 : mStartTime(start_time), mDuration(duration) {}
49
54 bool done(u32 current_time) const {
55 u32 elapsed_time = current_time - mStartTime; // Rollover-safe
56 return elapsed_time >= mDuration;
57 }
58
62 u32 elapsed(u32 current_time) const {
63 return current_time - mStartTime; // Rollover-safe
64 }
65
68 void reset(u32 start_time) {
69 mStartTime = start_time;
70 }
71
75 void reset(u32 start_time, u32 duration) {
76 mStartTime = start_time;
77 mDuration = duration;
78 }
79
80private:
83};
84
85} // namespace fl
u32 mStartTime
Start timestamp.
Definition timeout.h:81
u32 elapsed(u32 current_time) const
Get elapsed time since timeout started.
Definition timeout.h:62
u32 mDuration
Timeout duration.
Definition timeout.h:82
bool done(u32 current_time) const
Check if the timeout has completed.
Definition timeout.h:54
void reset(u32 start_time)
Reset the timeout to start counting from specified time.
Definition timeout.h:68
Timeout(u32 start_time, u32 duration)
Construct a timeout with specified start time and duration.
Definition timeout.h:47
void reset(u32 start_time, u32 duration)
Reset with a new start time and duration.
Definition timeout.h:75
Timeout() FL_NOEXCEPT
Default constructor - creates an already-expired timeout.
Definition timeout.h:42
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT