From 3dd13ae899ab506d4b1fc979310d68185eb60ea7 Mon Sep 17 00:00:00 2001 From: Ulrich Meine Date: Tue, 1 Sep 2026 21:53:09 +0200 Subject: [PATCH] enable PageVoltage for small decimals; add formatValue overload to OBP60Formatter --- lib/obp60task/OBP60Formatter.cpp | 16 ++++++++++++ lib/obp60task/PageVoltage.cpp | 45 +++++++++----------------------- lib/obp60task/Pagedata.h | 2 ++ 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/lib/obp60task/OBP60Formatter.cpp b/lib/obp60task/OBP60Formatter.cpp index ddc4712..c6ddda2 100644 --- a/lib/obp60task/OBP60Formatter.cpp +++ b/lib/obp60task/OBP60Formatter.cpp @@ -922,6 +922,22 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, Strin return formatValue(value, commondata, false, setPrecision); } +// Format double value from SI to user defined format and convert to string user defined precision setting +String formatValue(const double &value, const String &vFormat, CommonData &commondata) +{ + GwApi::BoatValue tmpBVal("dummy"); // temporary boat value for string formatter + String sVal; + + tmpBVal.setFormat(vFormat); + tmpBVal.valid = true; + tmpBVal.value = value; + sVal = formatValue(&tmpBVal, commondata, false, String("-1")).svalue; // Formatted value as string including unit conversion and switching decimal places + if (sVal.length() > 0 && sVal[0] == '!') { + sVal = sVal.substring(1); // cut leading "!" created at OBPFormatter; doesn't work for other fonts than 7SEG + } + return sVal; +} + // Helper method for conversion of any data value from SI to user defined format double convertValue(const double &value, const String &name, const String &format, CommonData &commondata) { diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp index de467ba..000bc88 100644 --- a/lib/obp60task/PageVoltage.cpp +++ b/lib/obp60task/PageVoltage.cpp @@ -5,11 +5,15 @@ class PageVoltage : public Page { -bool init = false; // Marker for init done -uint8_t 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 -double raw = 0; -char mode = 'D'; // display mode (A)nalog | (D)igital + bool init = false; // Marker for init done + uint8_t 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 + double raw = 0; + char mode = 'D'; // display mode (A)nalog | (D)igital + + static constexpr int8_t LEFT = 0; + static constexpr int8_t CENTER = 1; + static constexpr int8_t RIGHT = 2; public: PageVoltage(CommonData &common){ @@ -110,6 +114,7 @@ public: String batVoltage = config->getString(config->batteryVoltage); String batType = config->getString(config->batteryType); String backlightMode = config->getString(config->backlight); + bool smallDecimals = config->getBool(config->smallDecimals); double value1 = 0; double valueTrend = 0; // Average over 10 values @@ -236,34 +241,8 @@ public: // Reading bus data or using simulation data getdisplay().setFont(&DSEG7Classic_BoldItalic60pt7b); getdisplay().setCursor(20, 240); - 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 < 10){ - getdisplay().print(value1,2); - } - if(value1 >= 10 && value1 < 100){ - getdisplay().print(value1,1); - } - if(value1 >= 100){ - getdisplay().print(value1,0); - } - } - else{ - getdisplay().print("---"); // Missing bus data - } - } + String sValue = formatValue(value1, String("formatXdr:U:V"), *commonData); + printBoatValue(sValue, 300, 240, RIGHT, 60, smallDecimals); // Show trend indicator if(trend == true){ diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 0fcb304..aa096df 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -205,6 +205,8 @@ typedef struct{ // Formatter for boat values FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata); FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool ignoreSimuDataSetting); +FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, String setPrecision); +String formatValue(const double &value, const String &vFormat, CommonData &commondata); // Helper method for conversion of any data value from SI to user defined format (defined in OBP60Formatter) double convertValue(const double &value, const String &format, CommonData &commondata);