Skip to content

sntp callback: use a recurrent schedule function #6888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cores/esp8266/Schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void run_scheduled_functions();

// recurrent scheduled function:
//
// * Internal queue may not be a FIFO.
// * Internal queue is a FIFO.
// * Run the lambda periodically about every <repeat_us> microseconds until
// it returns false.
// * Note that it may be more than <repeat_us> microseconds between calls if
Expand All @@ -60,6 +60,7 @@ void run_scheduled_functions();
// recurrent function.
// * If alarm is used, anytime during scheduling when it returns true,
// any remaining delay from repeat_us is disregarded, and fn is executed.

bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
uint32_t repeat_us, const std::function<bool(void)>& alarm = nullptr);

Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/sntp-lwip2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,15 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz)
// apparently tz->tz_dsttime is a bitfield and should not be further used (cf man)
sntp_set_daylight(0);
}
if (tv) /* after*/
if (tv) /*after*/
{
// reset time subsystem
tune_timeshift64(tv->tv_sec * 1000000ULL + tv->tv_usec);

sntp_set_system_time(tv->tv_sec);

if (_settimeofday_cb)
schedule_function(_settimeofday_cb);
schedule_recurrent_function_us([](){ _settimeofday_cb(); return false; }, 0);
}
return 0;
}
Expand Down