kopia lustrzana https://github.com/OpenRTX/OpenRTX
GPS: using 16-bit integers for altitude and speed
rodzic
e4a62f30ee
commit
a17ad80f10
|
@ -258,6 +258,19 @@ static inline float minmea_tocoord(struct minmea_float *f)
|
|||
*/
|
||||
int minmea_tofixedpoint(struct minmea_float *f);
|
||||
|
||||
|
||||
/**
|
||||
* Convert a fixed-point value to an integer value.
|
||||
* Returns zero for "unknown" values.
|
||||
*/
|
||||
static inline int minmea_toint(struct minmea_float *f)
|
||||
{
|
||||
if(f->scale == 0)
|
||||
return 0;
|
||||
|
||||
return f->value / f->scale;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -50,8 +50,8 @@ typedef struct
|
|||
uint32_t active_sats; // Bitmap representing which sats are part of the fix
|
||||
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
|
||||
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
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define KNOTS2KMH 1.852f
|
||||
#define KNOTS2KMH(x) ((((int) x) * 1852) / 1000)
|
||||
|
||||
static char sentence[2*MINMEA_MAX_LENGTH];
|
||||
static bool gpsEnabled = false;
|
||||
|
@ -102,7 +102,7 @@ void gps_task()
|
|||
}
|
||||
|
||||
gps_data.tmg_true = minmea_tofloat(&frame.course);
|
||||
gps_data.speed = minmea_tofloat(&frame.speed) * KNOTS2KMH;
|
||||
gps_data.speed = KNOTS2KMH(minmea_toint(&frame.speed));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -113,7 +113,7 @@ void gps_task()
|
|||
{
|
||||
gps_data.fix_quality = frame.fix_quality;
|
||||
gps_data.satellites_tracked = frame.satellites_tracked;
|
||||
gps_data.altitude = minmea_tofloat(&frame.altitude);
|
||||
gps_data.altitude = minmea_toint(&frame.altitude);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -166,7 +166,7 @@ void gps_task()
|
|||
struct minmea_sentence_vtg frame;
|
||||
if (minmea_parse_vtg(&frame, sentence))
|
||||
{
|
||||
gps_data.speed = minmea_tofloat(&frame.speed_kph);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -673,7 +673,7 @@ void vp_announceGPSInfo(vpGPSInfoFlags_t gpsInfoFlags)
|
|||
if ((gpsInfoFlags & vpGPSSpeed) != 0)
|
||||
{
|
||||
// speed/altitude:
|
||||
sniprintf(buffer, 16, "%4.1fkm/h", state.gps_data.speed);
|
||||
sniprintf(buffer, 16, "%dkm/h", state.gps_data.speed);
|
||||
vp_queuePrompt(PROMPT_SPEED);
|
||||
vp_queueString(buffer, vpAnnounceCommonSymbols |
|
||||
vpAnnounceLessCommonSymbols);
|
||||
|
@ -683,7 +683,7 @@ void vp_announceGPSInfo(vpGPSInfoFlags_t gpsInfoFlags)
|
|||
{
|
||||
vp_queuePrompt(PROMPT_ALTITUDE);
|
||||
|
||||
sniprintf(buffer, 16, "%4.1fm", state.gps_data.altitude);
|
||||
sniprintf(buffer, 16, "%dm", state.gps_data.altitude);
|
||||
vp_queueString(buffer, vpAnnounceCommonSymbols);
|
||||
addSilenceIfNeeded(flags);
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <ui/ui_default.h>
|
||||
#include <rtx.h>
|
||||
|
@ -1269,8 +1270,8 @@ void ui_saveState()
|
|||
}
|
||||
|
||||
#ifdef CONFIG_GPS
|
||||
static float priorGPSSpeed = 0;
|
||||
static float priorGPSAltitude = 0;
|
||||
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;
|
||||
|
@ -1300,15 +1301,13 @@ static vpGPSInfoFlags_t GetGPSDirectionOrSpeedChanged()
|
|||
priorGPSFixType = state.gps_data.fix_type;
|
||||
}
|
||||
|
||||
float speedDiff=fabs(state.gps_data.speed - priorGPSSpeed);
|
||||
if (speedDiff >= 1)
|
||||
if (state.gps_data.speed != priorGPSSpeed)
|
||||
{
|
||||
whatChanged |= vpGPSSpeed;
|
||||
priorGPSSpeed = state.gps_data.speed;
|
||||
}
|
||||
|
||||
float altitudeDiff = fabs(state.gps_data.altitude - priorGPSAltitude);
|
||||
if (altitudeDiff >= 5)
|
||||
if (state.gps_data.altitude != priorGPSAltitude)
|
||||
{
|
||||
whatChanged |= vpGPSAltitude;
|
||||
priorGPSAltitude = state.gps_data.altitude;
|
||||
|
|
|
@ -707,7 +707,7 @@ void _ui_drawMenuGPS()
|
|||
gfx_print(layout.line2_pos, layout.top_font, TEXT_ALIGN_RIGHT,
|
||||
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",
|
||||
color_white, "S %dkm/h A %dm",
|
||||
last_state.gps_data.speed,
|
||||
last_state.gps_data.altitude);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue