From 8c93f44c847a6dbb96c593b2ea95c9718c5be76f Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Fri, 22 Feb 2019 23:17:28 +0100 Subject: [PATCH] timemanager fixes #2 --- include/globals.h | 2 +- src/cyclic.cpp | 2 -- src/display.cpp | 27 ++++++++++++++------------- src/main.cpp | 2 +- src/timemanager.cpp | 17 ++++++++--------- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/include/globals.h b/include/globals.h index a3f3bbea..ff3f2028 100644 --- a/include/globals.h +++ b/include/globals.h @@ -114,7 +114,7 @@ extern SemaphoreHandle_t I2Caccess, TimePulse; extern TaskHandle_t irqHandlerTask, ClockTask; extern TimerHandle_t WifiChanTimer; extern Timezone myTZ; -extern time_t LastSyncTime; +extern time_t LastSyncTime, userUTCTime; // application includes #include "led.h" diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 8393f2b9..021ea8d6 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -7,8 +7,6 @@ // Local logging tag static const char TAG[] = "main"; -time_t userUTCTime; // Seconds since the UTC in seconds GPS time starting 1.1.2000 - // do all housekeeping void doHousekeeping() { diff --git a/src/display.cpp b/src/display.cpp index 9c949e75..ef5fdecc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -41,16 +41,6 @@ const char lora_datarate[] = {"1211100908078CNA1211109C8C7C"}; const char lora_datarate[] = {"121110090807FSNA"}; #endif -// time display symbols -#if defined HAS_GPS || defined HAS_RTC -const char timeNoPulseSymbol = '?'; -#if defined HAS_IF482 -const char timePulseSymbol = '+'; -#elif defined HAS_DCF77 -const char timePulseSymbol = '*'; -#endif -#endif - // helper arry for converting month values to text const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -139,8 +129,18 @@ void init_display(const char *Productname, const char *Version) { void refreshtheDisplay() { + // time display symbols + const char timeNotSetSymbol = '?'; +#if defined HAS_IF482 + const char timeIsSetSymbol = '+'; +#elif defined HAS_DCF77 + const char timeIsSetSymbol = '*'; +#else + const char timeIsSetSymbol = '#'; +#endif + uint8_t msgWaiting; - char timePulse, timeState; + char timeIsSet, timeState; char buff[16]; // 16 chars line buffer time_t t; @@ -227,8 +227,9 @@ void refreshtheDisplay() { u8x8.printf("%-16s", display_line6); #else // we want a systime display instead LoRa status t = myTZ.toLocal(now()); - timePulse = TimeIsSynced ? timePulseSymbol : timeNoPulseSymbol; - timeState = TimePulseTick ? timePulse : ' '; + timeIsSet = + (timeStatus() == timeNotSet) ? timeNotSetSymbol : timeIsSetSymbol; + timeState = TimePulseTick ? ' ' : timeIsSet; TimePulseTick = false; u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t), timeState, day(t), printmonth[month(t)]); diff --git a/src/main.cpp b/src/main.cpp index 4211de6e..af783420 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,7 +72,7 @@ TaskHandle_t irqHandlerTask, ClockTask; SemaphoreHandle_t I2Caccess, TimePulse; bool volatile TimePulseTick = false; bool TimeIsSynced = false; -time_t LastSyncTime = 0; +time_t LastSyncTime = 0, userUTCTime = 0; // container holding unique MAC address hashes with Memory Alloctor using PSRAM, // if present diff --git a/src/timemanager.cpp b/src/timemanager.cpp index ee24c2c2..8d559c5b 100644 --- a/src/timemanager.cpp +++ b/src/timemanager.cpp @@ -11,16 +11,16 @@ void time_sync() { time_t lastTimeSync = now() - LastSyncTime; // check if a sync is due - if ((lastTimeSync >= (TIME_SYNC_INTERVAL * 60000)) || !LastSyncTime) - // is it time to sync with external source? + if ((lastTimeSync >= (TIME_SYNC_INTERVAL * 60000)) || !LastSyncTime) { + // is it time to sync with external source? #ifdef HAS_GPS syncTime(get_gpstime()); // attempt sync with GPS time -#elif defined HAS_LORA && defined TIME_SYNC_LORA - LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime); -#else - { - } // no time source -> no sync #endif +#if defined HAS_LORA && defined TIME_SYNC_LORA + if (!TimeIsSynced) // no GPS sync -> try lora sync + LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime); +#endif + } #ifdef HAS_RTC if (TimeIsSynced) { // recalibrate RTC, if we have one @@ -149,8 +149,7 @@ time_t compiledUTC(void) { time_t tmConvert_t(uint16_t YYYY, uint8_t MM, uint8_t DD, uint8_t hh, uint8_t mm, uint8_t ss) { tmElements_t tm; - tm.Year = - CalendarYrToTm(YYYY); // year offset from 1970 in time.h + tm.Year = CalendarYrToTm(YYYY); // year offset from 1970 in time.h tm.Month = MM; tm.Day = DD; tm.Hour = hh;