Skip to content

Commit

Permalink
GPS: using 16-bit integers for course over ground
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoSchr authored and silseva committed Apr 10, 2024
1 parent a17ad80 commit 70f0ce4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions openrtx/include/core/gps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions openrtx/src/core/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions openrtx/src/core/voicePromptUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 5 additions & 6 deletions openrtx/src/ui/default/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 70f0ce4

Please sign in to comment.