GPS: using fixed-point 32-bit value for latitude and longitude

pull/267/head
Marco 2024-03-31 12:24:09 +02:00 zatwierdzone przez Silvano Seva
rodzic 36ef3b310c
commit e4a62f30ee
4 zmienionych plików z 35 dodań i 18 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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;

Wyświetl plik

@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include <utils.h>
#include <inttypes.h>
#include <ui/ui_default.h>
#include <beeps.h>
#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);

Wyświetl plik

@ -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,