diff --git a/lib/obp60task/OBP60Formater.cpp b/lib/obp60task/OBP60Formater.cpp index f7a4cff..85e67b1 100644 --- a/lib/obp60task/OBP60Formater.cpp +++ b/lib/obp60task/OBP60Formater.cpp @@ -5,44 +5,43 @@ // ToDo // simulation data // hold values by missing data -// different unit convertion -FormatedData formatValue(GwApi::BoatValue *value){ -// GwApi *api; +FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ FormatedData result; -/* + // Load configuration values - String lengthFormat = api->getConfig()->getConfigItem(api->getConfig()->lengthFormat,true)->asString(); // [m|ft] - String distanceFormat = api->getConfig()->getConfigItem(api->getConfig()->distanceFormat,true)->asString(); // [m|km|nm] - String speedFormat = api->getConfig()->getConfigItem(api->getConfig()->speedFormat,true)->asString(); // [m/s|km/h|kn] - String windspeedFormat = api->getConfig()->getConfigItem(api->getConfig()->windspeedFormat,true)->asString(); // [m/s|km/h|kn|bft] - String tempFormat = api->getConfig()->getConfigItem(api->getConfig()->tempFormat,true)->asString(); // [K|°C|°F] - String dateFormat = api->getConfig()->getConfigItem(api->getConfig()->dateFormat,true)->asString(); // [DE|GB|US] -*/ + int timeZone = commondata.config->getInt(commondata.config->timeZone); // [UTC -12...+12] + String lengthFormat = commondata.config->getString(commondata.config->lengthFormat); // [m|ft] + String distanceFormat = commondata.config->getString(commondata.config->distanceFormat); // [m|km|nm] + String speedFormat = commondata.config->getString(commondata.config->speedFormat); // [m/s|km/h|kn] + String windspeedFormat = commondata.config->getString(commondata.config->windspeedFormat); // [m/s|km/h|kn|bft] + String tempFormat = commondata.config->getString(commondata.config->tempFormat); // [K|°C|°F] + String dateFormat = commondata.config->getString(commondata.config->dateFormat); // [DE|GB|US] + if (! value->valid){ result.svalue = "---"; result.unit = ""; return result; } - static const int bsize=30; + 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); -/* + tNMEA0183Msg::breakTime(tv,parts); if(String(dateFormat) == "DE"){ snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); } - if(String(dateFormat) == "GB"){ + else if(String(dateFormat) == "GB"){ snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); } - if(String(dateFormat) == "US"){ + else if(String(dateFormat) == "US"){ snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mon+1,parts.tm_mday,parts.tm_year+1900); } -*/ - snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); + else{ + snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); + } } else if(value->getFormat() == "formatTime"){ double inthr; @@ -50,10 +49,16 @@ FormatedData formatValue(GwApi::BoatValue *value){ double intsec; double val; val=modf(value->value/3600.0,&inthr); + inthr += timeZone; 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); - result.unit = ""; + if(timeZone == 0){ + result.unit = "UTC"; + } + else{ + result.unit = "LOT"; + } } else if (value->getFormat() == "formatFixed0"){ snprintf(buffer,bsize,"%.0f",value->value); @@ -67,7 +72,7 @@ FormatedData formatValue(GwApi::BoatValue *value){ snprintf(buffer,bsize,"%2.1f",course); } if(course >= 10 && course < 100){ - snprintf(buffer,bsize,"%3.1f",course); + snprintf(buffer,bsize,"%2.1f",course); } if(course >= 100){ snprintf(buffer,bsize,"%3.0f",course); @@ -75,16 +80,73 @@ FormatedData formatValue(GwApi::BoatValue *value){ } else if (value->getFormat() == "formatKnots" || value->getFormat() == "formatWind"){ double speed = value->value; - speed = speed * 1.94384; // Unit conversion form m/s to kn - result.unit = "kn"; - if(speed < 10){ - snprintf(buffer,bsize,"%2.1f",speed); + if(String(speedFormat) == "km/h" || String(windspeedFormat) == "km/h"){ + speed = speed * 3.6; // Unit conversion form m/s to km/h + result.unit = "m/s"; } - if(speed >= 10 && speed < 100){ - snprintf(buffer,bsize,"%3.1f",speed); + else if(String(speedFormat) == "kn" || String(windspeedFormat) == "kn"){ + speed = speed * 1.94384; // Unit conversion form m/s to kn + result.unit = "kn"; } - if(speed >= 100){ - snprintf(buffer,bsize,"%3.0f",speed); + else if(String(windspeedFormat) == "bft"){ + if(speed < 0.3){ + speed = 0; + } + if(speed >=0.3 && speed < 1.5){ + speed = 1; + } + if(speed >=1.5 && speed < 3.3){ + speed = 2; + } + if(speed >=3.3 && speed < 5.4){ + speed = 3; + } + if(speed >=5.4 && speed < 7.9){ + speed = 4; + } + if(speed >=7.9 && speed < 10.7){ + speed = 5; + } + if(speed >=10.7 && speed < 13.8){ + speed = 6; + } + if(speed >=13.8 && speed < 17.1){ + speed = 7; + } + if(speed >=17.1 && speed < 20.7){ + speed = 8; + } + if(speed >=20.7 && speed < 24.4){ + speed = 9; + } + if(speed >=24.4 && speed < 28.4){ + speed = 10; + } + if(speed >=28.4 && speed < 32.6){ + speed = 11; + } + if(speed >=32.6){ + speed = 12; + } + result.unit = "bft"; + } + else{ + speed = speed; // Unit conversion form m/s to m/s + result.unit = "m/s"; + } + if(String(windspeedFormat) == "bft"){ + snprintf(buffer,bsize,"%2.0f",speed); + } + else{ + if(speed < 10){ + snprintf(buffer,bsize,"%2.1f",speed); + } + if(speed >= 10 && speed < 100){ + snprintf(buffer,bsize,"%2.1f",speed); + } + if(speed >= 100){ + snprintf(buffer,bsize,"%3.0f",speed); + } } } else if (value->getFormat() == "formatRot"){ @@ -95,7 +157,7 @@ FormatedData formatValue(GwApi::BoatValue *value){ snprintf(buffer,bsize,"%2.1f",rotation); } if(rotation >= 10 && rotation < 100){ - snprintf(buffer,bsize,"%3.1f",rotation); + snprintf(buffer,bsize,"%2.1f",rotation); } if(rotation >= 100){ snprintf(buffer,bsize,"%3.0f",rotation); @@ -108,7 +170,7 @@ FormatedData formatValue(GwApi::BoatValue *value){ snprintf(buffer,bsize,"%2.1f",dop); } if(dop >= 10 && dop < 100){ - snprintf(buffer,bsize,"%3.1f",dop); + snprintf(buffer,bsize,"%2.1f",dop); } if(dop >= 100){ snprintf(buffer,bsize,"%3.0f",dop); @@ -150,7 +212,13 @@ FormatedData formatValue(GwApi::BoatValue *value){ } else if (value->getFormat() == "formatDepth"){ double depth = value->value; - result.unit = "m"; + if(String(lengthFormat) == "ft"){ + depth = depth * 3.28084; + result.unit = "ft"; + } + else{ + result.unit = "m"; + } if(depth < 10){ snprintf(buffer,bsize,"%2.1f",depth); } @@ -163,8 +231,17 @@ FormatedData formatValue(GwApi::BoatValue *value){ } else if (value->getFormat() == "kelvinToC"){ double temp = value->value; - temp = temp - 273.15; - result.unit = "degree"; + if(String(tempFormat) == "°C"){ + temp = temp - 273.15; + result.unit = "C"; + } + else if(String(tempFormat) == "°F"){ + temp = temp - 459.67; + result.unit = "F"; + } + else{ + result.unit = "K"; + } if(temp < 10){ snprintf(buffer,bsize,"%2.1f",temp); } @@ -177,8 +254,18 @@ FormatedData formatValue(GwApi::BoatValue *value){ } else if (value->getFormat() == "mtr2nm"){ double distance = value->value; - distance = distance * 0.000539957; - result.unit = "nm"; + if(String(distanceFormat) == "km"){ + distance = distance * 0.001; + result.unit = "km"; + } + else if(String(distanceFormat) == "nm"){ + distance = distance * 0.000539957; + result.unit = "nm"; + } + else{ + distance = distance * 0.000539957; + result.unit = "m"; + } if(distance < 10){ snprintf(buffer,bsize,"%2.1f",distance); } diff --git a/lib/obp60task/PageOneValue.cpp b/lib/obp60task/PageOneValue.cpp index a1b82d3..b60a506 100644 --- a/lib/obp60task/PageOneValue.cpp +++ b/lib/obp60task/PageOneValue.cpp @@ -13,15 +13,17 @@ class PageOneValue : public Page{ String displaycolor = config->getString(config->displaycolor); bool holdvalues = config->getBool(config->holdvalues); String flashLED = config->getString(config->flashLED); + String backlightMode = config->getString(config->backlight); // Get boat values GwApi::BoatValue *bvalue=pageData.values[0]; // First element in list (only one value by PageOneValue) String name1 = bvalue->getName().c_str(); // Value name + name1 = name1.substring(0, 6); // String length limit for value name double value1 = bvalue->value; // Value as double in SI unit - String svalue1 = formatValue(bvalue).svalue; // Formatted value as string including unit conversion and switching decimal places - String unit1 = formatValue(bvalue).unit; // Unit of value + String svalue1 = formatValue(bvalue, commonData).svalue; // Formatted value as string including unit conversion and switching decimal places + String unit1 = formatValue(bvalue, commonData).unit; // Unit of value - // Optical warning by limit violation + // Optical warning by limit violation (unused) if(String(flashLED) == "Limit Violation"){ setBlinkingLED(false); setPortPin(OBP_FLASH_LED, false); @@ -89,8 +91,10 @@ class PageOneValue : public Page{ display.setFont(&Ubuntu_Bold8pt7b); display.setCursor(115, 290); display.print(" [ <<<<<< >>>>>> ]"); - display.setCursor(343, 290); - display.print("[ILUM]"); + if(String(backlightMode) == "Control by Key"){ + display.setCursor(343, 290); + display.print("[ILUM]"); + } // Update display display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 3884b15..b5ebb67 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -68,4 +68,4 @@ typedef struct{ // Formater for boat values -FormatedData formatValue(GwApi::BoatValue *value); +FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata); diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index ad8d8dd..26d36dc 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -365,6 +365,9 @@ void OBP60Task(GwApi *api){ // Task Loop //############################### + GwApi::BoatValue *hdop = boatValues.findValueOrCreate("HDOP"); // Load HDOP + String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString(); + LOG_DEBUG(GwLog::LOG,"obp60task: start mainloop"); int pageNumber=0; int lastPage=pageNumber; @@ -389,9 +392,6 @@ void OBP60Task(GwApi *api){ } // If GPS fix then LED on (HDOP) - String gpsFix = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString(); - GwApi::BoatValue *hdop; - hdop = boatValues.findValueOrCreate("HDOP"); if(String(gpsFix) == "GPS Fix" && hdop->valid == true && int(hdop->value) <= 50){ setPortPin(OBP_FLASH_LED, true); } @@ -457,12 +457,12 @@ void OBP60Task(GwApi *api){ //handle the page if (pages[pageNumber].description && pages[pageNumber].description->header){ - //build some header and footer using commonData - - + display.setFont(&Ubuntu_Bold32pt7b); + display.setCursor(20, 100); + display.print("Hallo"); } - //.... + //call the particular page Page *currentPage=pages[pageNumber].page; if (currentPage == NULL){