From 9e5d1b5244cf68d547f7f5f61d6acf406618350e Mon Sep 17 00:00:00 2001 From: Norbert Walter Date: Sun, 19 Dec 2021 13:51:47 +0100 Subject: [PATCH] Add heartbeat, date time and faster page update rate --- lib/obp60task/GwOBP60Task.cpp | 49 ++++++++++++++++++++++++++++++++--- lib/obp60task/OBP60Data.h | 1 + lib/obp60task/OBP60Pages.h | 20 +++++++++++++- lib/obp60task/Page_0.h | 2 +- 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/lib/obp60task/GwOBP60Task.cpp b/lib/obp60task/GwOBP60Task.cpp index fe2cee0..f31f563 100644 --- a/lib/obp60task/GwOBP60Task.cpp +++ b/lib/obp60task/GwOBP60Task.cpp @@ -80,6 +80,37 @@ class GetBoatDataRequest: public GwMessage{ }; }; +String formatValue(GwApi::BoatValue *value){ + if (! value->valid) return "----"; + static const int bsize=30; + char buffer[bsize+1]; + buffer[0]=0; + if (value->getFormat() == "formatDate"){ + time_t tv=tNMEA0183Msg::daysToTime_t(value->value); + tmElements_t parts; + tNMEA0183Msg::breakTime(tv,parts); + snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); + } + else if(value->getFormat() == "formatTime"){ + double inthr; + double intmin; + double intsec; + double val; + val=modf(value->value/3600.0,&inthr); + val=modf(val*3600.0/60.0,&intmin); + modf(val*60.0,&intsec); + snprintf(buffer,bsize,"%02.0f:%02.0f:%02.0f",inthr,intmin,intsec); + } + else if (value->getFormat() == "formatFixed0"){ + snprintf(buffer,bsize,"%.0f",value->value); + } + else{ + snprintf(buffer,bsize,"%.4f",value->value); + } + buffer[bsize]=0; + return String(buffer); +} + // Hardware initialisation before start all services //################################################## void OBP60Init(GwApi *api){ @@ -204,7 +235,8 @@ void OBP60Task(void *param){ GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude")); GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude")); GwApi::BoatValue *waterdepth=new GwApi::BoatValue(F("WaterDepth")); - GwApi::BoatValue *valueList[]={sog, date, time, longitude, latitude, waterdepth}; + GwApi::BoatValue *pdop=new GwApi::BoatValue(F("PDOP")); + GwApi::BoatValue *valueList[]={sog, date, time, longitude, latitude, waterdepth, pdop}; //Init E-Ink display display.init(); // Initialize and clear display @@ -283,14 +315,23 @@ void OBP60Task(void *param){ } //fetch the current values of the items that we have in itemNames - api->getBoatDataValues(6,valueList); + api->getBoatDataValues(7,valueList); busInfo.WaterDepth.fvalue = waterdepth->value; + waterdepth->getFormat().toCharArray(busInfo.WaterDepth.unit, 8, 0); busInfo.WaterDepth.valid = int(waterdepth->valid); busInfo.SOG.fvalue = sog->value; + sog->getFormat().toCharArray(busInfo.SOG.unit, 8, 0); busInfo.SOG.valid = int(sog->valid); + formatValue(date).toCharArray(busInfo.Date.svalue, 31, 0); + busInfo.Date.valid = date->valid; + formatValue(time).toCharArray(busInfo.Time.svalue, 31, 0); + busInfo.Time.valid = time->valid; + busInfo.PDOP.fvalue = pdop->value; + busInfo.PDOP.valid = pdop->valid; - // Subtask all 1000ms show pages - if((taskRunCounter % 100) == 0 || first_view == true){ + + // Subtask all 500ms show pages + if((taskRunCounter % 50) == 0 || first_view == true){ LOG_DEBUG(GwLog::DEBUG,"Keystatus: %s", keystatus); LOG_DEBUG(GwLog::DEBUG,"Pagenumber: %d", pageNumber); if(displayMode == "Logo + QR Code" || displayMode == "Logo" || displayMode == "White Screen"){ diff --git a/lib/obp60task/OBP60Data.h b/lib/obp60task/OBP60Data.h index 1492591..2a9b95b 100644 --- a/lib/obp60task/OBP60Data.h +++ b/lib/obp60task/OBP60Data.h @@ -6,6 +6,7 @@ typedef struct{ float fvalue = 0; // Float value char svalue[31] = ""; // Char value + char unit[8] = ""; // Unit int valid = 0; // Valid flag } dataContainer; diff --git a/lib/obp60task/OBP60Pages.h b/lib/obp60task/OBP60Pages.h index 9d2cc62..261e537 100644 --- a/lib/obp60task/OBP60Pages.h +++ b/lib/obp60task/OBP60Pages.h @@ -6,6 +6,7 @@ // Global vars int pageNumber = 0; // Page number for actual page bool first_view = true; +bool heartbeat = false; void showPage(busData values){ // Clear display @@ -17,8 +18,25 @@ void showPage(busData values){ display.setTextColor(GxEPD_BLACK); display.setCursor(0, 15); display.print(" WiFi AP TCP N2K 183 GPS"); + display.setFont(&Ubuntu_Bold32pt7b); + display.setCursor(205, 14); + if(heartbeat == true){ + display.print("."); + } + else{ + display.print(" "); + } + heartbeat = !heartbeat; + display.setFont(&Ubuntu_Bold8pt7b); display.setCursor(230, 15); - display.print("14.12.2021 17:50 UTC"); + if(values.PDOP.valid == true && values.PDOP.fvalue <= 50){ + display.print(values.Date.svalue); + display.print(" "); + display.print(values.Time.svalue); + } + else{ + display.print("No GPS data"); + } // Read page number switch (pageNumber) { diff --git a/lib/obp60task/Page_0.h b/lib/obp60task/Page_0.h index 750dc70..fc91f27 100644 --- a/lib/obp60task/Page_0.h +++ b/lib/obp60task/Page_0.h @@ -5,7 +5,7 @@ #include "OBP60Hardware.h" void page_0(busData pvalues){ - // Measuring Values + // Name and unit display.setFont(&Ubuntu_Bold32pt7b); display.setTextColor(GxEPD_BLACK); display.setCursor(20, 100);