mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-09-11 19:55:14 +02:00
OBPFormatter(): make precision selectable regardless of user setting
This commit is contained in:
@@ -50,15 +50,10 @@ String formatLongitude(double lon) {
|
|||||||
return String(degree, 0) + "\x90 " + String(minute, 4) + "' " + ((lon > 0) ? "E" : "W");
|
return String(degree, 0) + "\x90 " + String(minute, 4) + "' " + ((lon > 0) ? "E" : "W");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert and format boat value from SI to user defined format (definition for compatibility purposes)
|
|
||||||
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata) {
|
|
||||||
|
|
||||||
return formatValue(value, commondata, false); // call <formatValue> with standard handling of user setting for simulation data
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert and format boat value from SI to user defined format
|
// Convert and format boat value from SI to user defined format
|
||||||
// generate random simulation data; can be deselected to use conversion+formatting function even in simulation mode
|
// generates random simulation data; can be deselected to use conversion+formatting function even in simulation mode
|
||||||
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool ignoreSimuDataSetting){
|
// String setPrecision - overrides precision setting from config; if not set, use config setting
|
||||||
|
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool ignoreSimuDataSetting, String setPrecision) {
|
||||||
GwLog *logger = commondata.logger;
|
GwLog *logger = commondata.logger;
|
||||||
FormattedData result;
|
FormattedData result;
|
||||||
static int dayoffset = 0;
|
static int dayoffset = 0;
|
||||||
@@ -76,12 +71,13 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
|||||||
String tempFormat = commondata.config->getString(commondata.config->tempFormat); // [K|°C|°F]
|
String tempFormat = commondata.config->getString(commondata.config->tempFormat); // [K|°C|°F]
|
||||||
String dateFormat = commondata.config->getString(commondata.config->dateFormat); // [DE|GB|US]
|
String dateFormat = commondata.config->getString(commondata.config->dateFormat); // [DE|GB|US]
|
||||||
String precision = commondata.config->getString(commondata.config->valueprecision); // [1|2]
|
String precision = commondata.config->getString(commondata.config->valueprecision); // [1|2]
|
||||||
|
bool usesimudata = commondata.config->getBool(commondata.config->useSimuData); // [on|off]
|
||||||
|
|
||||||
bool usesimudata;
|
if (setPrecision == "1" || setPrecision == "2") {
|
||||||
|
precision = setPrecision; // override precision setting from config
|
||||||
|
}
|
||||||
if (ignoreSimuDataSetting){
|
if (ignoreSimuDataSetting){
|
||||||
usesimudata = false; // ignore user setting for simulation data; we want to format the boat value passed to this function
|
usesimudata = false; // ignore user setting for simulation data; we want to format the boat value passed to this function
|
||||||
} else {
|
|
||||||
usesimudata = commondata.config->getBool(commondata.config->useSimuData); // [on|off]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If boat value not valid
|
// If boat value not valid
|
||||||
@@ -216,7 +212,7 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
|||||||
rawvalue = value->value;
|
rawvalue = value->value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
course = M_PI_2 + float(random(-17, 17) / 100.0); // create random course/wind values with 90° +/- 10°
|
course = M_PI_2 + float(random(-26, 26) / 100.0); // create random course/wind values with 90° +/- 15°
|
||||||
rawvalue = course;
|
rawvalue = course;
|
||||||
}
|
}
|
||||||
course = WindUtils::to360(course * RAD_TO_DEG); // Unit conversion form rad to deg
|
course = WindUtils::to360(course * RAD_TO_DEG); // Unit conversion form rad to deg
|
||||||
@@ -908,6 +904,24 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert and format boat value from SI to user defined format
|
||||||
|
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata) {
|
||||||
|
|
||||||
|
return formatValue(value, commondata, false, String("-1")); // call <formatValue> with standard setting for simulation data and precision setting from config
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert and format boat value from SI to user defined format with simulation data setting and precision setting from config
|
||||||
|
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool ignoreSimuDataSetting) {
|
||||||
|
|
||||||
|
return formatValue(value, commondata, ignoreSimuDataSetting, String("-1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert and format boat value from SI to user defined format with standard setting for simulation data and specified precision
|
||||||
|
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, String setPrecision) {
|
||||||
|
|
||||||
|
return formatValue(value, commondata, false, setPrecision);
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user