FastLED 3.10.8
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) FL_NO_EXCEPT
48 : mStartTime(start_time), mDuration(duration) {}
49
54 bool done(u32 current_time) const FL_NO_EXCEPT {
55 u32 elapsed_time = current_time - mStartTime; // Rollover-safe
56 return elapsed_time >= mDuration;
57 }
58
62 u32 elapsed(u32 current_time) const FL_NO_EXCEPT {
63 return current_time - mStartTime; // Rollover-safe
64 }
65
68 void reset(u32 start_time) FL_NO_EXCEPT {
69 mStartTime = start_time;
70 }
71
75 void reset(u32 start_time, u32 duration) FL_NO_EXCEPT {
76 mStartTime = start_time;
77 mDuration = duration;
78 }
79
80private:
83};
84
85} // namespace fl
u32 mStartTime
Start timestamp.
Definition timeout.h:81
bool done(u32 current_time) const FL_NO_EXCEPT
Check if the timeout has completed.
Definition timeout.h:54
u32 mDuration
Timeout duration.
Definition timeout.h:82
void reset(u32 start_time) FL_NO_EXCEPT
Reset the timeout to start counting from specified time.
Definition timeout.h:68
Timeout() FL_NO_EXCEPT
Default constructor - creates an already-expired timeout.
Definition timeout.h:42
Timeout(u32 start_time, u32 duration) FL_NO_EXCEPT
Construct a timeout with specified start time and duration.
Definition timeout.h:47
void reset(u32 start_time, u32 duration) FL_NO_EXCEPT
Reset with a new start time and duration.
Definition timeout.h:75
u32 elapsed(u32 current_time) const FL_NO_EXCEPT
Get elapsed time since timeout started.
Definition timeout.h:62
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179