clock time handling improvements
This commit is contained in:
parent
bb187ef0bd
commit
1b42afafd7
@ -11,6 +11,5 @@
|
|||||||
|
|
||||||
void clock_init(void);
|
void clock_init(void);
|
||||||
void clock_loop(void *pvParameters);
|
void clock_loop(void *pvParameters);
|
||||||
time_t telegram_time(void);
|
|
||||||
|
|
||||||
#endif // _CLOCKCONTROLLER_H
|
#endif // _CLOCKCONTROLLER_H
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <U8x8lib.h>
|
#include <U8x8lib.h>
|
||||||
#include "cyclic.h"
|
#include "cyclic.h"
|
||||||
|
#include "rtctime.h"
|
||||||
|
|
||||||
extern uint8_t volatile DisplayState;
|
extern uint8_t volatile DisplayState;
|
||||||
extern HAS_DISPLAY u8x8;
|
extern HAS_DISPLAY u8x8;
|
||||||
|
@ -23,5 +23,6 @@ void timepulse_start(void);
|
|||||||
int sync_TimePulse(void);
|
int sync_TimePulse(void);
|
||||||
int sync_SysTime(time_t);
|
int sync_SysTime(time_t);
|
||||||
int sync_SysTime(uint32_t t);
|
int sync_SysTime(uint32_t t);
|
||||||
|
time_t best_time(void);
|
||||||
|
|
||||||
#endif // _RTCTIME_H
|
#endif // _RTCTIME_H
|
@ -40,7 +40,7 @@ void clock_loop(void *pvParameters) { // ClockTask
|
|||||||
|
|
||||||
// preload first DCF frame before start
|
// preload first DCF frame before start
|
||||||
#ifdef HAS_DCF77
|
#ifdef HAS_DCF77
|
||||||
DCF77_Frame(t1(telegram_time()));
|
DCF77_Frame(t1(best_time()));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// output time telegram for second following sec beginning with timepulse
|
// output time telegram for second following sec beginning with timepulse
|
||||||
@ -51,7 +51,7 @@ void clock_loop(void *pvParameters) { // ClockTask
|
|||||||
if (timeStatus() == timeNotSet) // do we have valid time?
|
if (timeStatus() == timeNotSet) // do we have valid time?
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
t = telegram_time(); // time to send to clock
|
t = best_time(); // time to send to clock
|
||||||
|
|
||||||
#if defined HAS_IF482
|
#if defined HAS_IF482
|
||||||
|
|
||||||
@ -71,24 +71,4 @@ void clock_loop(void *pvParameters) { // ClockTask
|
|||||||
} // for
|
} // for
|
||||||
} // clock_loop()
|
} // clock_loop()
|
||||||
|
|
||||||
// helper function to fetch current second from most precise time source
|
|
||||||
time_t telegram_time(void) {
|
|
||||||
time_t t;
|
|
||||||
|
|
||||||
#ifdef HAS_GPS // gps is our primary time source if present
|
|
||||||
t = get_gpstime();
|
|
||||||
if (t) // did we get a valid time?
|
|
||||||
return t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAS_RTC // rtc is our secondary time source if present
|
|
||||||
t = get_rtctime();
|
|
||||||
if (t)
|
|
||||||
return t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// else we use systime as fallback source
|
|
||||||
return now();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // HAS_IF482 || defined HAS_DCF77
|
#endif // HAS_IF482 || defined HAS_DCF77
|
@ -4,6 +4,9 @@
|
|||||||
// a nice & free logic test program for DCF77 can be found here:
|
// a nice & free logic test program for DCF77 can be found here:
|
||||||
https://www-user.tu-chemnitz.de/~heha/viewzip.cgi/hs/Funkuhr.zip/
|
https://www-user.tu-chemnitz.de/~heha/viewzip.cgi/hs/Funkuhr.zip/
|
||||||
//
|
//
|
||||||
|
// a DCF77 digital scope for Arduino boards can be found here:
|
||||||
|
https://github.com/udoklein/dcf77
|
||||||
|
//
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAS_DCF77
|
#ifdef HAS_DCF77
|
||||||
|
@ -221,7 +221,7 @@ void refreshtheDisplay() {
|
|||||||
// update LoRa status display (line 6)
|
// update LoRa status display (line 6)
|
||||||
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
|
||||||
time_t t = myTZ.toLocal(now());
|
time_t t = myTZ.toLocal(best_time());
|
||||||
char timeState =
|
char timeState =
|
||||||
(timeStatus() == timeSet) ? timesyncSymbol : timeNosyncSymbol;
|
(timeStatus() == timeSet) ? timesyncSymbol : timeNosyncSymbol;
|
||||||
char timePulse = TimePulseTick ? '.' : ':';
|
char timePulse = TimePulseTick ? '.' : ':';
|
||||||
|
@ -91,16 +91,14 @@ time_t get_gpstime(void) {
|
|||||||
// !! never call now() or delay in this function, this would break this
|
// !! never call now() or delay in this function, this would break this
|
||||||
// function to be used as SyncProvider for Time.h
|
// function to be used as SyncProvider for Time.h
|
||||||
|
|
||||||
|
time_t t = 0; // 0 effects calling SyncProvider() to not set time
|
||||||
|
|
||||||
if ((gps.time.age() < 1500) && (gps.time.isValid())) {
|
if ((gps.time.age() < 1500) && (gps.time.isValid())) {
|
||||||
// get current gps time
|
// get current gps time
|
||||||
time_t t =
|
t = tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(),
|
||||||
tmConvert_t(gps.date.year(), gps.date.month(), gps.date.day(),
|
|
||||||
gps.time.hour(), gps.time.minute(), gps.time.second());
|
gps.time.hour(), gps.time.minute(), gps.time.second());
|
||||||
return t;
|
|
||||||
} else {
|
|
||||||
ESP_LOGW(TAG, "GPS has no confident time");
|
|
||||||
return 0; // sync failure, 0 effects calling SyncProvider() to not set time
|
|
||||||
}
|
}
|
||||||
|
return t;
|
||||||
} // get_gpstime()
|
} // get_gpstime()
|
||||||
|
|
||||||
// GPS serial feed FreeRTos Task
|
// GPS serial feed FreeRTos Task
|
||||||
|
@ -93,6 +93,30 @@ int sync_TimePulse(void) {
|
|||||||
return 0; // failure
|
return 0; // failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helper function to fetch current second from most precise time source
|
||||||
|
time_t best_time(void) {
|
||||||
|
|
||||||
|
time_t t;
|
||||||
|
|
||||||
|
#ifdef HAS_GPS // gps is our primary time source if present
|
||||||
|
t = get_gpstime();
|
||||||
|
if (t) // did we get a valid time?
|
||||||
|
return t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Reading RTC time from chip take too long on i2c bus, causes jitter
|
||||||
|
#ifdef HAS_RTC // rtc is our secondary time source if present
|
||||||
|
t = get_rtctime();
|
||||||
|
if (t)
|
||||||
|
return t;
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
// else we use systime as fallback source
|
||||||
|
return now();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAS_RTC // we have hardware RTC
|
#ifdef HAS_RTC // we have hardware RTC
|
||||||
|
|
||||||
RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface
|
RtcDS3231<TwoWire> Rtc(Wire); // RTC hardware i2c interface
|
||||||
@ -166,14 +190,12 @@ int set_rtctime(uint32_t t) { // t is epoch seconds starting 1.1.1970
|
|||||||
time_t get_rtctime(void) {
|
time_t get_rtctime(void) {
|
||||||
// !! never call now() or delay in this function, this would break this
|
// !! never call now() or delay in this function, this would break this
|
||||||
// function to be used as SyncProvider for Time.h
|
// function to be used as SyncProvider for Time.h
|
||||||
time_t t = 0;
|
time_t t = 0; // 0 effects calling SyncProvider() to not set time
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (I2C_MUTEX_LOCK()) {
|
if (I2C_MUTEX_LOCK()) {
|
||||||
if (Rtc.IsDateTimeValid()) {
|
if (Rtc.IsDateTimeValid()) {
|
||||||
RtcDateTime tt = Rtc.GetDateTime();
|
RtcDateTime tt = Rtc.GetDateTime();
|
||||||
t = tt.Epoch32Time();
|
t = tt.Epoch32Time();
|
||||||
} else {
|
|
||||||
ESP_LOGW(TAG, "RTC has no confident time");
|
|
||||||
}
|
}
|
||||||
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user