mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-09-11 19:55:14 +02:00
enable PageVoltage for small decimals; add formatValue overload to OBP60Formatter
This commit is contained in:
@@ -922,6 +922,22 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, Strin
|
|||||||
return formatValue(value, commondata, false, setPrecision);
|
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
|
// 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)
|
double convertValue(const double &value, const String &name, const String &format, CommonData &commondata)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,11 +5,15 @@
|
|||||||
|
|
||||||
class PageVoltage : public Page
|
class PageVoltage : public Page
|
||||||
{
|
{
|
||||||
bool init = false; // Marker for init done
|
bool init = false; // Marker for init done
|
||||||
uint8_t average = 0; // Average type [0...3], 0=off, 1=10s, 2=60s, 3=300s
|
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
|
bool trend = true; // Trend indicator [0|1], 0=off, 1=on
|
||||||
double raw = 0;
|
double raw = 0;
|
||||||
char mode = 'D'; // display mode (A)nalog | (D)igital
|
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:
|
public:
|
||||||
PageVoltage(CommonData &common){
|
PageVoltage(CommonData &common){
|
||||||
@@ -110,6 +114,7 @@ public:
|
|||||||
String batVoltage = config->getString(config->batteryVoltage);
|
String batVoltage = config->getString(config->batteryVoltage);
|
||||||
String batType = config->getString(config->batteryType);
|
String batType = config->getString(config->batteryType);
|
||||||
String backlightMode = config->getString(config->backlight);
|
String backlightMode = config->getString(config->backlight);
|
||||||
|
bool smallDecimals = config->getBool(config->smallDecimals);
|
||||||
|
|
||||||
double value1 = 0;
|
double value1 = 0;
|
||||||
double valueTrend = 0; // Average over 10 values
|
double valueTrend = 0; // Average over 10 values
|
||||||
@@ -236,34 +241,8 @@ public:
|
|||||||
// Reading bus data or using simulation data
|
// Reading bus data or using simulation data
|
||||||
getdisplay().setFont(&DSEG7Classic_BoldItalic60pt7b);
|
getdisplay().setFont(&DSEG7Classic_BoldItalic60pt7b);
|
||||||
getdisplay().setCursor(20, 240);
|
getdisplay().setCursor(20, 240);
|
||||||
if(simulation == true){
|
String sValue = formatValue(value1, String("formatXdr:U:V"), *commonData);
|
||||||
if(batVoltage == "12V"){
|
printBoatValue(sValue, 300, 240, RIGHT, 60, smallDecimals);
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show trend indicator
|
// Show trend indicator
|
||||||
if(trend == true){
|
if(trend == true){
|
||||||
|
|||||||
@@ -205,6 +205,8 @@ typedef struct{
|
|||||||
// Formatter for boat values
|
// Formatter for boat values
|
||||||
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata);
|
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata);
|
||||||
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool ignoreSimuDataSetting);
|
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)
|
// 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);
|
double convertValue(const double &value, const String &format, CommonData &commondata);
|
||||||
|
|||||||
Reference in New Issue
Block a user