Skip to content

Commit

Permalink
Add pseudo-get delay function for scheduled functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dok-net committed Jul 19, 2023
1 parent f05cb54 commit cebad90
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cores/esp8266/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ uint32_t get_scheduled_recurrent_delay_us()
return (remaining > 0) ? static_cast<uint32_t>(remaining) : 0;
}

uint32_t get_scheduled_delay_us()
{
return sFirst ? 0 : ~static_cast<decltype(micros())>(0) >> 1;
}

void run_scheduled_functions()
{
// prevent scheduling of new functions during this run
Expand Down
7 changes: 7 additions & 0 deletions cores/esp8266/Schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(void)>& fn);

// Run all scheduled functions.
Expand Down
2 changes: 1 addition & 1 deletion libraries/SoftwareSerial

0 comments on commit cebad90

Please sign in to comment.