@@ -369,7 +369,7 @@ void printReports()
369369
370370 char modifiedHpa[20 ];
371371 const char *hpaUnits =
372- getHpaUnits (hpa, modifiedHpa, sizeof (modifiedHpa), 3 ); // Returns string of the HPA units
372+ getHpaUnits (hpa, modifiedHpa, sizeof (modifiedHpa), 3 , true ); // Returns string of the HPA units
373373
374374 systemPrintf (" Rover Accuracy (%s): %s, SIV: %d GNSS State: " , hpaUnits, modifiedHpa,
375375 gnssGetSatellitesInView ());
@@ -716,44 +716,49 @@ void reportFatalError(const char *errorMsg)
716716 }
717717}
718718
719- // Returns string of the HPA units
720- const char * getHpaUnits ( double hpa, char *buffer, int length, int decimals )
719+ // This allows the measurementScaleTable to be alphabetised if desired
720+ int measurementScaleToIndex ( uint8_t scale )
721721{
722- const char *units;
723-
724- // Return the units
725- if (settings.measurementScale >= MEASUREMENT_SCALE_MAX)
722+ for (int i = 0 ; i < MEASUREMENT_UNITS_MAX; i++)
726723 {
727- units = " Unknown " ;
728- strcpy (buffer, " Unknown " ) ;
724+ if (measurementScaleTable[i]. measurementUnit == scale)
725+ return i ;
729726 }
730- else
727+
728+ return -1 ; // This should never happen...
729+ }
730+
731+ // Returns string of the HPA units
732+ const char *getHpaUnits (double hpa, char *buffer, int length, int decimals, bool limit)
733+ {
734+ static const char unknown[] = " Unknown" ;
735+
736+ int i = measurementScaleToIndex (settings.measurementScale );
737+ if (i >= 0 )
731738 {
732- units = measurementScaleUnits[settings. measurementScale ] ;
739+ const char * units = measurementScaleTable[i]. measurementScale1NameShort ;
733740
734- // Convert the HPA value to a string
735- switch (settings.measurementScale )
741+ hpa *= measurementScaleTable[i].multiplierMetersToScale1 ; // Scale1: m->m or m->ft
742+
743+ bool limited = false ;
744+ if (limit && (hpa > measurementScaleTable[i].reportingLimitScale1 )) // Limit the reported accuracy (Scale1)
736745 {
737- case MEASUREMENTS_IN_METERS:
738- snprintf (buffer, length, " %.*f " , decimals, hpa) ;
739- break ;
746+ limited = true ;
747+ hpa = measurementScaleTable[i]. reportingLimitScale1 ;
748+ }
740749
741- case MEASUREMENTS_IN_FEET_INCHES:
742- double inches;
743- double feet;
744- inches = hpa * INCHES_IN_A_METER;
745- feet = inches / 12 .;
746- if (inches >= 36 .)
747- snprintf (buffer, length, " %.*f" , decimals, feet);
748- else
749- {
750- units = " in" ;
751- snprintf (buffer, length, " %.*f" , decimals, inches);
752- }
753- break ;
750+ if (hpa <= measurementScaleTable[i].changeFromScale1To2At ) // Scale2: m->m or ft->in
751+ {
752+ hpa *= measurementScaleTable[i].multiplierScale1To2 ;
753+ units = measurementScaleTable[i].measurementScale2NameShort ;
754754 }
755+
756+ snprintf (buffer, length, " %s%.*f" , limited ? " > " : " " , decimals, hpa);
757+ return units;
755758 }
756- return units;
759+
760+ strncpy (buffer, unknown, length);
761+ return unknown;
757762}
758763
759764// Helper method to convert GNSS time and date into Unix Epoch
0 commit comments