Fix GPS coordinate in the OSD between 0 and -1 (#8374)

Fix GPS coordinate in the OSD between 0 and -1
This commit is contained in:
Michael Keller 2019-06-06 01:33:16 +12:00 committed by GitHub
commit b5b18863dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 10 deletions

View File

@ -227,17 +227,13 @@ static void osdFormatCoordinate(char *buff, char sym, int32_t val)
// We show 7 decimals, so we need to use 12 characters:
// eg: s-180.1234567z s=symbol, z=zero terminator, decimal separator between 0 and 1
static const int coordinateMaxLength = 13;//12 for the number (4 + dot + 7) + 1 for the symbol
buff[0] = sym;
const int32_t integerPart = val / GPS_DEGREES_DIVIDER;
const int32_t decimalPart = labs(val % GPS_DEGREES_DIVIDER);
const int written = tfp_sprintf(buff + 1, "%d.%07d", integerPart, decimalPart);
// pad with blanks to coordinateMaxLength
for (int pos = 1 + written; pos < coordinateMaxLength; ++pos) {
buff[pos] = SYM_BLANK;
int pos = 0;
buff[pos++] = sym;
if (val < 0) {
buff[pos++] = '-';
val = -val;
}
buff[coordinateMaxLength] = '\0';
tfp_sprintf(buff + pos, "%d.%07d", val / GPS_DEGREES_DIVIDER, val % GPS_DEGREES_DIVIDER);
}
#endif // USE_GPS