commit
e8245cc862
@ -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
|
||||||
|
@ -41,6 +41,16 @@ 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 timeNosyncSymbol = '?';
|
||||||
|
#if defined HAS_IF482
|
||||||
|
const char timesyncSymbol = '+';
|
||||||
|
#elif defined HAS_DCF77
|
||||||
|
const char timesyncSymbol = '*';
|
||||||
|
#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"};
|
||||||
@ -130,6 +140,11 @@ void init_display(const char *Productname, const char *Version) {
|
|||||||
|
|
||||||
void refreshtheDisplay() {
|
void refreshtheDisplay() {
|
||||||
|
|
||||||
|
uint8_t msgWaiting;
|
||||||
|
char timeSync, timeState;
|
||||||
|
char buff[16]; // 16 chars line buffer
|
||||||
|
time_t t;
|
||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (I2C_MUTEX_LOCK()) {
|
if (I2C_MUTEX_LOCK()) {
|
||||||
|
|
||||||
@ -143,17 +158,6 @@ void refreshtheDisplay() {
|
|||||||
if (!DisplayState)
|
if (!DisplayState)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t msgWaiting;
|
|
||||||
char buff[16]; // 16 chars line buffer
|
|
||||||
#if (defined HAS_DCF77) || (defined HAS_IF482)
|
|
||||||
const char timeNosyncSymbol = '?';
|
|
||||||
#if (defined HAS_IF482)
|
|
||||||
const char timesyncSymbol = '+';
|
|
||||||
#else
|
|
||||||
const char timesyncSymbol = '*';
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// update counter (lines 0-1)
|
// update counter (lines 0-1)
|
||||||
snprintf(
|
snprintf(
|
||||||
buff, sizeof(buff), "PAX:%-4d",
|
buff, sizeof(buff), "PAX:%-4d",
|
||||||
@ -221,12 +225,12 @@ 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());
|
t = myTZ.toLocal(best_time());
|
||||||
char timeState =
|
timeSync = (timeStatus() == timeSet) ? timesyncSymbol : timeNosyncSymbol;
|
||||||
(timeStatus() == timeSet) ? timesyncSymbol : timeNosyncSymbol;
|
timeState = TimePulseTick ? timeSync : ' ';
|
||||||
char timePulse = TimePulseTick ? '.' : ':';
|
TimePulseTick = false;
|
||||||
u8x8.printf("%02d:%02d%c%02d%c %2d.%3s", hour(t), minute(t), timePulse,
|
u8x8.printf("%02d:%02d:%02d%c %2d.%3s", hour(t), minute(t), second(t),
|
||||||
second(t), timeState, day(t), printmonth[month(t)]);
|
timeState, day(t), printmonth[month(t)]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// update LMiC event display (line 7)
|
// update LMiC event display (line 7)
|
||||||
|
@ -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
|
||||||
|
@ -25,11 +25,13 @@ public:
|
|||||||
MyHalConfig_t myHalConfig{};
|
MyHalConfig_t myHalConfig{};
|
||||||
|
|
||||||
// LMIC pin mapping
|
// LMIC pin mapping
|
||||||
|
|
||||||
const lmic_pinmap lmic_pins = {
|
const lmic_pinmap lmic_pins = {
|
||||||
.nss = LORA_CS,
|
.nss = LORA_CS,
|
||||||
.rxtx = LMIC_UNUSED_PIN,
|
.rxtx = LMIC_UNUSED_PIN,
|
||||||
.rst = LORA_RST,
|
.rst = LORA_RST == NOT_A_PIN ? LMIC_UNUSED_PIN : LORA_RST,
|
||||||
.dio = {LORA_IRQ, LORA_IO1, LORA_IO2},
|
.dio = {LORA_IRQ, LORA_IO1,
|
||||||
|
LORA_IO2 == NOT_A_PIN ? LMIC_UNUSED_PIN : LORA_IO2},
|
||||||
// optional: set polarity of rxtx pin.
|
// optional: set polarity of rxtx pin.
|
||||||
.rxtx_rx_active = 0,
|
.rxtx_rx_active = 0,
|
||||||
// optional: set RSSI cal for listen-before-talk
|
// optional: set RSSI cal for listen-before-talk
|
||||||
|
@ -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