From e4a62f30eeda115df719d8181d8aa1cfcd5599e9 Mon Sep 17 00:00:00 2001 From: Marco <49691247+marcoSchr@users.noreply.github.com> Date: Sun, 31 Mar 2024 12:24:09 +0200 Subject: [PATCH] GPS: using fixed-point 32-bit value for latitude and longitude --- openrtx/include/core/gps.h | 4 ++-- openrtx/src/core/gps.c | 4 ++-- openrtx/src/core/voicePromptUtils.c | 21 ++++++++++++++------- openrtx/src/ui/default/ui_menu.c | 24 +++++++++++++++++------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/openrtx/include/core/gps.h b/openrtx/include/core/gps.h index 5607314f..c681d720 100644 --- a/openrtx/include/core/gps.h +++ b/openrtx/include/core/gps.h @@ -48,8 +48,8 @@ typedef struct uint8_t satellites_in_view; // Satellites in view gpssat_t satellites[12]; // Details about satellites in view uint32_t active_sats; // Bitmap representing which sats are part of the fix - float latitude; // Latitude coordinates - float longitude; // Longitude coordinates + int32_t latitude; // Latitude coordinates + int32_t longitude; // Longitude coordinates float altitude; // Antenna altitude above mean sea level (geoid) in m float speed; // Ground speed in km/h float tmg_mag; // Course over ground, degrees, magnetic diff --git a/openrtx/src/core/gps.c b/openrtx/src/core/gps.c index 1247e6fb..1b16d15c 100644 --- a/openrtx/src/core/gps.c +++ b/openrtx/src/core/gps.c @@ -90,8 +90,8 @@ void gps_task() struct minmea_sentence_rmc frame; if (minmea_parse_rmc(&frame, sentence)) { - gps_data.latitude = minmea_tocoord(&frame.latitude); - gps_data.longitude = minmea_tocoord(&frame.longitude); + gps_data.latitude = minmea_tofixedpoint(&frame.latitude); + gps_data.longitude = minmea_tofixedpoint(&frame.longitude); gps_data.timestamp.hour = frame.time.hours; gps_data.timestamp.minute = frame.time.minutes; gps_data.timestamp.second = frame.time.seconds; diff --git a/openrtx/src/core/voicePromptUtils.c b/openrtx/src/core/voicePromptUtils.c index f0c25a53..1982962a 100644 --- a/openrtx/src/core/voicePromptUtils.c +++ b/openrtx/src/core/voicePromptUtils.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include "interfaces/cps_io.h" @@ -689,20 +690,26 @@ void vp_announceGPSInfo(vpGPSInfoFlags_t gpsInfoFlags) if ((gpsInfoFlags & vpGPSLatitude) != 0) { - // lat/long - sniprintf(buffer, 16, "%8.6f", state.gps_data.latitude); + // Convert from signed longitude, to unsigned + direction + int32_t latitude = abs(state.gps_data.latitude); + uint8_t latitude_int = latitude / 1000000; + int32_t latitude_dec = latitude % 1000000; + voicePrompt_t direction = (state.gps_data.latitude < 0) ? PROMPT_SOUTH : PROMPT_NORTH; + sniprintf(buffer, 16, "%d.%06"PRId32, latitude_int, latitude_dec); stripTrailingZeroes(buffer); vp_queuePrompt(PROMPT_LATITUDE); vp_queueString(buffer, vpAnnounceCommonSymbols); - vp_queuePrompt(PROMPT_NORTH); + vp_queuePrompt(direction); } if ((gpsInfoFlags & vpGPSLongitude) != 0) { - float longitude = state.gps_data.longitude; - voicePrompt_t direction = (longitude < 0) ? PROMPT_WEST : PROMPT_EAST; - longitude = (longitude < 0) ? -longitude : longitude; - sniprintf(buffer, 16, "%8.6f", longitude); + // Convert from signed longitude, to unsigned + direction + int32_t longitude = abs(state.gps_data.longitude); + uint8_t longitude_int = longitude / 1000000; + int32_t longitude_dec = longitude % 1000000; + voicePrompt_t direction = (state.gps_data.longitude < 0) ? PROMPT_WEST : PROMPT_EAST; + sniprintf(buffer, 16, "%d.%06"PRId32, longitude_int, longitude_dec); stripTrailingZeroes(buffer); vp_queuePrompt(PROMPT_LONGITUDE); diff --git a/openrtx/src/ui/default/ui_menu.c b/openrtx/src/ui/default/ui_menu.c index f9d61d35..2908d932 100644 --- a/openrtx/src/ui/default/ui_menu.c +++ b/openrtx/src/ui/default/ui_menu.c @@ -682,20 +682,30 @@ void _ui_drawMenuGPS() } gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_LEFT, color_white, fix_buf); + + // Convert from signed longitude, to unsigned + direction + int32_t latitude = abs(last_state.gps_data.latitude); + uint8_t latitude_int = latitude / 1000000; + int32_t latitude_dec = latitude % 1000000; + char *direction_lat = (last_state.gps_data.latitude < 0) ? "S " : "N "; + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_CENTER, - color_white, "N "); + color_white, direction_lat); gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_RIGHT, - color_white, "%8.6f", last_state.gps_data.latitude); + color_white, "%d.%.6d", latitude_int, latitude_dec); gfx_print(layout.line2_pos, layout.top_font, TEXT_ALIGN_LEFT, color_white, type_buf); + // Convert from signed longitude, to unsigned + direction - float longitude = last_state.gps_data.longitude; - char *direction = (longitude < 0) ? "W " : "E "; - longitude = (longitude < 0) ? -longitude : longitude; + int32_t longitude = abs(last_state.gps_data.longitude); + uint8_t longitude_int = longitude / 1000000; + int32_t longitude_dec = longitude % 1000000; + char *direction_lon = (last_state.gps_data.longitude < 0) ? "W " : "E "; + gfx_print(layout.line2_pos, layout.top_font, TEXT_ALIGN_CENTER, - color_white, direction); + color_white, direction_lon); gfx_print(layout.line2_pos, layout.top_font, TEXT_ALIGN_RIGHT, - color_white, "%8.6f", longitude); + color_white, "%d.%.6d", longitude_int, longitude_dec); gfx_print(layout.bottom_pos, layout.bottom_font, TEXT_ALIGN_CENTER, color_white, "S %4.1fkm/h A %4.1fm", last_state.gps_data.speed,