From 8c24176d966420d9230b2a52f6ea9403af6b38cb Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 24 Apr 2018 16:41:45 -0400 Subject: [PATCH] Fix GPS speed and max speed to respect the units selection Previously GPS speed and max speed would always display in KPH even if the user chose imperial units. Now they will display in MPH for imperial units. --- src/main/common/maths.h | 1 + src/main/io/osd.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/common/maths.h b/src/main/common/maths.h index 4107612e45..7ebd4f3c93 100644 --- a/src/main/common/maths.h +++ b/src/main/common/maths.h @@ -38,6 +38,7 @@ #define DEGREES_TO_RADIANS(angle) ((angle) * 0.0174532925f) #define CM_S_TO_KM_H(centimetersPerSecond) (centimetersPerSecond * 36 / 1000) +#define CM_S_TO_MPH(centimetersPerSecond) (((centimetersPerSecond * 10000) / 5080) / 88) #define MIN(a,b) \ __extension__ ({ __typeof__ (a) _a = (a); \ diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 6cdff4de31..310091893c 100644 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -427,8 +427,15 @@ static bool osdDrawSingleElement(uint8_t item) break; case OSD_GPS_SPEED: - // FIXME ideally we want to use SYM_KMH symbol but it's not in the font any more, so we use K. - tfp_sprintf(buff, "%3dK", CM_S_TO_KM_H(gpsSol.groundSpeed)); + // FIXME ideally we want to use SYM_KMH symbol but it's not in the font any more, so we use K (M for MPH) + switch (osdConfig()->units) { + case OSD_UNIT_IMPERIAL: + tfp_sprintf(buff, "%3dM", CM_S_TO_MPH(gpsSol.groundSpeed)); + break; + default: + tfp_sprintf(buff, "%3dK", CM_S_TO_KM_H(gpsSol.groundSpeed)); + break; + } break; case OSD_GPS_LAT: @@ -1119,7 +1126,14 @@ static void osdUpdateStats(void) { int16_t value = 0; #ifdef USE_GPS - value = CM_S_TO_KM_H(gpsSol.groundSpeed); + switch (osdConfig()->units) { + case OSD_UNIT_IMPERIAL: + value = CM_S_TO_MPH(gpsSol.groundSpeed); + break; + default: + value = CM_S_TO_KM_H(gpsSol.groundSpeed); + break; + } #endif if (stats.max_speed < value) { stats.max_speed = value;