From cd4721f5aadfc3d8d3e234b5805c06af09f11bc3 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 1 Jan 2023 14:26:11 -0600 Subject: [PATCH] Re-base next run time to current in setInterval When reenabling a thread to run, it is desired to base the next run from the current time. For example: ```myThread.enabled = false; // idle the thread // do something else for a while myThread.enabled = true; myThread.setInteval(myThreadInterval); // reset the interval ``` --- Thread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Thread.cpp b/Thread.cpp index cd29d98..c72c391 100644 --- a/Thread.cpp +++ b/Thread.cpp @@ -27,8 +27,8 @@ void Thread::setInterval(unsigned long _interval){ // Save interval interval = _interval; - // Cache the next run based on the last_run - _cached_next_run = last_run + interval; + // Cache the next run re-based to the current time + _cached_next_run = millis() + interval; } bool Thread::shouldRun(unsigned long time){