diff --git a/lib/obp60task/PageBattery2.cpp b/lib/obp60task/PageBattery2.cpp index b691c30..d78e237 100644 --- a/lib/obp60task/PageBattery2.cpp +++ b/lib/obp60task/PageBattery2.cpp @@ -5,6 +5,10 @@ class PageBattery2 : public Page { +static constexpr int8_t LEFT = 0; +static constexpr int8_t CENTER = 1; +static constexpr int8_t RIGHT = 2; + bool init = false; // Marker for init done int average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s, 3=300s bool trend = true; // Trend indicator [0|1], 0=off, 1=on @@ -65,6 +69,7 @@ public: String batType = config->getString(config->batteryType); String backlightMode = config->getString(config->backlight); String powerSensor = config->getString(config->usePowSensor1); + bool smallDecimals = config->getBool(config->smallDecimals); double value1 = 0; // Battery voltage double value2 = 0; // Battery current @@ -198,20 +203,16 @@ public: getdisplay().print(batType); // Show voltage type - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 140); int bvoltage = 0; if(String(batVoltage) == "12V") bvoltage = 12; else bvoltage = 24; - getdisplay().print(bvoltage); + printBoatValue(String(bvoltage), 10, 140, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("V"); // Show battery capacity - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 200); - if(batCapacity <= 999) getdisplay().print(batCapacity, 0); - if(batCapacity > 999) getdisplay().print(float(batCapacity/1000.0), 1); + String svalueCapacity = (batCapacity <= 999) ? String(batCapacity) : String(float(batCapacity/1000.0), 1); + printBoatValue(svalueCapacity, 10, 200, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); if(batCapacity <= 999) getdisplay().print("Ah"); if(batCapacity > 999) getdisplay().print("kAh"); @@ -248,20 +249,19 @@ public: } // Show fill level in percent - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(150, 200); - getdisplay().print(batPercentage); + printBoatValue(String(batPercentage), 150, 200, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("%"); // Show time to full discharge - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(150, 260); + String svalueRange; if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){ - if(batRange < 9.9) getdisplay().print(batRange, 1); - else getdisplay().print(batRange, 0); + svalueRange = (batRange < 9.9) ? String(batRange, 1) : String(batRange, 0); } - else getdisplay().print("--"); + else{ + svalueRange = "--"; + } + printBoatValue(svalueRange, 150, 260, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("h"); @@ -282,54 +282,38 @@ public: getdisplay().print("Sensor Modul"); // Reading bus data or using simulation data - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 140); - if(simulation == true){ - if(batVoltage == "12V"){ - value1 = 12.0; - } - if(batVoltage == "24V"){ - value1 = 24.0; - } - value1 += float(random(0, 5)) / 10; // Simulation data - getdisplay().print(value1,1); - } - else{ - // Check for valid real data, display also if hold values activated - if(valid1 == true || holdvalues == true){ - // Resolution switching - if(value1 <= 9.9) getdisplay().print(value1, 2); - if(value1 > 9.9 && value1 <= 99.9)getdisplay().print(value1, 1); - if(value1 > 99.9) getdisplay().print(value1, 0); - } - else{ - getdisplay().print("---"); // Missing bus data - } + String svalue1; + // Check for valid real data, display also if hold values activated + if(valid1 == true || holdvalues == true){ + svalue1 = formatValue(value1, String("formatXdr:U:V"), *commonData); + } else { + svalue1 = "---"; // Missing bus data } + printBoatValue(svalue1, 355, 140, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("V"); // Show actual current in A - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 200); + String svalue2; if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){ - if(value2 <= 9.9) getdisplay().print(value2, 2); - if(value2 > 9.9 && value2 <= 99.9)getdisplay().print(value2, 1); - if(value2 > 99.9) getdisplay().print(value2, 0); + svalue2 = formatValue(value2, String("formatXdr:I:A"), *commonData); } - else getdisplay().print("---"); + else{ + svalue2 = "---"; + } + printBoatValue(svalue2, 355, 200, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("A"); // Show actual consumption in W - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 260); + String svalue3; if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){ - if(value3 <= 9.9) getdisplay().print(value3, 2); - if(value3 > 9.9 && value3 <= 99.9)getdisplay().print(value3, 1); - if(value3 > 99.9) getdisplay().print(value3, 0); + svalue3 = formatValue(value3, String("formatXdr:G:"), *commonData); } - else getdisplay().print("---"); + else{ + svalue3 = "---"; + } + printBoatValue(svalue3, 355, 260, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("W"); diff --git a/lib/obp60task/PageGenerator.cpp b/lib/obp60task/PageGenerator.cpp index 9f0b93e..8135193 100644 --- a/lib/obp60task/PageGenerator.cpp +++ b/lib/obp60task/PageGenerator.cpp @@ -5,6 +5,10 @@ class PageGenerator : public Page { + static constexpr int8_t LEFT = 0; + static constexpr int8_t CENTER = 1; + static constexpr int8_t RIGHT = 2; + public: PageGenerator(CommonData &common){ commonData = &common; @@ -32,6 +36,7 @@ public: int genPower = config->getInt(config->genPower); String backlightMode = config->getString(config->backlight); String powerSensor = config->getString(config->usePowSensor3); + bool smallDecimals = config->getBool(config->smallDecimals); double value1 = 0; // Solar voltage double value2 = 0; // Solar current @@ -95,20 +100,16 @@ public: getdisplay().print("Generator"); // Show voltage type - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 140); int bvoltage = 0; if(String(batVoltage) == "12V") bvoltage = 12; else bvoltage = 24; - getdisplay().print(bvoltage); + printBoatValue(String(bvoltage), 10, 140, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("V"); // Show solar power - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 200); - if(genPower <= 999) getdisplay().print(genPower, 0); - if(genPower > 999) getdisplay().print(float(genPower/1000.0), 1); + String svalueGenPower = (genPower <= 999) ? String(genPower) : String(float(genPower/1000.0), 1); + printBoatValue(svalueGenPower, 10, 200, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); if(genPower <= 999) getdisplay().print("W"); if(genPower > 999) getdisplay().print("kW"); @@ -124,9 +125,7 @@ public: generatorGraphic(200, 95, commonData->fgcolor, commonData->bgcolor); // Show load level in percent - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(150, 200); - getdisplay().print(genPercentage); + printBoatValue(String(genPercentage), 150, 200, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("%"); getdisplay().setFont(&Ubuntu_Bold8pt8b); @@ -151,54 +150,37 @@ public: getdisplay().print("Sensor Modul"); // Reading bus data or using simulation data - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 140); - if(simulation == true){ - if(batVoltage == "12V"){ - value1 = 12.0; - } - if(batVoltage == "24V"){ - value1 = 24.0; - } - value1 += float(random(0, 5)) / 10; // Simulation data - getdisplay().print(value1,1); - } - else{ - // Check for valid real data, display also if hold values activated - if(valid1 == true || holdvalues == true){ - // Resolution switching - if(value1 <= 9.9) getdisplay().print(value1, 2); - if(value1 > 9.9 && value1 <= 99.9)getdisplay().print(value1, 1); - if(value1 > 99.9) getdisplay().print(value1, 0); - } - else{ - getdisplay().print("---"); // Missing bus data - } + String svalue1; + if(valid1 == true || holdvalues == true){ + svalue1 = formatValue(value1, String("formatXdr:U:V"), *commonData); + } else { + svalue1 = "---"; // Missing bus data } + printBoatValue(svalue1, 355, 140, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("V"); // Show actual current in A - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 200); + String svalue2; if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){ - if(value2 <= 9.9) getdisplay().print(value2, 2); - if(value2 > 9.9 && value2 <= 99.9)getdisplay().print(value2, 1); - if(value2 > 99.9) getdisplay().print(value2, 0); + svalue2 = formatValue(value2, String("formatXdr:I:A"), *commonData); } - else getdisplay().print("---"); + else{ + svalue2 = "---"; + } + printBoatValue(svalue2, 355, 200, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("A"); // Show actual consumption in W - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 260); + String svalue3; if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){ - if(value3 <= 9.9) getdisplay().print(value3, 2); - if(value3 > 9.9 && value3 <= 99.9)getdisplay().print(value3, 1); - if(value3 > 99.9) getdisplay().print(value3, 0); + svalue3 = formatValue(value3, String("formatXdr:G:"), *commonData); } - else getdisplay().print("---"); + else{ + svalue3 = "---"; + } + printBoatValue(svalue3, 355, 260, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("W"); diff --git a/lib/obp60task/PageRollPitch.cpp b/lib/obp60task/PageRollPitch.cpp index 59c79dc..ff999ff 100644 --- a/lib/obp60task/PageRollPitch.cpp +++ b/lib/obp60task/PageRollPitch.cpp @@ -5,6 +5,10 @@ class PageRollPitch : public Page { + static constexpr int8_t LEFT = 0; + static constexpr int8_t CENTER = 1; + static constexpr int8_t RIGHT = 2; + public: PageRollPitch(CommonData &common){ commonData = &common; @@ -44,12 +48,15 @@ public: double rolloffset = roffset.toFloat()/360*(2*M_PI); String poffset = config->getString(config->pitchOffset); double pitchoffset = poffset.toFloat()/360*(2*M_PI); + bool smallDecimals = config->getBool(config->smallDecimals); // Get boat values for roll GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list (xdrRoll) String name1 = xdrDelete(bvalue1->getName()); // Value name - name1 = name1.substring(0, 6); // String length limit for value name + name1 = name1.substring(0, 5); // String length limit for value name bool valid1 = bvalue1->valid; // Valid information + String unit1 = formatValue(bvalue1, *commonData).unit; // Unit of value + unit1 = unit1.substring(0, 4); // String length limit for value unit if(valid1 == true){ value1 = bvalue1->value + rolloffset; // Raw value for pitch } @@ -73,8 +80,10 @@ public: // Get boat values for pitch GwApi::BoatValue *bvalue2 = pageData.values[1]; // Second element in list (xdrPitch) String name2 = xdrDelete(bvalue2->getName()); // Value name - name2 = name2.substring(0, 6); // String length limit for value name + name2 = name2.substring(0, 5); // String length limit for value name bool valid2 = bvalue2->valid; // Valid information + String unit2 = formatValue(bvalue2, *commonData).unit; // Unit of value + unit2 = unit2.substring(0, 4); // String length limit for value unit if(valid2 == true){ value2 = bvalue2->value + pitchoffset; // Raw value for pitch } @@ -86,7 +95,7 @@ public: value2 = 0; } } - if(value2/(2*PI)*360 > -10 && value2/(2*M_PI)*360 < 10){ + if(value2/(2*M_PI)*360 > -10 && value2/(2*M_PI)*360 < 10){ svalue2 = String(value2/(2*M_PI)*360,1); // Convert raw value to string } else{ @@ -121,53 +130,44 @@ public: getdisplay().setTextColor(commonData->fgcolor); // Show roll limit - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 65); - getdisplay().print(rolllimit); // Value - //getdisplay().print(svalue1); // Value + printBoatValue(String(rolllimit), 10, 65, LEFT, 20, smallDecimals); // Value getdisplay().setFont(&Ubuntu_Bold12pt8b); getdisplay().setCursor(10, 95); getdisplay().print("Limit"); // Name getdisplay().setFont(&Ubuntu_Bold8pt8b); getdisplay().setCursor(10, 115); - getdisplay().print("DEG"); + getdisplay().print("Deg"); // Horizintal separator left getdisplay().fillRect(0, 149, 60, 3, commonData->fgcolor); // Show roll value - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 270); - if(holdvalues == false) getdisplay().print(svalue1); // Value - else getdisplay().print(svalue1old); + if(holdvalues == false) printBoatValue(svalue1, 101, 270, RIGHT, 20, smallDecimals); // Value + else printBoatValue(svalue1old, 101, 270, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold12pt8b); getdisplay().setCursor(10, 220); getdisplay().print(name1); // Name getdisplay().setFont(&Ubuntu_Bold8pt8b); getdisplay().setCursor(10, 190); - getdisplay().print("Deg"); + getdisplay().print(unit1); // Unit // Horizintal separator right getdisplay().fillRect(340, 149, 80, 3, commonData->fgcolor); // Show pitch value - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(295, 270); - if(holdvalues == false) getdisplay().print(svalue2); // Value - else getdisplay().print(svalue2old); + if(holdvalues == false) printBoatValue(svalue2, 395, 270, RIGHT, 20, smallDecimals); // Value + else printBoatValue(svalue2old, 395, 270, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold12pt8b); - getdisplay().setCursor(335, 220); - getdisplay().print(name2); // Name + drawTextRalign(395, 220, name2); // Name getdisplay().setFont(&Ubuntu_Bold8pt8b); getdisplay().setCursor(335, 190); - getdisplay().print("Deg"); + getdisplay().print(unit2); // Unit //******************************************************************************************* // Draw instrument int rInstrument = 100; // Radius of instrument - float pi = 3.141592; getdisplay().fillCircle(200, 150, rInstrument + 10, commonData->fgcolor); // Outer circle getdisplay().fillCircle(200, 150, rInstrument + 7, commonData->bgcolor); // Outer circle @@ -264,11 +264,11 @@ public: int y0 = 150; int x1 = x0 + 50*cos(value1); int y1 = y0 + 50*sin(value1); - int x2 = x0 + 50*cos(value1 - pi/2); - int y2 = y0 + 50*sin(value1 - pi/2); + int x2 = x0 + 50*cos(value1 - M_PI/2); + int y2 = y0 + 50*sin(value1 - M_PI/2); getdisplay().fillTriangle(x0, y0, x1, y1, x2, y2, commonData->bgcolor); // Clear half top side of boat circle (right triangle) - x1 = x0 + 50*cos(value1 + pi); - y1 = y0 + 50*sin(value1 + pi); + x1 = x0 + 50*cos(value1 + M_PI); + y1 = y0 + 50*sin(value1 + M_PI); getdisplay().fillTriangle(x0, y0, x1, y1, x2, y2, commonData->bgcolor); // Clear half top side of boat circle (left triangle) getdisplay().fillRect(150, 160, 100, 4, commonData->fgcolor); // Water line diff --git a/lib/obp60task/PageSolar.cpp b/lib/obp60task/PageSolar.cpp index 4fd20a5..5120ea6 100644 --- a/lib/obp60task/PageSolar.cpp +++ b/lib/obp60task/PageSolar.cpp @@ -5,6 +5,10 @@ class PageSolar : public Page { + static constexpr int8_t LEFT = 0; + static constexpr int8_t CENTER = 1; + static constexpr int8_t RIGHT = 2; + public: PageSolar(CommonData &common){ commonData = &common; @@ -31,6 +35,7 @@ public: int solPower = config->getInt(config->solarPower); String backlightMode = config->getString(config->backlight); String powerSensor = config->getString(config->usePowSensor2); + bool smallDecimals = config->getBool(config->smallDecimals); double value1 = 0; // Solar voltage double value2 = 0; // Solar current @@ -91,20 +96,16 @@ public: getdisplay().print("Solar"); // Show voltage type - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 140); int bvoltage = 0; if(String(batVoltage) == "12V") bvoltage = 12; else bvoltage = 24; - getdisplay().print(bvoltage); + printBoatValue(String(bvoltage), 10, 140, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("V"); // Show solar power - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(10, 200); - if(solPower <= 999) getdisplay().print(solPower, 0); - if(solPower > 999) getdisplay().print(float(solPower/1000.0), 1); + String svalueSolPower = (solPower <= 999) ? String(solPower) : String(float(solPower/1000.0), 1); + printBoatValue(svalueSolPower, 10, 200, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); if(solPower <= 999) getdisplay().print("W"); if(solPower > 999) getdisplay().print("kW"); @@ -120,9 +121,7 @@ public: solarGraphic(150, 45, commonData->fgcolor, commonData->bgcolor); // Show load level in percent - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(150, 200); - getdisplay().print(solPercentage); + printBoatValue(String(solPercentage), 150, 200, LEFT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("%"); getdisplay().setFont(&Ubuntu_Bold8pt8b); @@ -147,54 +146,37 @@ public: getdisplay().print("Sensor Modul"); // Reading bus data or using simulation data - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 140); - if(simulation == true){ - if(batVoltage == "12V"){ - value1 = 12.0; - } - if(batVoltage == "24V"){ - value1 = 24.0; - } - value1 += float(random(0, 5)) / 10; // Simulation data - getdisplay().print(value1,1); - } - else{ - // Check for valid real data, display also if hold values activated - if(valid1 == true || holdvalues == true){ - // Resolution switching - if(value1 <= 9.9) getdisplay().print(value1, 2); - if(value1 > 9.9 && value1 <= 99.9)getdisplay().print(value1, 1); - if(value1 > 99.9) getdisplay().print(value1, 0); - } - else{ - getdisplay().print("---"); // Missing bus data - } + String svalue1; + if(valid1 == true || holdvalues == true){ + svalue1 = formatValue(value1, String("formatXdr:U:V"), *commonData); + } else { + svalue1 = "---"; // Missing bus data } + printBoatValue(svalue1, 355, 140, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("V"); // Show actual current in A - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 200); + String svalue2; if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){ - if(value2 <= 9.9) getdisplay().print(value2, 2); - if(value2 > 9.9 && value2 <= 99.9)getdisplay().print(value2, 1); - if(value2 > 99.9) getdisplay().print(value2, 0); + svalue2 = formatValue(value2, String("formatXdr:I:A"), *commonData); } - else getdisplay().print("---"); + else{ + svalue2 = "---"; + } + printBoatValue(svalue2, 355, 200, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("A"); // Show actual consumption in W - getdisplay().setFont(&DSEG7Classic_BoldItalic20pt7b); - getdisplay().setCursor(260, 260); + String svalue3; if((powerSensor == "INA219" || powerSensor == "INA226") && simulation == false){ - if(value3 <= 9.9) getdisplay().print(value3, 2); - if(value3 > 9.9 && value3 <= 99.9)getdisplay().print(value3, 1); - if(value3 > 99.9) getdisplay().print(value3, 0); + svalue3 = formatValue(value3, String("formatXdr:G:"), *commonData); } - else getdisplay().print("---"); + else{ + svalue3 = "---"; + } + printBoatValue(svalue3, 355, 260, RIGHT, 20, smallDecimals); getdisplay().setFont(&Ubuntu_Bold16pt8b); getdisplay().print("W");