timemanager fixes #2
This commit is contained in:
parent
0c1c95d868
commit
8c93f44c84
@ -114,7 +114,7 @@ extern SemaphoreHandle_t I2Caccess, TimePulse;
|
|||||||
extern TaskHandle_t irqHandlerTask, ClockTask;
|
extern TaskHandle_t irqHandlerTask, ClockTask;
|
||||||
extern TimerHandle_t WifiChanTimer;
|
extern TimerHandle_t WifiChanTimer;
|
||||||
extern Timezone myTZ;
|
extern Timezone myTZ;
|
||||||
extern time_t LastSyncTime;
|
extern time_t LastSyncTime, userUTCTime;
|
||||||
|
|
||||||
// application includes
|
// application includes
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = "main";
|
static const char TAG[] = "main";
|
||||||
|
|
||||||
time_t userUTCTime; // Seconds since the UTC in seconds GPS time starting 1.1.2000
|
|
||||||
|
|
||||||
// do all housekeeping
|
// do all housekeeping
|
||||||
void doHousekeeping() {
|
void doHousekeeping() {
|
||||||
|
|
||||||
|
@ -41,16 +41,6 @@ const char lora_datarate[] = {"1211100908078CNA1211109C8C7C"};
|
|||||||
const char lora_datarate[] = {"121110090807FSNA"};
|
const char lora_datarate[] = {"121110090807FSNA"};
|
||||||
#endif
|
#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
|
// helper arry for converting month values to text
|
||||||
const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||||
@ -139,8 +129,18 @@ void init_display(const char *Productname, const char *Version) {
|
|||||||
|
|
||||||
void refreshtheDisplay() {
|
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;
|
uint8_t msgWaiting;
|
||||||
char timePulse, timeState;
|
char timeIsSet, timeState;
|
||||||
char buff[16]; // 16 chars line buffer
|
char buff[16]; // 16 chars line buffer
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
@ -227,8 +227,9 @@ void refreshtheDisplay() {
|
|||||||
u8x8.printf("%-16s", display_line6);
|
u8x8.printf("%-16s", display_line6);
|
||||||
#else // we want a systime display instead LoRa status
|
#else // we want a systime display instead LoRa status
|
||||||
t = myTZ.toLocal(now());
|
t = myTZ.toLocal(now());
|
||||||
timePulse = TimeIsSynced ? timePulseSymbol : timeNoPulseSymbol;
|
timeIsSet =
|
||||||
timeState = TimePulseTick ? timePulse : ' ';
|
(timeStatus() == timeNotSet) ? timeNotSetSymbol : timeIsSetSymbol;
|
||||||
|
timeState = TimePulseTick ? ' ' : timeIsSet;
|
||||||
TimePulseTick = false;
|
TimePulseTick = false;
|
||||||
u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t),
|
u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t),
|
||||||
timeState, day(t), printmonth[month(t)]);
|
timeState, day(t), printmonth[month(t)]);
|
||||||
|
@ -72,7 +72,7 @@ TaskHandle_t irqHandlerTask, ClockTask;
|
|||||||
SemaphoreHandle_t I2Caccess, TimePulse;
|
SemaphoreHandle_t I2Caccess, TimePulse;
|
||||||
bool volatile TimePulseTick = false;
|
bool volatile TimePulseTick = false;
|
||||||
bool TimeIsSynced = 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,
|
// container holding unique MAC address hashes with Memory Alloctor using PSRAM,
|
||||||
// if present
|
// if present
|
||||||
|
@ -11,16 +11,16 @@ void time_sync() {
|
|||||||
|
|
||||||
time_t lastTimeSync = now() - LastSyncTime; // check if a sync is due
|
time_t lastTimeSync = now() - LastSyncTime; // check if a sync is due
|
||||||
|
|
||||||
if ((lastTimeSync >= (TIME_SYNC_INTERVAL * 60000)) || !LastSyncTime)
|
if ((lastTimeSync >= (TIME_SYNC_INTERVAL * 60000)) || !LastSyncTime) {
|
||||||
// is it time to sync with external source?
|
// is it time to sync with external source?
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
syncTime(get_gpstime()); // attempt sync with GPS time
|
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
|
#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
|
#ifdef HAS_RTC
|
||||||
if (TimeIsSynced) { // recalibrate RTC, if we have one
|
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,
|
time_t tmConvert_t(uint16_t YYYY, uint8_t MM, uint8_t DD, uint8_t hh,
|
||||||
uint8_t mm, uint8_t ss) {
|
uint8_t mm, uint8_t ss) {
|
||||||
tmElements_t tm;
|
tmElements_t tm;
|
||||||
tm.Year =
|
tm.Year = CalendarYrToTm(YYYY); // year offset from 1970 in time.h
|
||||||
CalendarYrToTm(YYYY); // year offset from 1970 in time.h
|
|
||||||
tm.Month = MM;
|
tm.Month = MM;
|
||||||
tm.Day = DD;
|
tm.Day = DD;
|
||||||
tm.Hour = hh;
|
tm.Hour = hh;
|
||||||
|
Loading…
Reference in New Issue
Block a user