FastLED 3.9.15
Loading...
Searching...
No Matches

◆ time()

fl::u32 fl::time ( )

Universal millisecond timer - returns milliseconds since system startup.

This function provides consistent timing across all FastLED platforms:

  • Arduino/AVR: Hardware timer-based millis()
  • ESP32/ESP8266: ESP-IDF timing functions
  • ARM: Platform-specific ARM timers
  • WASM: JavaScript-based timing
  • Native/Testing: std::chrono implementation
  • Stub: Fake timer for testing
Returns
Number of milliseconds since the system started
Note
Wraps around approximately every 49.7 days (2^32 milliseconds)
This function is designed to be zero-overhead - it compiles to a direct platform call in optimized builds

Behavior

  • Consistent: All platforms return milliseconds since startup/initialization
  • Monotonic: Time always increases (except on wraparound)
  • Resolution: 1 millisecond resolution on all platforms
  • Wraparound: Consistent wraparound behavior at 2^32 milliseconds

Usage

// Basic timing
fl::u32 start = fl::time();
do_work();
fl::u32 elapsed = fl::time() - start;
// Animation timing
static fl::u32 last_frame = 0;
fl::u32 now = fl::time();
if (now - last_frame >= 16) { // 60 FPS
render_frame();
last_frame = now;
}
// Timeout handling
fl::u32 timeout = fl::time() + 5000; // 5 second timeout
while (fl::time() < timeout && !is_complete()) {
process_step();
}
fl::u32 time()
Universal millisecond timer - returns milliseconds since system startup.
Definition time.cpp:136

Definition at line 136 of file time.cpp.

136 {
137#ifdef FASTLED_TESTING
138 // Check for injected time provider first
139 {
140 fl::lock_guard<fl::mutex> lock(get_time_mutex());
141 const auto& provider = get_time_provider();
142 if (provider) {
143 return provider();
144 }
145 }
146#endif
147
148 // Use platform-specific implementation
149 return get_platform_time();
150}
fl::u32 get_platform_time()
Get platform-specific time in milliseconds This function contains all platform-specific timing code.
Definition time.cpp:98

References time().

Referenced by fl::HashMapLru< Key, T, Hash, KeyEqual, INLINED_COUNT >::ValueWithTimestamp::ValueWithTimestamp(), drawPlasmaWave(), fl::task::operator=(), rainbowWave(), fl::task::set_last_run_time(), fl::TaskImpl::set_last_run_time(), time(), fl::Scheduler::update(), and fl::Scheduler::update_tasks_of_type().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: