Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 538025a

Browse filesBrowse files
committed
Simplified roll-over logic
1 parent 717f4ad commit 538025a
Copy full SHA for 538025a

File tree

Expand file treeCollapse file tree

1 file changed

+7
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-6
lines changed

‎cores/esp8266/Schedule.cpp

Copy file name to clipboardExpand all lines: cores/esp8266/Schedule.cpp
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
126126
// prevent new item overwriting an already expired rTarget.
127127
const auto now = micros();
128128
const auto itemRemaining = item->callNow.remaining();
129-
const int32_t remaining = rTarget - now;
130-
if (!rFirst || (remaining > 0 && static_cast<decltype(micros())>(remaining) > itemRemaining))
129+
const auto remaining = rTarget - now;
130+
if (!rFirst || (remaining <= HALF_MAX_MICROS && remaining > itemRemaining))
131131
{
132132
rTarget = now + itemRemaining;
133133
}
@@ -149,8 +149,9 @@ decltype(micros()) get_scheduled_recurrent_delay_us()
149149
{
150150
if (!rFirst) return HALF_MAX_MICROS;
151151
// handle already expired rTarget.
152-
const int32_t remaining = rTarget - micros();
153-
return (remaining > 0) ? static_cast<decltype(micros())>(remaining) : 0;
152+
const auto now = micros();
153+
const auto remaining = rTarget - now;
154+
return (remaining <= HALF_MAX_MICROS) ? remaining : 0;
154155
}
155156

156157
decltype(micros()) get_scheduled_delay_us()
@@ -262,8 +263,8 @@ void run_scheduled_recurrent_functions()
262263
// prevent current item overwriting an already expired rTarget.
263264
const auto now = micros();
264265
const auto currentRemaining = current->callNow.remaining();
265-
const int32_t remaining = rTarget - now;
266-
if (remaining > 0 && static_cast<decltype(micros())>(remaining) > currentRemaining)
266+
const auto remaining = rTarget - now;
267+
if (remaining <= HALF_MAX_MICROS && remaining > currentRemaining)
267268
{
268269
rTarget = now + currentRemaining;
269270
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.