Added config option for display precision and formatter code improvements

This commit is contained in:
Thomas Hooge 2025-07-29 21:50:14 +02:00
parent fb3af0bf83
commit eb51092b23
3 changed files with 265 additions and 218 deletions

View File

@ -65,13 +65,27 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
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]
bool usesimudata = commondata.config->getBool(commondata.config->useSimuData); // [on|off] bool usesimudata = commondata.config->getBool(commondata.config->useSimuData); // [on|off]
String precision = commondata.config->getString(commondata.config->valueprecision); // [1|2]
// If boat value not valid // If boat value not valid
if (! value->valid && !usesimudata){ if (! value->valid && !usesimudata){
result.svalue = "---"; result.svalue = "---";
return result; return result;
} }
const char* fmt_dec_1;
const char* fmt_dec_10;
const char* fmt_dec_100;
if (precision == "1") {
fmt_dec_1 = "%3.1f";
fmt_dec_10 = "%3.0f";
fmt_dec_100 = "%3.0f";
} else {
fmt_dec_1 = "%3.2f";
fmt_dec_10 = "%3.1f";
fmt_dec_100 = "%3.0f";
}
// LOG_DEBUG(GwLog::DEBUG,"formatValue init: getFormat: %s date->value: %f time->value: %f", value->getFormat(), commondata.date->value, commondata.time->value); // LOG_DEBUG(GwLog::DEBUG,"formatValue init: getFormat: %s date->value: %f time->value: %f", value->getFormat(), commondata.date->value, commondata.time->value);
static const int bsize = 30; static const int bsize = 30;
char buffer[bsize+1]; char buffer[bsize+1];
@ -91,25 +105,25 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
tmElements_t parts; tmElements_t parts;
time_t tv=tNMEA0183Msg::daysToTime_t(value->value + dayoffset); time_t tv=tNMEA0183Msg::daysToTime_t(value->value + dayoffset);
tNMEA0183Msg::breakTime(tv,parts); tNMEA0183Msg::breakTime(tv,parts);
if(usesimudata == false) { if (usesimudata == false) {
if(String(dateFormat) == "DE"){ if (String(dateFormat) == "DE") {
snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); snprintf(buffer,bsize, "%02d.%02d.%04d", parts.tm_mday, parts.tm_mon+1, parts.tm_year+1900);
} }
else if(String(dateFormat) == "GB"){ else if(String(dateFormat) == "GB") {
snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); snprintf(buffer, bsize, "%02d/%02d/%04d", parts.tm_mday, parts.tm_mon+1, parts.tm_year+1900);
} }
else if(String(dateFormat) == "US"){ else if(String(dateFormat) == "US") {
snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mon+1,parts.tm_mday,parts.tm_year+1900); snprintf(buffer, bsize, "%02d/%02d/%04d", parts.tm_mon+1, parts.tm_mday, parts.tm_year+1900);
} }
else if(String(dateFormat) == "ISO"){ else if(String(dateFormat) == "ISO") {
snprintf(buffer,bsize,"%04d-%02d-%02d",parts.tm_year+1900,parts.tm_mon+1,parts.tm_mday); snprintf(buffer, bsize, "%04d-%02d-%02d", parts.tm_year+1900, parts.tm_mon+1, parts.tm_mday);
} }
else{ else {
snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900); snprintf(buffer, bsize, "%02d.%02d.%04d", parts.tm_mday, parts.tm_mon+1, parts.tm_year+1900);
} }
} }
else{ else{
snprintf(buffer,bsize,"01.01.2022"); snprintf(buffer, bsize, "01.01.2022");
} }
if(timeZone == 0){ if(timeZone == 0){
result.unit = "UTC"; result.unit = "UTC";
@ -130,11 +144,11 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
if (timeInSeconds > 86400) {timeInSeconds = timeInSeconds - 86400;} if (timeInSeconds > 86400) {timeInSeconds = timeInSeconds - 86400;}
if (timeInSeconds < 0) {timeInSeconds = timeInSeconds + 86400;} if (timeInSeconds < 0) {timeInSeconds = timeInSeconds + 86400;}
// LOG_DEBUG(GwLog::DEBUG,"... formatTime value: %f tz: %f corrected timeInSeconds: %f ", value->value, timeZone, timeInSeconds); // LOG_DEBUG(GwLog::DEBUG,"... formatTime value: %f tz: %f corrected timeInSeconds: %f ", value->value, timeZone, timeInSeconds);
if(usesimudata == false) { if (usesimudata == false) {
val=modf(timeInSeconds/3600.0,&inthr); val = modf(timeInSeconds/3600.0, &inthr);
val=modf(val*3600.0/60.0,&intmin); val = modf(val*3600.0/60.0, &intmin);
modf(val*60.0,&intsec); modf(val*60.0,&intsec);
snprintf(buffer,bsize,"%02.0f:%02.0f:%02.0f",inthr,intmin,intsec); snprintf(buffer, bsize, "%02.0f:%02.0f:%02.0f", inthr, intmin, intsec);
} }
else{ else{
static long sec; static long sec;
@ -143,7 +157,7 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
sec ++; sec ++;
} }
sec = sec % 60; sec = sec % 60;
snprintf(buffer,bsize,"11:36:%02i", int(sec)); snprintf(buffer, bsize, "11:36:%02i", int(sec));
lasttime = millis(); lasttime = millis();
} }
if(timeZone == 0){ if(timeZone == 0){
@ -156,26 +170,26 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
//######################################################## //########################################################
else if (value->getFormat() == "formatFixed0"){ else if (value->getFormat() == "formatFixed0"){
if(usesimudata == false) { if(usesimudata == false) {
snprintf(buffer,bsize,"%3.0f",value->value); snprintf(buffer, bsize, "%3.0f", value->value);
rawvalue = value->value; rawvalue = value->value;
} }
else{ else{
rawvalue = 8.0 + float(random(0, 10)) / 10.0; rawvalue = 8.0 + float(random(0, 10)) / 10.0;
snprintf(buffer,bsize,"%3.0f", rawvalue); snprintf(buffer, bsize, "%3.0f", rawvalue);
} }
result.unit = ""; result.unit = "";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatCourse" || value->getFormat() == "formatWind"){ else if (value->getFormat() == "formatCourse" || value->getFormat() == "formatWind"){
double course = 0; double course = 0;
if(usesimudata == false) { if (usesimudata == false) {
course = value->value; course = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
course = 2.53 + float(random(0, 10) / 100.0); course = 2.53 + float(random(0, 10) / 100.0);
rawvalue = course; rawvalue = course;
} }
course = course * 57.2958; // Unit conversion form rad to deg course = course * 57.2958; // Unit conversion form rad to deg
// Format 3 numbers with prefix zero // Format 3 numbers with prefix zero
@ -185,7 +199,7 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
//######################################################## //########################################################
else if (value->getFormat() == "formatKnots" && (value->getName() == "SOG" || value->getName() == "STW")){ else if (value->getFormat() == "formatKnots" && (value->getName() == "SOG" || value->getName() == "STW")){
double speed = 0; double speed = 0;
if(usesimudata == false) { if (usesimudata == false) {
speed = value->value; speed = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
@ -193,85 +207,85 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rawvalue = 4.0 + float(random(0, 40)); rawvalue = 4.0 + float(random(0, 40));
speed = rawvalue; speed = rawvalue;
} }
if(String(speedFormat) == "km/h"){ if (String(speedFormat) == "km/h"){
speed = speed * 3.6; // Unit conversion form m/s to km/h speed = speed * 3.6; // Unit conversion form m/s to km/h
result.unit = "km/h"; result.unit = "km/h";
} }
else if(String(speedFormat) == "kn"){ else if (String(speedFormat) == "kn"){
speed = speed * 1.94384; // Unit conversion form m/s to kn speed = speed * 1.94384; // Unit conversion form m/s to kn
result.unit = "kn"; result.unit = "kn";
} }
else{ else {
speed = speed; // Unit conversion form m/s to m/s speed = speed; // Unit conversion form m/s to m/s
result.unit = "m/s"; result.unit = "m/s";
} }
if(speed < 10){ if(speed < 10) {
snprintf(buffer,bsize,"%3.2f",speed); snprintf(buffer, bsize, fmt_dec_1, speed);
} }
if(speed >= 10 && speed < 100){ else if (speed < 100) {
snprintf(buffer,bsize,"%3.1f",speed); snprintf(buffer, bsize, fmt_dec_10, speed);
} }
if(speed >= 100){ else {
snprintf(buffer,bsize,"%3.0f",speed); snprintf(buffer, bsize, fmt_dec_100, speed);
} }
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatKnots" && (value->getName() == "AWS" || value->getName() == "TWS" || value->getName() == "MaxAws" || value->getName() == "MaxTws")){ else if (value->getFormat() == "formatKnots" && (value->getName() == "AWS" || value->getName() == "TWS" || value->getName() == "MaxAws" || value->getName() == "MaxTws")){
double speed = 0; double speed = 0;
if(usesimudata == false) { if (usesimudata == false) {
speed = value->value; speed = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 4.0 + float(random(0, 40)); rawvalue = 4.0 + float(random(0, 40));
speed = rawvalue; speed = rawvalue;
} }
if(String(windspeedFormat) == "km/h"){ if (String(windspeedFormat) == "km/h"){
speed = speed * 3.6; // Unit conversion form m/s to km/h speed = speed * 3.6; // Unit conversion form m/s to km/h
result.unit = "km/h"; result.unit = "km/h";
} }
else if(String(windspeedFormat) == "kn"){ else if (String(windspeedFormat) == "kn"){
speed = speed * 1.94384; // Unit conversion form m/s to kn speed = speed * 1.94384; // Unit conversion form m/s to kn
result.unit = "kn"; result.unit = "kn";
} }
else if(String(windspeedFormat) == "bft"){ else if(String(windspeedFormat) == "bft"){
if(speed < 0.3){ if (speed < 0.3) {
speed = 0; speed = 0;
} }
if(speed >=0.3 && speed < 1.5){ else if (speed < 1.5) {
speed = 1; speed = 1;
} }
if(speed >=1.5 && speed < 3.3){ else if (speed < 3.3) {
speed = 2; speed = 2;
} }
if(speed >=3.3 && speed < 5.4){ else if (speed < 5.4) {
speed = 3; speed = 3;
} }
if(speed >=5.4 && speed < 7.9){ else if (speed < 7.9) {
speed = 4; speed = 4;
} }
if(speed >=7.9 && speed < 10.7){ else if (speed < 10.7) {
speed = 5; speed = 5;
} }
if(speed >=10.7 && speed < 13.8){ else if (speed < 13.8) {
speed = 6; speed = 6;
} }
if(speed >=13.8 && speed < 17.1){ else if (speed < 17.1) {
speed = 7; speed = 7;
} }
if(speed >=17.1 && speed < 20.7){ else if (speed < 20.7) {
speed = 8; speed = 8;
} }
if(speed >=20.7 && speed < 24.4){ else if (speed < 24.4) {
speed = 9; speed = 9;
} }
if(speed >=24.4 && speed < 28.4){ else if (speed < 28.4) {
speed = 10; speed = 10;
} }
if(speed >=28.4 && speed < 32.6){ else if (speed < 32.6) {
speed = 11; speed = 11;
} }
if(speed >=32.6){ else {
speed = 12; speed = 12;
} }
result.unit = "bft"; result.unit = "bft";
@ -280,82 +294,85 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
speed = speed; // Unit conversion form m/s to m/s speed = speed; // Unit conversion form m/s to m/s
result.unit = "m/s"; result.unit = "m/s";
} }
if(String(windspeedFormat) == "bft"){ if (String(windspeedFormat) == "bft"){
snprintf(buffer,bsize,"%2.0f",speed); snprintf(buffer, bsize, "%2.0f", speed);
} }
else{ else{
if(speed < 10){ if (speed < 10){
snprintf(buffer,bsize,"%3.2f",speed); snprintf(buffer, bsize, fmt_dec_1, speed);
} }
if(speed >= 10 && speed < 100){ else if (speed < 100){
snprintf(buffer,bsize,"%3.1f",speed); snprintf(buffer, bsize, fmt_dec_10, speed);
} }
if(speed >= 100){ else {
snprintf(buffer,bsize,"%3.0f",speed); snprintf(buffer, bsize, fmt_dec_100, speed);
} }
} }
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatRot"){ else if (value->getFormat() == "formatRot"){
double rotation = 0; double rotation = 0;
if(usesimudata == false) { if (usesimudata == false) {
rotation = value->value; rotation = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 0.04 + float(random(0, 10)) / 100.0; rawvalue = 0.04 + float(random(0, 10)) / 100.0;
rotation = rawvalue; rotation = rawvalue;
} }
rotation = rotation * 57.2958; // Unit conversion form rad/s to deg/s rotation = rotation * 57.2958; // Unit conversion form rad/s to deg/s
result.unit = "Deg/s"; result.unit = "Deg/s";
if(rotation < -100){ if (rotation < -100){
rotation = -99; rotation = -99;
} }
if(rotation > 100){ if (rotation > 100){
rotation = 99; rotation = 99;
} }
if(rotation > -10 && rotation < 10){ if (rotation > -10 && rotation < 10){
snprintf(buffer,bsize,"%3.2f",rotation); snprintf(buffer, bsize, "%3.2f", rotation);
} }
if(rotation <= -10 || rotation >= 10){ if (rotation <= -10 || rotation >= 10){
snprintf(buffer,bsize,"%3.0f",rotation); snprintf(buffer, bsize, "%3.0f", rotation);
} }
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatDop"){ else if (value->getFormat() == "formatDop"){
double dop = 0; double dop = 0;
if(usesimudata == false) { if (usesimudata == false) {
dop = value->value; dop = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 2.0 + float(random(0, 40)) / 10.0; rawvalue = 2.0 + float(random(0, 40)) / 10.0;
dop = rawvalue; dop = rawvalue;
} }
result.unit = "m"; result.unit = "m";
if(dop > 99.9){ if (dop > 99.9){
dop = 99.9; dop = 99.9;
} }
if(dop < 10){ if (dop < 10){
snprintf(buffer,bsize,"%3.2f",dop); snprintf(buffer, bsize, fmt_dec_1, dop);
} }
if(dop >= 10 && dop < 100){ else if(dop < 100){
snprintf(buffer,bsize,"%3.1f",dop); snprintf(buffer, bsize, fmt_dec_10, dop);
}
else {
snprintf(buffer, bsize, fmt_dec_100, dop);
} }
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatLatitude"){ else if (value->getFormat() == "formatLatitude"){
if(usesimudata == false) { if (usesimudata == false) {
double lat = value->value; double lat = value->value;
rawvalue = value->value; rawvalue = value->value;
String latitude = ""; String latitude = "";
String latdir = ""; String latdir = "";
float degree = abs(int(lat)); float degree = abs(int(lat));
float minute = abs((lat - int(lat)) * 60); float minute = abs((lat - int(lat)) * 60);
if(lat > 0){ if (lat > 0){
latdir = "N"; latdir = "N";
} }
else{ else {
latdir = "S"; latdir = "S";
} }
latitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + latdir; latitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + latdir;
@ -364,41 +381,41 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
} }
else{ else{
rawvalue = 35.0 + float(random(0, 10)) / 10000.0; rawvalue = 35.0 + float(random(0, 10)) / 10000.0;
snprintf(buffer,bsize," 51\" %2.4f' N", rawvalue); snprintf(buffer, bsize, " 51\" %2.4f' N", rawvalue);
} }
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatLongitude"){ else if (value->getFormat() == "formatLongitude"){
if(usesimudata == false) { if (usesimudata == false) {
double lon = value->value; double lon = value->value;
rawvalue = value->value; rawvalue = value->value;
String longitude = ""; String longitude = "";
String londir = ""; String londir = "";
float degree = abs(int(lon)); float degree = abs(int(lon));
float minute = abs((lon - int(lon)) * 60); float minute = abs((lon - int(lon)) * 60);
if(lon > 0){ if (lon > 0){
londir = "E"; londir = "E";
} }
else{ else {
londir = "W"; londir = "W";
} }
longitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + londir; longitude = String(degree,0) + "\x90 " + String(minute,4) + "' " + londir;
result.unit = ""; result.unit = "";
strcpy(buffer, longitude.c_str()); strcpy(buffer, longitude.c_str());
} }
else{ else {
rawvalue = 6.0 + float(random(0, 10)) / 100000.0; rawvalue = 6.0 + float(random(0, 10)) / 100000.0;
snprintf(buffer,bsize," 15\" %2.4f'", rawvalue); snprintf(buffer, bsize, " 15\" %2.4f'", rawvalue);
} }
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatDepth"){ else if (value->getFormat() == "formatDepth"){
double depth = 0; double depth = 0;
if(usesimudata == false) { if (usesimudata == false) {
depth = value->value; depth = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 18.0 + float(random(0, 100)) / 10.0; rawvalue = 18.0 + float(random(0, 100)) / 10.0;
depth = rawvalue; depth = rawvalue;
} }
@ -409,14 +426,14 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
else{ else{
result.unit = "m"; result.unit = "m";
} }
if(depth < 10){ if (depth < 10) {
snprintf(buffer,bsize,"%3.2f",depth); snprintf(buffer, bsize, fmt_dec_1, depth);
} }
if(depth >= 10 && depth < 100){ else if (depth < 100){
snprintf(buffer,bsize,"%3.1f",depth); snprintf(buffer, bsize, fmt_dec_10, depth);
} }
if(depth >= 100){ else {
snprintf(buffer,bsize,"%3.0f",depth); snprintf(buffer, bsize, fmt_dec_100, depth);
} }
} }
//######################################################## //########################################################
@ -430,50 +447,50 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
xte = rawvalue; xte = rawvalue;
} }
if (xte >= 100) { if (xte >= 100) {
snprintf(buffer,bsize,"%3.0f",value->value); snprintf(buffer, bsize, fmt_dec_100, value->value);
} else if (xte >= 10) { } else if (xte >= 10) {
snprintf(buffer,bsize,"%3.1f",value->value); snprintf(buffer, bsize, fmt_dec_10, value->value);
} else { } else {
snprintf(buffer,bsize,"%3.2f",value->value); snprintf(buffer, bsize, fmt_dec_1, value->value);
} }
result.unit = "nm"; result.unit = "nm";
} }
//######################################################## //########################################################
else if (value->getFormat() == "kelvinToC"){ else if (value->getFormat() == "kelvinToC"){
double temp = 0; double temp = 0;
if(usesimudata == false) { if (usesimudata == false) {
temp = value->value; temp = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 296.0 + float(random(0, 10)) / 10.0; rawvalue = 296.0 + float(random(0, 10)) / 10.0;
temp = rawvalue; temp = rawvalue;
} }
if(String(tempFormat) == "C"){ if (String(tempFormat) == "C") {
temp = temp - 273.15; temp = temp - 273.15;
result.unit = "C"; result.unit = "C";
} }
else if(String(tempFormat) == "F"){ else if (String(tempFormat) == "F") {
temp = (temp - 273.15) * 9 / 5 + 32; temp = (temp - 273.15) * 9 / 5 + 32;
result.unit = "F"; result.unit = "F";
} }
else{ else{
result.unit = "K"; result.unit = "K";
} }
if(temp < 10){ if(temp < 10) {
snprintf(buffer,bsize,"%3.2f",temp); snprintf(buffer, bsize, fmt_dec_1, temp);
} }
if(temp >= 10 && temp < 100){ else if (temp < 100) {
snprintf(buffer,bsize,"%3.1f",temp); snprintf(buffer, bsize, fmt_dec_10, temp);
} }
if(temp >= 100){ else {
snprintf(buffer,bsize,"%3.0f",temp); snprintf(buffer, bsize, fmt_dec_100, temp);
} }
} }
//######################################################## //########################################################
else if (value->getFormat() == "mtr2nm"){ else if (value->getFormat() == "mtr2nm"){
double distance = 0; double distance = 0;
if(usesimudata == false) { if (usesimudata == false) {
distance = value->value; distance = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
@ -481,25 +498,25 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rawvalue = 2960.0 + float(random(0, 10)); rawvalue = 2960.0 + float(random(0, 10));
distance = rawvalue; distance = rawvalue;
} }
if(String(distanceFormat) == "km"){ if (String(distanceFormat) == "km") {
distance = distance * 0.001; distance = distance * 0.001;
result.unit = "km"; result.unit = "km";
} }
else if(String(distanceFormat) == "nm"){ else if (String(distanceFormat) == "nm") {
distance = distance * 0.000539957; distance = distance * 0.000539957;
result.unit = "nm"; result.unit = "nm";
} }
else{; else {
result.unit = "m"; result.unit = "m";
} }
if(distance < 10){ if (distance < 10){
snprintf(buffer,bsize,"%3.2f",distance); snprintf(buffer, bsize, fmt_dec_1, distance);
} }
if(distance >= 10 && distance < 100){ else if (distance < 100){
snprintf(buffer,bsize,"%3.1f",distance); snprintf(buffer, bsize, fmt_dec_10, distance);
} }
if(distance >= 100){ else {
snprintf(buffer,bsize,"%3.0f",distance); snprintf(buffer, bsize, fmt_dec_100, distance);
} }
} }
//######################################################## //########################################################
@ -508,122 +525,122 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:P:P"){ else if (value->getFormat() == "formatXdr:P:P"){
double pressure = 0; double pressure = 0;
if(usesimudata == false) { if (usesimudata == false) {
pressure = value->value; pressure = value->value;
rawvalue = value->value; rawvalue = value->value;
pressure = pressure / 100.0; // Unit conversion form Pa to hPa pressure = pressure / 100.0; // Unit conversion form Pa to hPa
} }
else{ else {
rawvalue = 968 + float(random(0, 10)); rawvalue = 968 + float(random(0, 10));
pressure = rawvalue; pressure = rawvalue;
} }
snprintf(buffer,bsize,"%4.0f",pressure); snprintf(buffer, bsize, "%4.0f", pressure);
result.unit = "hPa"; result.unit = "hPa";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:P:B"){ else if (value->getFormat() == "formatXdr:P:B"){
double pressure = 0; double pressure = 0;
if(usesimudata == false) { if (usesimudata == false) {
pressure = value->value; pressure = value->value;
rawvalue = value->value; rawvalue = value->value;
pressure = pressure / 100.0; // Unit conversion form Pa to mBar pressure = pressure / 100.0; // Unit conversion form Pa to mBar
} }
else{ else {
rawvalue = value->value; rawvalue = value->value;
pressure = 968 + float(random(0, 10)); pressure = 968 + float(random(0, 10));
} }
snprintf(buffer,bsize,"%4.0f",pressure); snprintf(buffer, bsize, "%4.0f", pressure);
result.unit = "mBar"; result.unit = "mBar";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:U:V"){ else if (value->getFormat() == "formatXdr:U:V"){
double voltage = 0; double voltage = 0;
if(usesimudata == false) { if (usesimudata == false) {
voltage = value->value; voltage = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 12 + float(random(0, 30)) / 10.0; rawvalue = 12 + float(random(0, 30)) / 10.0;
voltage = rawvalue; voltage = rawvalue;
} }
if(voltage < 10){ if (voltage < 10) {
snprintf(buffer,bsize,"%3.2f",voltage); snprintf(buffer, bsize, fmt_dec_1, voltage);
} }
else{ else {
snprintf(buffer,bsize,"%3.1f",voltage); snprintf(buffer, bsize, fmt_dec_10, voltage);
} }
result.unit = "V"; result.unit = "V";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:I:A"){ else if (value->getFormat() == "formatXdr:I:A"){
double current = 0; double current = 0;
if(usesimudata == false) { if (usesimudata == false) {
current = value->value; current = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 8.2 + float(random(0, 50)) / 10.0; rawvalue = 8.2 + float(random(0, 50)) / 10.0;
current = rawvalue; current = rawvalue;
} }
if(current < 10){ if (current < 10) {
snprintf(buffer,bsize,"%3.2f",current); snprintf(buffer, bsize, fmt_dec_1, current);
} }
if(current >= 10 && current < 100){ else if(current < 100) {
snprintf(buffer,bsize,"%3.1f",current); snprintf(buffer, bsize, fmt_dec_10, current);
} }
if(current >= 100){ else {
snprintf(buffer,bsize,"%3.0f",current); snprintf(buffer, bsize, fmt_dec_100, current);
} }
result.unit = "A"; result.unit = "A";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:C:K"){ else if (value->getFormat() == "formatXdr:C:K"){
double temperature = 0; double temperature = 0;
if(usesimudata == false) { if (usesimudata == false) {
temperature = value->value - 273.15; // Convert K to C temperature = value->value - 273.15; // Convert K to C
rawvalue = value->value - 273.15; rawvalue = value->value - 273.15;
} }
else{ else {
rawvalue = 21.8 + float(random(0, 50)) / 10.0; rawvalue = 21.8 + float(random(0, 50)) / 10.0;
temperature = rawvalue; temperature = rawvalue;
} }
if(temperature < 10){ if (temperature < 10) {
snprintf(buffer,bsize,"%3.2f",temperature); snprintf(buffer, bsize, fmt_dec_1, temperature);
} }
if(temperature >= 10 && temperature < 100){ else if (temperature < 100) {
snprintf(buffer,bsize,"%3.1f",temperature); snprintf(buffer, bsize, fmt_dec_10, temperature);
} }
if(temperature >= 100){ else {
snprintf(buffer,bsize,"%3.0f",temperature); snprintf(buffer, bsize, fmt_dec_100, temperature);
} }
result.unit = "Deg C"; result.unit = "Deg C";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:C:C"){ else if (value->getFormat() == "formatXdr:C:C"){
double temperature = 0; double temperature = 0;
if(usesimudata == false) { if (usesimudata == false) {
temperature = value->value; // Value in C temperature = value->value; // Value in C
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 21.8 + float(random(0, 50)) / 10.0; rawvalue = 21.8 + float(random(0, 50)) / 10.0;
temperature = rawvalue; temperature = rawvalue;
} }
if(temperature < 10){ if (temperature < 10) {
snprintf(buffer,bsize,"%3.2f",temperature); snprintf(buffer, bsize, fmt_dec_1, temperature);
} }
if(temperature >= 10 && temperature < 100){ else if(temperature < 100) {
snprintf(buffer,bsize,"%3.1f",temperature); snprintf(buffer, bsize, fmt_dec_10, temperature);
} }
if(temperature >= 100){ else {
snprintf(buffer,bsize,"%3.0f",temperature); snprintf(buffer, bsize, fmt_dec_100, temperature);
} }
result.unit = "Deg C"; result.unit = "Deg C";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:H:P"){ else if (value->getFormat() == "formatXdr:H:P"){
double humidity = 0; double humidity = 0;
if(usesimudata == false) { if (usesimudata == false) {
humidity = value->value; // Value in % humidity = value->value; // Value in %
rawvalue = value->value; rawvalue = value->value;
} }
@ -631,143 +648,143 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
rawvalue = 41.3 + float(random(0, 50)) / 10.0; rawvalue = 41.3 + float(random(0, 50)) / 10.0;
humidity = rawvalue; humidity = rawvalue;
} }
if(humidity < 10){ if (humidity < 10) {
snprintf(buffer,bsize,"%3.2f",humidity); snprintf(buffer, bsize, fmt_dec_1, humidity);
} }
if(humidity >= 10 && humidity < 100){ else if(humidity < 100) {
snprintf(buffer,bsize,"%3.1f",humidity); snprintf(buffer, bsize, fmt_dec_10, humidity);
} }
if(humidity >= 100){ else {
snprintf(buffer,bsize,"%3.0f",humidity); snprintf(buffer, bsize, fmt_dec_100, humidity);
} }
result.unit = "%"; result.unit = "%";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:V:P"){ else if (value->getFormat() == "formatXdr:V:P"){
double volume = 0; double volume = 0;
if(usesimudata == false) { if (usesimudata == false) {
volume = value->value; // Value in % volume = value->value; // Value in %
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 85.8 + float(random(0, 50)) / 10.0; rawvalue = 85.8 + float(random(0, 50)) / 10.0;
volume = rawvalue; volume = rawvalue;
} }
if(volume < 10){ if (volume < 10) {
snprintf(buffer,bsize,"%3.2f",volume); snprintf(buffer, bsize, fmt_dec_1, volume);
} }
if(volume >= 10 && volume < 100){ else if (volume < 100) {
snprintf(buffer,bsize,"%3.1f",volume); snprintf(buffer, bsize, fmt_dec_10, volume);
} }
if(volume >= 100){ else if (volume >= 100) {
snprintf(buffer,bsize,"%3.0f",volume); snprintf(buffer, bsize, fmt_dec_100, volume);
} }
result.unit = "%"; result.unit = "%";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:V:M"){ else if (value->getFormat() == "formatXdr:V:M"){
double volume = 0; double volume = 0;
if(usesimudata == false) { if (usesimudata == false) {
volume = value->value; // Value in l volume = value->value; // Value in l
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 75.2 + float(random(0, 50)) / 10.0; rawvalue = 75.2 + float(random(0, 50)) / 10.0;
volume = rawvalue; volume = rawvalue;
} }
if(volume < 10){ if (volume < 10) {
snprintf(buffer,bsize,"%3.2f",volume); snprintf(buffer, bsize, fmt_dec_1, volume);
} }
if(volume >= 10 && volume < 100){ else if (volume < 100) {
snprintf(buffer,bsize,"%3.1f",volume); snprintf(buffer, bsize, fmt_dec_10, volume);
} }
if(volume >= 100){ else {
snprintf(buffer,bsize,"%3.0f",volume); snprintf(buffer, bsize, fmt_dec_100, volume);
} }
result.unit = "l"; result.unit = "l";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:R:I"){ else if (value->getFormat() == "formatXdr:R:I"){
double flow = 0; double flow = 0;
if(usesimudata == false) { if (usesimudata == false) {
flow = value->value; // Value in l/min flow = value->value; // Value in l/min
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 7.5 + float(random(0, 20)) / 10.0; rawvalue = 7.5 + float(random(0, 20)) / 10.0;
flow = rawvalue; flow = rawvalue;
} }
if(flow < 10){ if (flow < 10) {
snprintf(buffer,bsize,"%3.2f",flow); snprintf(buffer, bsize, fmt_dec_1, flow);
} }
if(flow >= 10 && flow < 100){ else if (flow < 100) {
snprintf(buffer,bsize,"%3.1f",flow); snprintf(buffer, bsize, fmt_dec_10, flow);
} }
if(flow >= 100){ else {
snprintf(buffer,bsize,"%3.0f",flow); snprintf(buffer, bsize, fmt_dec_100, flow);
} }
result.unit = "l/min"; result.unit = "l/min";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:G:"){ else if (value->getFormat() == "formatXdr:G:"){
double generic = 0; double generic = 0;
if(usesimudata == false) { if (usesimudata == false) {
generic = value->value; // Value in l/min generic = value->value;
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 18.5 + float(random(0, 20)) / 10.0; rawvalue = 18.5 + float(random(0, 20)) / 10.0;
generic = rawvalue; generic = rawvalue;
} }
if(generic < 10){ if (generic < 10) {
snprintf(buffer,bsize,"%3.2f",generic); snprintf(buffer, bsize, fmt_dec_1, generic);
} }
if(generic >= 10 && generic < 100){ else if (generic < 100) {
snprintf(buffer,bsize,"%3.1f",generic); snprintf(buffer, bsize, fmt_dec_10, generic);
} }
if(generic >= 100){ else {
snprintf(buffer,bsize,"%3.0f",generic); snprintf(buffer, bsize, fmt_dec_100, generic);
} }
result.unit = ""; result.unit = "";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:A:P"){ else if (value->getFormat() == "formatXdr:A:P"){
double dplace = 0; double dplace = 0;
if(usesimudata == false) { if (usesimudata == false) {
dplace = value->value; // Value in % dplace = value->value; // Value in %
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 55.3 + float(random(0, 20)) / 10.0; rawvalue = 55.3 + float(random(0, 20)) / 10.0;
dplace = rawvalue; dplace = rawvalue;
} }
if(dplace < 10){ if (dplace < 10) {
snprintf(buffer,bsize,"%3.2f",dplace); snprintf(buffer, bsize, fmt_dec_1, dplace);
} }
if(dplace >= 10 && dplace < 100){ else if (dplace < 100) {
snprintf(buffer,bsize,"%3.1f",dplace); snprintf(buffer, bsize, fmt_dec_10, dplace);
} }
if(dplace >= 100){ else {
snprintf(buffer,bsize,"%3.0f",dplace); snprintf(buffer, bsize, fmt_dec_100, dplace);
} }
result.unit = "%"; result.unit = "%";
} }
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:A:D"){ else if (value->getFormat() == "formatXdr:A:D"){
double angle = 0; double angle = 0;
if(usesimudata == false) { if (usesimudata == false) {
angle = value->value; angle = value->value;
angle = angle * 57.2958; // Unit conversion form rad to deg angle = angle * 57.2958; // Unit conversion form rad to deg
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = PI / 100 + (random(-5, 5) / 360 * 2* PI); rawvalue = PI / 100 + (random(-5, 5) / 360 * 2* PI);
angle = rawvalue * 57.2958; angle = rawvalue * 57.2958;
} }
if(angle > -10 && angle < 10){ if (angle > -10 && angle < 10) {
snprintf(buffer,bsize,"%3.1f",angle); snprintf(buffer,bsize,"%3.1f",angle);
} }
else{ else {
snprintf(buffer,bsize,"%3.0f",angle); snprintf(buffer,bsize,"%3.0f",angle);
} }
result.unit = "Deg"; result.unit = "Deg";
@ -775,41 +792,41 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
//######################################################## //########################################################
else if (value->getFormat() == "formatXdr:T:R"){ else if (value->getFormat() == "formatXdr:T:R"){
double rpm = 0; double rpm = 0;
if(usesimudata == false) { if (usesimudata == false) {
rpm = value->value; // Value in rpm rpm = value->value; // Value in rpm
rawvalue = value->value; rawvalue = value->value;
} }
else{ else {
rawvalue = 2505 + random(0, 20); rawvalue = 2505 + random(0, 20);
rpm = rawvalue; rpm = rawvalue;
} }
if(rpm < 10){ if (rpm < 10) {
snprintf(buffer,bsize,"%3.2f",rpm); snprintf(buffer, bsize, fmt_dec_1, rpm);
} }
if(rpm >= 10 && rpm < 100){ else if (rpm < 100) {
snprintf(buffer,bsize,"%3.1f",rpm); snprintf(buffer, bsize, fmt_dec_10, rpm);
} }
if(rpm >= 100){ else {
snprintf(buffer,bsize,"%3.0f",rpm); snprintf(buffer, bsize, fmt_dec_100, rpm);
} }
result.unit = "rpm"; result.unit = "rpm";
} }
//######################################################## //########################################################
// Default format // Default format
//######################################################## //########################################################
else{ else {
if(value->value < 10){ if (value->value < 10) {
snprintf(buffer,bsize,"%3.2f",value->value); snprintf(buffer, bsize, fmt_dec_1, value->value);
} }
if(value->value >= 10 && value->value < 100){ else if (value->value < 100) {
snprintf(buffer,bsize,"%3.1f",value->value); snprintf(buffer, bsize, fmt_dec_10, value->value);
} }
if(value->value >= 100){ else {
snprintf(buffer,bsize,"%3.0f",value->value); snprintf(buffer, bsize, fmt_dec_100, value->value);
} }
result.unit = ""; result.unit = "";
} }
buffer[bsize]=0; buffer[bsize] = 0;
result.value = rawvalue; // Return value is only necessary in case of simulation of graphic pointer result.value = rawvalue; // Return value is only necessary in case of simulation of graphic pointer
result.svalue = String(buffer); result.svalue = String(buffer);
return result; return result;

View File

@ -1117,6 +1117,21 @@
"obp60":"true" "obp60":"true"
} }
}, },
{
"name": "valueprecision",
"label": "Display value precision",
"type": "list",
"default": "2",
"description": "Maximum number of decimal places to display [1|2]",
"list": [
"1",
"2"
],
"category": "OBP60 Display",
"capabilities": {
"obp60":"true"
}
},
{ {
"name": "backlight", "name": "backlight",
"label": "Backlight Mode", "label": "Backlight Mode",

View File

@ -1129,6 +1129,21 @@
"obp40": "true" "obp40": "true"
} }
}, },
{
"name": "valueprecision",
"label": "Display value precision",
"type": "list",
"default": "2",
"description": "Maximum number of decimal places to display [1|2]",
"list": [
"1",
"2"
],
"category": "OBP40 Display",
"capabilities": {
"obp40":"true"
}
},
{ {
"name": "backlight", "name": "backlight",
"label": "Backlight Mode", "label": "Backlight Mode",