mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2026-02-11 07:03:07 +01:00
general but flexible limits for formatting numbers
This commit is contained in:
@@ -92,6 +92,8 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
const char* fmt_dec_1;
|
||||
const char* fmt_dec_10;
|
||||
const char* fmt_dec_100;
|
||||
double limit_dec_10;
|
||||
double limit_dec_100;
|
||||
if (precision == "1") {
|
||||
//
|
||||
//All values are displayed using a DSEG7* font. In this font, ' ' is a very short space, and '.' takes up no space at all.
|
||||
@@ -100,10 +102,14 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
fmt_dec_1 = "!%1.1f"; //insert a blank digit and then display a two-digit number
|
||||
fmt_dec_10 = "!%2.0f"; //insert a blank digit and then display a two-digit number
|
||||
fmt_dec_100 = "%3.0f"; //dispay a three digit number
|
||||
limit_dec_10=9.95; // use fmt_dec_1 below this number to avoid formatting 9.96 as 10.0 instead of 10
|
||||
limit_dec_100=99.5;
|
||||
} else {
|
||||
fmt_dec_1 = "%3.2f";
|
||||
fmt_dec_10 = "%3.1f";
|
||||
fmt_dec_100 = "%3.0f";
|
||||
limit_dec_10=9.995;
|
||||
limit_dec_100=99.95;
|
||||
}
|
||||
|
||||
// LOG_DEBUG(GwLog::DEBUG,"formatValue init: getFormat: %s date->value: %f time->value: %f", value->getFormat(), commondata.date->value, commondata.time->value);
|
||||
@@ -243,10 +249,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
speed = speed; // Unit conversion form m/s to m/s
|
||||
result.unit = "m/s";
|
||||
}
|
||||
if(speed < 9.95) {
|
||||
if(speed < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, speed);
|
||||
}
|
||||
else if (speed < 100) {
|
||||
else if (speed < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, speed);
|
||||
}
|
||||
else {
|
||||
@@ -323,10 +329,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
snprintf(buffer, bsize, "%2.0f", speed);
|
||||
}
|
||||
else{
|
||||
if (speed < 9.95){
|
||||
if (speed < limit_dec_10){
|
||||
snprintf(buffer, bsize, fmt_dec_1, speed);
|
||||
}
|
||||
else if (speed < 100.0){
|
||||
else if (speed < limit_dec_100){
|
||||
snprintf(buffer, bsize, fmt_dec_10, speed);
|
||||
}
|
||||
else {
|
||||
@@ -377,10 +383,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
if (dop > 99.9){
|
||||
dop = 99.9;
|
||||
}
|
||||
if (dop < 9.95){
|
||||
if (dop < limit_dec_10){
|
||||
snprintf(buffer, bsize, fmt_dec_1, dop);
|
||||
}
|
||||
else if(dop < 100){
|
||||
else if(dop < limit_dec_100){
|
||||
snprintf(buffer, bsize, fmt_dec_10, dop);
|
||||
}
|
||||
else {
|
||||
@@ -456,10 +462,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
else{
|
||||
result.unit = "m";
|
||||
}
|
||||
if (depth < 9.95) {
|
||||
if (depth < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, depth);
|
||||
}
|
||||
else if (depth < 100){
|
||||
else if (depth < limit_dec_100){
|
||||
snprintf(buffer, bsize, fmt_dec_10, depth);
|
||||
}
|
||||
else {
|
||||
@@ -522,10 +528,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
else{
|
||||
result.unit = "K";
|
||||
}
|
||||
if(temp < 9.95) {
|
||||
if(temp < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, temp);
|
||||
}
|
||||
else if (temp < 100) {
|
||||
else if (temp < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, temp);
|
||||
}
|
||||
else {
|
||||
@@ -555,10 +561,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
else {
|
||||
result.unit = "m";
|
||||
}
|
||||
if (distance < 9.95){
|
||||
if (distance < limit_dec_10){
|
||||
snprintf(buffer, bsize, fmt_dec_1, distance);
|
||||
}
|
||||
else if (distance < 100){
|
||||
else if (distance < limit_dec_100){
|
||||
snprintf(buffer, bsize, fmt_dec_10, distance);
|
||||
}
|
||||
else {
|
||||
@@ -612,7 +618,7 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 12 + float(random(0, 30)) / 10.0;
|
||||
voltage = rawvalue;
|
||||
}
|
||||
if (voltage < 9.95) {
|
||||
if (voltage < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, voltage);
|
||||
}
|
||||
else {
|
||||
@@ -632,10 +638,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 8.2 + float(random(0, 50)) / 10.0;
|
||||
current = rawvalue;
|
||||
}
|
||||
if (current < 9.95) {
|
||||
if (current < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, current);
|
||||
}
|
||||
else if(current < 100) {
|
||||
else if(current < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, current);
|
||||
}
|
||||
else {
|
||||
@@ -655,10 +661,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 21.8 + float(random(0, 50)) / 10.0;
|
||||
temperature = rawvalue;
|
||||
}
|
||||
if (temperature < 9.95) {
|
||||
if (temperature < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, temperature);
|
||||
}
|
||||
else if (temperature < 100) {
|
||||
else if (temperature < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, temperature);
|
||||
}
|
||||
else {
|
||||
@@ -678,10 +684,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 21.8 + float(random(0, 50)) / 10.0;
|
||||
temperature = rawvalue;
|
||||
}
|
||||
if (temperature < 9.95) {
|
||||
if (temperature < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, temperature);
|
||||
}
|
||||
else if(temperature < 100) {
|
||||
else if(temperature < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, temperature);
|
||||
}
|
||||
else {
|
||||
@@ -701,10 +707,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 41.3 + float(random(0, 50)) / 10.0;
|
||||
humidity = rawvalue;
|
||||
}
|
||||
if (humidity < 9.95) {
|
||||
if (humidity < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, humidity);
|
||||
}
|
||||
else if(humidity < 100) {
|
||||
else if(humidity < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, humidity);
|
||||
}
|
||||
else {
|
||||
@@ -724,13 +730,13 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 85.8 + float(random(0, 50)) / 10.0;
|
||||
volume = rawvalue;
|
||||
}
|
||||
if (volume < 9.95) {
|
||||
if (volume < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, volume);
|
||||
}
|
||||
else if (volume < 100) {
|
||||
else if (volume < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, volume);
|
||||
}
|
||||
else if (volume >= 100) {
|
||||
else if (volume >= limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_100, volume);
|
||||
}
|
||||
result.unit = "%";
|
||||
@@ -747,10 +753,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 75.2 + float(random(0, 50)) / 10.0;
|
||||
volume = rawvalue;
|
||||
}
|
||||
if (volume < 9.95) {
|
||||
if (volume < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, volume);
|
||||
}
|
||||
else if (volume < 100) {
|
||||
else if (volume < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, volume);
|
||||
}
|
||||
else {
|
||||
@@ -770,10 +776,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 7.5 + float(random(0, 20)) / 10.0;
|
||||
flow = rawvalue;
|
||||
}
|
||||
if (flow < 9.95) {
|
||||
if (flow < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, flow);
|
||||
}
|
||||
else if (flow < 100) {
|
||||
else if (flow < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, flow);
|
||||
}
|
||||
else {
|
||||
@@ -793,10 +799,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 18.5 + float(random(0, 20)) / 10.0;
|
||||
generic = rawvalue;
|
||||
}
|
||||
if (generic < 9.95) {
|
||||
if (generic < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, generic);
|
||||
}
|
||||
else if (generic < 100) {
|
||||
else if (generic < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, generic);
|
||||
}
|
||||
else {
|
||||
@@ -816,10 +822,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 55.3 + float(random(0, 20)) / 10.0;
|
||||
dplace = rawvalue;
|
||||
}
|
||||
if (dplace < 9.95) {
|
||||
if (dplace < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, dplace);
|
||||
}
|
||||
else if (dplace < 100) {
|
||||
else if (dplace < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, dplace);
|
||||
}
|
||||
else {
|
||||
@@ -860,10 +866,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
rawvalue = 2505 + random(0, 20);
|
||||
rpm = rawvalue;
|
||||
}
|
||||
if (rpm < 9.95) {
|
||||
if (rpm < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, rpm);
|
||||
}
|
||||
else if (rpm < 100) {
|
||||
else if (rpm < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, rpm);
|
||||
}
|
||||
else {
|
||||
@@ -876,10 +882,10 @@ FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata, bool
|
||||
// Default format
|
||||
//########################################################
|
||||
else {
|
||||
if (value->value < 9.95) {
|
||||
if (value->value < limit_dec_10) {
|
||||
snprintf(buffer, bsize, fmt_dec_1, value->value);
|
||||
}
|
||||
else if (value->value < 100) {
|
||||
else if (value->value < limit_dec_100) {
|
||||
snprintf(buffer, bsize, fmt_dec_10, value->value);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user