From 70f0ce45d336f7bd856f215d2244db36315d8915 Mon Sep 17 00:00:00 2001 From: Marco <49691247+marcoSchr@users.noreply.github.com> Date: Sun, 31 Mar 2024 15:30:15 +0200 Subject: [PATCH] GPS: using 16-bit integers for course over ground --- openrtx/include/core/gps.h | 4 ++-- openrtx/src/core/gps.c | 4 ++-- openrtx/src/core/voicePromptUtils.c | 4 ++-- openrtx/src/ui/default/ui.c | 11 +++++------ 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/openrtx/include/core/gps.h b/openrtx/include/core/gps.h index 448058d3..73be489e 100644 --- a/openrtx/include/core/gps.h +++ b/openrtx/include/core/gps.h @@ -52,8 +52,8 @@ typedef struct int32_t longitude; // Longitude coordinates int16_t altitude; // Antenna altitude above mean sea level (geoid) in m uint16_t speed; // Ground speed in km/h - float tmg_mag; // Course over ground, degrees, magnetic - float tmg_true; // Course over ground, degrees, true + int16_t tmg_mag; // Course over ground, degrees, magnetic + int16_t tmg_true; // Course over ground, degrees, true } gps_t; diff --git a/openrtx/src/core/gps.c b/openrtx/src/core/gps.c index af4ad891..54934968 100644 --- a/openrtx/src/core/gps.c +++ b/openrtx/src/core/gps.c @@ -167,8 +167,8 @@ void gps_task() if (minmea_parse_vtg(&frame, sentence)) { gps_data.speed = minmea_toint(&frame.speed_kph); - gps_data.tmg_mag = minmea_tofloat(&frame.magnetic_track_degrees); - gps_data.tmg_true = minmea_tofloat(&frame.true_track_degrees); + gps_data.tmg_mag = minmea_toint(&frame.magnetic_track_degrees); + gps_data.tmg_true = minmea_toint(&frame.true_track_degrees); } } break; diff --git a/openrtx/src/core/voicePromptUtils.c b/openrtx/src/core/voicePromptUtils.c index f18b7d9b..a0c9cadb 100644 --- a/openrtx/src/core/voicePromptUtils.c +++ b/openrtx/src/core/voicePromptUtils.c @@ -550,7 +550,7 @@ void vp_announceM17Info(const channel_t* channel, bool isEditing, static bool IsCompassCloseEnoughToCardinalPoint() { - float tmg_true = state.gps_data.tmg_true; + int16_t tmg_true = state.gps_data.tmg_true; return (tmg_true < (0 + margin) || tmg_true > (360 - margin)) || // north (tmg_true > (90 - margin) && tmg_true < (90 + margin)) || // east @@ -638,7 +638,7 @@ void vp_announceGPSInfo(vpGPSInfoFlags_t gpsInfoFlags) vp_queuePrompt(PROMPT_COMPASS); if (!IsCompassCloseEnoughToCardinalPoint()) { - sniprintf(buffer, 16, "%3.1f", state.gps_data.tmg_true); + sniprintf(buffer, 16, "%d", state.gps_data.tmg_true); vp_queueString(buffer, vpAnnounceCommonSymbols); vp_queuePrompt(PROMPT_DEGREES); } diff --git a/openrtx/src/ui/default/ui.c b/openrtx/src/ui/default/ui.c index e219a684..0a51604d 100644 --- a/openrtx/src/ui/default/ui.c +++ b/openrtx/src/ui/default/ui.c @@ -1272,10 +1272,10 @@ void ui_saveState() #ifdef CONFIG_GPS static uint16_t priorGPSSpeed = 0; static int16_t priorGPSAltitude = 0; -static float priorGPSDirection = 500; // impossible value init. -static uint8_t priorGPSFixQuality= 0; -static uint8_t priorGPSFixType = 0; -static uint8_t priorSatellitesInView = 0; +static int16_t priorGPSDirection = 500; // impossible value init. +static uint8_t priorGPSFixQuality= 0; +static uint8_t priorGPSFixType = 0; +static uint8_t priorSatellitesInView = 0; static uint32_t vpGPSLastUpdate = 0; static vpGPSInfoFlags_t GetGPSDirectionOrSpeedChanged() @@ -1313,8 +1313,7 @@ static vpGPSInfoFlags_t GetGPSDirectionOrSpeedChanged() priorGPSAltitude = state.gps_data.altitude; } - float degreeDiff = fabs(state.gps_data.tmg_true - priorGPSDirection); - if (degreeDiff >= 1) + if (state.gps_data.tmg_true != priorGPSDirection) { whatChanged |= vpGPSDirection; priorGPSDirection = state.gps_data.tmg_true;