From 72a4dde64f748a40601daeb0f5fc73e9c747b4ae Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 10 Dec 2019 11:41:42 +0100 Subject: [PATCH] sntp callback: use a recurrent schedule function (#6888) --- cores/esp8266/Schedule.h | 3 ++- cores/esp8266/sntp-lwip2.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/Schedule.h b/cores/esp8266/Schedule.h index a02241fa6..d33a7c08b 100644 --- a/cores/esp8266/Schedule.h +++ b/cores/esp8266/Schedule.h @@ -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 microseconds until // it returns false. // * Note that it may be more than microseconds between calls if @@ -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& fn, uint32_t repeat_us, const std::function& alarm = nullptr); diff --git a/cores/esp8266/sntp-lwip2.cpp b/cores/esp8266/sntp-lwip2.cpp index b046a1990..9750a40da 100644 --- a/cores/esp8266/sntp-lwip2.cpp +++ b/cores/esp8266/sntp-lwip2.cpp @@ -455,7 +455,7 @@ 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); @@ -463,7 +463,7 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz) 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; }