More work on clock page and datetime handling

This commit is contained in:
Thomas Hooge 2025-02-05 18:17:30 +01:00
parent eb3a0d5fc0
commit e398c7bdce
4 changed files with 55 additions and 55 deletions

View File

@ -424,7 +424,7 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *date, GwApi::BoatVa
String fmttype = commonData.config->getString(commonData.config->dateFormat);
String timesource = commonData.config->getString(commonData.config->timeSource);
int tz = commonData.config->getInt(commonData.config->timeZone);
getdisplay().setTextColor(textcolor);
getdisplay().setTextColor(commonData.fgcolor);
getdisplay().setFont(&Ubuntu_Bold8pt7b);
getdisplay().setCursor(230, 15);
if (timesource == "RTC") {

View File

@ -19,7 +19,7 @@
#include "movingAvg.h" // Lib for moving average building
// Timer for hardware functions
Ticker Timer1(blinkingFlashLED, 500); // Satrt Timer1 for flash LED all 500ms
Ticker Timer1(blinkingFlashLED, 500); // Start Timer1 for flash LED all 500ms
// Initialization for all sensors (RS232, I2C, 1Wire, IOs)
//####################################################################################
@ -432,33 +432,34 @@ void sensorTask(void *param){
if (millis() > starttime12 + 500) {
starttime12 = millis();
if (rtcOn == "DS1388" && RTC_ready) {
sensors.rtcTime.tm_year = ds1388.now().year() - 1900; // Save values in SensorData
sensors.rtcTime.tm_mon = ds1388.now().month() - 1;
sensors.rtcTime.tm_mday = ds1388.now().day();
sensors.rtcTime.tm_hour = ds1388.now().hour();
sensors.rtcTime.tm_min = ds1388.now().minute();
sensors.rtcTime.tm_sec = ds1388.now().second();
DateTime dt = ds1388.now();
sensors.rtcTime.tm_year = dt.year() - 1900; // Save values in SensorData
sensors.rtcTime.tm_mon = dt.month() - 1;
sensors.rtcTime.tm_mday = dt.day();
sensors.rtcTime.tm_hour = dt.hour();
sensors.rtcTime.tm_min = dt.minute();
sensors.rtcTime.tm_sec = dt.second();
sensors.rtcTime.tm_isdst = 0; // Not considering daylight saving time
// If GPS not ready or installed then send RTC time on bus
// TODO If there are other time sources on the bus there should
// be a logic not to send or to send with lower frequency
// or something totally different
if ((GPS_ready == false) || (GPS_ready == true && hdop->valid == false)) {
// Convert RTC time to Unix system time
// https://de.wikipedia.org/wiki/Unixzeit
// TODO implement daysAt1970 and sysTime as methods of DateTime
const short daysOfYear[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
// unused: long unixtime = ds1388.now().get();
uint16_t switchYear = ((sensors.rtcTime.tm_year-1)-1968)/4 - ((sensors.rtcTime.tm_year-1)-1900)/100 + ((sensors.rtcTime.tm_year-1)-1600)/400;
long daysAt1970 = (sensors.rtcTime.tm_year-1970)*365 + switchYear + daysOfYear[sensors.rtcTime.tm_mon-1] + sensors.rtcTime.tm_mday-1;
uint16_t switchYear = ((dt.year()-1)-1968)/4 - ((dt.year()-1)-1900)/100 + ((dt.year()-1)-1600)/400;
long daysAt1970 = (dt.year()-1970)*365 + switchYear + daysOfYear[dt.month()-1] + dt.day()-1;
// If switch year then add one day
if ((sensors.rtcTime.tm_mon > 2) && (sensors.rtcTime.tm_year % 4 == 0
&& (sensors.rtcTime.tm_year % 100 != 0 || sensors.rtcTime.tm_year % 400 == 0))) {
if ((dt.month() > 2) && (dt.year() % 4 == 0 && (dt.year() % 100 != 0 || dt.year() % 400 == 0))) {
daysAt1970 += 1;
}
// N2K sysTime ist double in n2klib
double sysTime = (sensors.rtcTime.tm_hour * 3600) + (sensors.rtcTime.tm_min * 60) + sensors.rtcTime.tm_sec;
// N2K sysTime is double in n2klib
double sysTime = (dt.hour() * 3600) + (dt.minute() * 60) + dt.second();
// WHY? isnan should always fail here
//if(!isnan(daysAt1970) && !isnan(sysTime)){
// api->getLogger()->logDebug(GwLog::LOG,"RTC time: %04d/%02d/%02d %02d:%02d:%02d",year, month, day, hour, minute, second);
// api->getLogger()->logDebug(GwLog::LOG,"Send PGN126992: %10d %10d",daysAt1970, (uint16_t)sysTime);
//api->getLogger()->logDebug(GwLog::LOG,"RTC time: %04d/%02d/%02d %02d:%02d:%02d",sensors.rtcTime.tm_year+1900,sensors.rtcTime.tm_mon, sensors.rtcTime.tm_mday, sensors.rtcTime.tm_hour, sensors.rtcTime.tm_min, sensors.rtcTime.tm_sec);
//api->getLogger()->logDebug(GwLog::LOG,"Send PGN126992: %10d %10d",daysAt1970, (uint16_t)sysTime);
SetN2kPGN126992(N2kMsg,0,daysAt1970,sysTime,N2ktimes_LocalCrystalClock);
api->sendN2kMessage(N2kMsg);
// }

View File

@ -19,18 +19,27 @@ class PageClock : public Page
bool simulation = false;
int simtime;
bool keylock = false;
char source = 'R'; // time source (R)TC | (G)PS
char source = 'R'; // time source (R)TC | (G)PS | (N)TP
char mode = 'A'; // display mode (A)nalog | (D)igital | race (T)imer
char tz = 'L'; // time zone (L)ocal | (U)TC
double timezone = 0; // there are timezones with non int offsets, e.g. 5.5 or 5.75
public:
PageClock(CommonData &common){
commonData = &common;
common.logger->logDebug(GwLog::LOG,"Instantiate PageClock");
simulation = common.config->getBool(common.config->useSimuData);
timezone = common.config->getString(common.config->timeZone).toDouble();
simtime = 38160; // time value 11:36
}
virtual void setupKeys(){
Page::setupKeys();
commonData->keydata[0].label = "SRC";
commonData->keydata[1].label = "MODE";
commonData->keydata[4].label = "TZ";
}
// Key functions
virtual int handleKey(int key){
// Time source
@ -92,12 +101,9 @@ char tz = 'L'; // time zone (L)ocal | (U)TC
// Get config data
String lengthformat = config->getString(config->lengthFormat);
String dateformat = config->getString(config->dateFormat);
bool simulation = config->getBool(config->useSimuData);
bool holdvalues = config->getBool(config->holdvalues);
String flashLED = config->getString(config->flashLED);
String backlightMode = config->getString(config->backlight);
String stimezone = config->getString(config->timeZone);
double timezone = stimezone.toDouble();
// Get boat values for GPS time
GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (only one value by PageOneValue)
@ -161,7 +167,7 @@ char tz = 'L'; // time zone (L)ocal | (U)TC
getdisplay().setTextColor(commonData->fgcolor);
time_t tv = mktime(&commonData.data.rtcTime) + timezone * 3600;
time_t tv = mktime(&commonData->data.rtcTime) + timezone * 3600;
struct tm *local_tm = localtime(&tv);
// Show values GPS date
@ -177,7 +183,7 @@ char tz = 'L'; // time zone (L)ocal | (U)TC
getdisplay().print(formatDate(dateformat, local_tm->tm_year + 1900, local_tm->tm_mon + 1, local_tm->tm_mday));
}
else {
getdisplay().print(formatDate(dateformat, commonData.data.rtcTime.tm_year + 1900, commonData.data.rtcTime.tm_mon + 1, commonData.data.rtcTime.tm_mday));
getdisplay().print(formatDate(dateformat, commonData->data.rtcTime.tm_year + 1900, commonData->data.rtcTime.tm_mon + 1, commonData->data.rtcTime.tm_mday));
}
}
} else {
@ -202,7 +208,7 @@ char tz = 'L'; // time zone (L)ocal | (U)TC
getdisplay().print(formatTime('s', local_tm->tm_hour, local_tm->tm_min, local_tm->tm_sec));
}
else {
getdisplay().print(formatTime('s', commonData.data.rtcTime.tm_hour, commonData.data.rtcTime.tm_min, commonData.data.rtcTime.tm_sec));
getdisplay().print(formatTime('s', commonData->data.rtcTime.tm_hour, commonData->data.rtcTime.tm_min, commonData->data.rtcTime.tm_sec));
}
}
}
@ -324,7 +330,7 @@ char tz = 'L'; // time zone (L)ocal | (U)TC
getdisplay().setCursor(175, 110);
if(holdvalues == false){
if (tz == 'L') {
getdisplay().print(unit2); // Unit
getdisplay().print(unit2); // Unit
} else {
getdisplay().print("UTC");
}
@ -346,21 +352,21 @@ char tz = 'L'; // time zone (L)ocal | (U)TC
double minute = 0;
if (source == 'R') {
if (tz == 'L') {
time_t tv = mktime(&commonData.data.rtcTime) + timezone * 3600;
time_t tv = mktime(&commonData->data.rtcTime) + timezone * 3600;
struct tm *local_tm = localtime(&tv);
minute = local_tm->tm_min;
hour = local_tm->tm_hour;
} else {
minute = commonData.data.rtcTime.tm_min;
hour = commonData.data.rtcTime.tm_hour;
minute = commonData->data.rtcTime.tm_min;
hour = commonData->data.rtcTime.tm_hour;
}
hour += minute / 60;
} else {
if (tz == 'L') {
value1 += int(timezone*3600);
value1 += timezone * 3600;
}
if (value1 > 86400) {value1 = value1 - 86400;}
if (value1 < 0) {value1 = value1 + 86400;}
if (value1 > 86400) {value1 -= 86400;}
if (value1 < 0) {value1 += 86400;}
hour = (value1 / 3600.0);
// minute = (hour - int(hour)) * 3600.0 / 60.0; // Analog minute pointer smooth moving
minute = int((hour - int(hour)) * 3600.0 / 60.0); // Jumping minute pointer from minute to minute
@ -426,28 +432,6 @@ char tz = 'L'; // time zone (L)ocal | (U)TC
getdisplay().fillCircle(200, 150, startwidth + 6, commonData->bgcolor);
getdisplay().fillCircle(200, 150, startwidth + 4, commonData->fgcolor);
//*******************************************************************************************
// Key Layout
getdisplay().setFont(&Ubuntu_Bold8pt7b);
if(keylock == false){
getdisplay().setCursor(10, 290);
getdisplay().print("[SRC]");
getdisplay().setCursor(60, 290);
getdisplay().print("[MODE]");
getdisplay().setCursor(293, 290);
getdisplay().print("[TZ]");
getdisplay().setCursor(130, 290);
getdisplay().print("[ <<<< " + String(commonData.data.actpage) + "/" + String(commonData.data.maxpage) + " >>>> ]");
if(String(backlightMode) == "Control by Key"){ // Key for illumination
getdisplay().setCursor(343, 290);
getdisplay().print("[ILUM]");
}
}
else{
getdisplay().setCursor(130, 290);
getdisplay().print(" [ Keylock active ]");
}
// Update display
getdisplay().nextPage(); // Partial update (fast)

View File

@ -705,6 +705,21 @@
"obp40": "true"
}
},
{
"name": "timeSource",
"label": "Status Time Source",
"type": "list",
"default": "GPS",
"description": "Data source for date and time display in status line [RTC|GPS]",
"list": [
{"l":"Internal real time clock (RTC)","v":"RTC"},
{"l":"External time via bus (GPS)","v":"GPS"}
],
"category": "OBP40 Display",
"capabilities": {
"obp40":"true"
}
},
{
"name": "refresh",
"label": "Refresh",