timemanager fixes #2

This commit is contained in:
Klaus K Wilting 2019-02-22 23:17:28 +01:00
parent 0c1c95d868
commit 8c93f44c84
5 changed files with 24 additions and 26 deletions

View File

@ -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"

View File

@ -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() {

View File

@ -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)]);

View File

@ -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

View File

@ -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;