From 84f4b73b4d9b2a929aa59d25fc4e6940abbd5ffa Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Sun, 2 Jul 2023 09:28:56 +0200 Subject: [PATCH] Add pseudo-get delay function for scheduled functions --- cores/esp8266/Schedule.cpp | 5 +++++ cores/esp8266/Schedule.h | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/cores/esp8266/Schedule.cpp b/cores/esp8266/Schedule.cpp index 64d9767fd1..2652051a30 100644 --- a/cores/esp8266/Schedule.cpp +++ b/cores/esp8266/Schedule.cpp @@ -149,6 +149,11 @@ uint32_t get_scheduled_recurrent_delay_us() return (remaining > 0) ? static_cast(remaining) : 0; } +uint32_t get_scheduled_delay_us() +{ + return sFirst ? 0 : ~static_cast(0) >> 1; +} + void run_scheduled_functions() { // prevent scheduling of new functions during this run diff --git a/cores/esp8266/Schedule.h b/cores/esp8266/Schedule.h index 7105212bf3..56333d08e2 100644 --- a/cores/esp8266/Schedule.h +++ b/cores/esp8266/Schedule.h @@ -60,6 +60,13 @@ uint32_t get_scheduled_recurrent_delay_us(); // * Run the lambda only once next time. // * A scheduled function can schedule a function. +// get_scheduled_delay_us() is named for symmetry to get_scheduled_recurrent_delay_us, +// despite the lack of specific delay times. Therefore it can return only one of two +// values, viz. 0 in case of any pending scheduled functions, or a large delay time if +// there is no function in the queue. + +uint32_t get_scheduled_delay_us(); + bool schedule_function (const std::function& fn); // Run all scheduled functions.