Skip to content

Commit

Permalink
Merge pull request #531 from OpenEVSE/jeremypoulter/issue529
Browse files Browse the repository at this point in the history
No longer endlessly loop twhen switching from NTP -> Manual time
  • Loading branch information
glynhudson committed Jan 29, 2023
2 parents bb11105 + a72eaf1 commit 94d8b4b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/time_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ unsigned long TimeManager::loop(MicroTasks::WakeReason reason)

unsigned long ret = MicroTask.Infinate;

if(_nextCheckTime > 0)
if(config_sntp_enabled() &&
NULL != _timeHost &&
_nextCheckTime > 0)
{
int64_t delay = (int64_t)_nextCheckTime - (int64_t)millis();

if(config_sntp_enabled() &&
net_is_connected() &&
if(net_is_connected() &&
false == _fetchingTime &&
delay <= 0)
{
Expand All @@ -100,7 +101,7 @@ unsigned long TimeManager::loop(MicroTasks::WakeReason reason)
struct timeval utc_time;
gettimeofday(&utc_time, NULL);

if(utc_time.tv_usec >= 999500)
if(utc_time.tv_usec >= 999000)
{
_setTheTime = false;

Expand All @@ -119,7 +120,7 @@ unsigned long TimeManager::loop(MicroTasks::WakeReason reason)
{
unsigned long msec = utc_time.tv_usec / 1000;
DBUGVAR(msec);
unsigned long delay = msec < 999 ? 999 - msec : 0;
unsigned long delay = msec < 998 ? 998 - msec : 0;
DBUGVAR(delay);
if(delay < ret) {
ret = delay;
Expand Down

0 comments on commit 94d8b4b

Please sign in to comment.