mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 01:05:27 +03:00
Refactor FrSky GPS coordinate to use a structure since the two arguments
are always used together. This also improves code readability by replacing tmp1/tmp2 with a well named variable.
This commit is contained in:
parent
a207774e10
commit
83d4e1e3fa
2 changed files with 16 additions and 10 deletions
|
@ -43,6 +43,11 @@ typedef enum {
|
|||
GPS_PASSTHROUGH_NO_SERIAL_PORT
|
||||
} gpsEnablePassthroughResult_e;
|
||||
|
||||
typedef struct gpsCoordinateDDDMMmmmm_s {
|
||||
int16_t dddmm;
|
||||
int16_t mmmm;
|
||||
} gpsCoordinateDDDMMmmmm_t;
|
||||
|
||||
extern int16_t GPS_angle[ANGLE_INDEX_COUNT]; // it's the angles that must be applied for GPS correction
|
||||
extern int32_t GPS_coord[2]; // LAT/LON
|
||||
extern int32_t GPS_home[2];
|
||||
|
|
|
@ -152,33 +152,34 @@ static void sendTime(void)
|
|||
|
||||
// Frsky pdf: dddmm.mmmm
|
||||
// .mmmm is returned in decimal fraction of minutes.
|
||||
static void GPStoDDDMM_MMMM(int32_t mwiigps, int16_t *dddmm, int16_t *mmmm)
|
||||
static void GPStoDDDMM_MMMM(int32_t mwiigps, gpsCoordinateDDDMMmmmm_t *result)
|
||||
{
|
||||
int32_t absgps, deg, min;
|
||||
absgps = abs(mwiigps);
|
||||
deg = absgps / 10000000;
|
||||
absgps = (absgps - deg * 10000000) * 60; // absgps = Minutes left * 10^7
|
||||
min = absgps / 10000000; // minutes left
|
||||
*dddmm = deg * 100 + min;
|
||||
*mmmm = (absgps - min * 10000000) / 1000;
|
||||
|
||||
result->dddmm = deg * 100 + min;
|
||||
result->mmmm = (absgps - min * 10000000) / 1000;
|
||||
}
|
||||
|
||||
static void sendGPS(void)
|
||||
{
|
||||
int16_t tmp1, tmp2;
|
||||
GPStoDDDMM_MMMM(GPS_coord[LAT], &tmp1, &tmp2);
|
||||
gpsCoordinateDDDMMmmmm_t coordinate;
|
||||
GPStoDDDMM_MMMM(GPS_coord[LAT], &coordinate);
|
||||
sendDataHead(ID_LATITUDE_BP);
|
||||
serialize16(tmp1);
|
||||
serialize16(coordinate.dddmm);
|
||||
sendDataHead(ID_LATITUDE_AP);
|
||||
serialize16(tmp2);
|
||||
serialize16(coordinate.mmmm);
|
||||
sendDataHead(ID_N_S);
|
||||
serialize16(GPS_coord[LAT] < 0 ? 'S' : 'N');
|
||||
|
||||
GPStoDDDMM_MMMM(GPS_coord[LON], &tmp1, &tmp2);
|
||||
GPStoDDDMM_MMMM(GPS_coord[LON], &coordinate);
|
||||
sendDataHead(ID_LONGITUDE_BP);
|
||||
serialize16(tmp1);
|
||||
serialize16(coordinate.dddmm);
|
||||
sendDataHead(ID_LONGITUDE_AP);
|
||||
serialize16(tmp2);
|
||||
serialize16(coordinate.mmmm);
|
||||
sendDataHead(ID_E_W);
|
||||
serialize16(GPS_coord[LON] < 0 ? 'W' : 'E');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue