enable PageVoltage for small decimals; add formatValue overload to OBP60Formatter

This commit is contained in:
Ulrich Meine
2026-09-01 21:53:09 +02:00
parent 6c318d5a69
commit 3dd13ae899
3 changed files with 30 additions and 33 deletions
+16
View File
@@ -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)
{
+7 -28
View File
@@ -11,6 +11,10 @@ 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){
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){
+2
View File
@@ -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);