Skip to content

Commit 97c8c7f

Browse files
committed
apply good suggestion from qodo-merge-pro
fix ADSB cardinal for broken mag direction
1 parent de322c4 commit 97c8c7f

4 files changed

Lines changed: 50 additions & 29 deletions

File tree

docs/ADSB.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ is an air traffic surveillance technology that enables aircraft to be accurately
77

88
OSD can be configured to shows the closest aircraft.
99

10-
## OSD element
10+
## OSD ADSB Info element
11+
* "-" no ADSB device detected
12+
* "H" IMU heading is not valid
13+
* "G" no GPS fix or less than 4 stats
14+
* "[Number]" count of ADSB aircrafts
15+
16+
## OSD ADSB Warning element
1117
OSD can be configured to simple view (one line) or to extended view (two lines) by \
1218
`set osd_adsb_warning_style=EXTENDED`
1319

src/main/io/adsb.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void adsbNewVehicle(adsbVehicleValues_t* vehicleValuesLocal) {
178178
}
179179

180180
// non GPS mode, GPS is not fix, just find free space in list or by icao and save vehicle without calculated values
181-
if (!enviromentOkForCalculatingDistaceBearing()) {
181+
if (!isEnvironmentOkForCalculatingADSBDistanceBearing()) {
182182
if(vehicle == NULL){
183183
vehicle = findFreeSpaceInList();
184184
}
@@ -264,8 +264,16 @@ void adsbTtlClean(timeUs_t currentTimeUs) {
264264
}
265265
};
266266

267-
bool enviromentOkForCalculatingDistaceBearing(void){
268-
return (STATE(GPS_FIX) && gpsSol.numSat > 4);
267+
bool isEnvironmentOkForCalculatingADSBDistanceBearing(void){
268+
return
269+
(gpsSol.numSat > 4 &&
270+
(
271+
STATE(GPS_FIX)
272+
#ifdef USE_GPS_FIX_ESTIMATION
273+
|| STATE(GPS_ESTIMATED_FIX)
274+
#endif
275+
)
276+
);
269277
}
270278

271279
#endif

src/main/io/adsb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ uint8_t getActiveVehiclesCount(void);
6464
void adsbTtlClean(timeUs_t currentTimeUs);
6565
adsbVehicleStatus_t* getAdsbStatus(void);
6666
adsbVehicleValues_t* getVehicleForFill(void);
67-
bool enviromentOkForCalculatingDistaceBearing(void);
67+
bool isEnvironmentOkForCalculatingADSBDistanceBearing(void);
6868
void recalculateVehicle(adsbVehicle_t* vehicle);

src/main/io/osd.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ bool osdDisplayIsHD(void)
250250
return false;
251251
}
252252

253+
/**
254+
* return flight direction on degrees
255+
*/
256+
int16_t getFlightDirection(void)
257+
{
258+
return STATE(AIRPLANE) ? CENTIDEGREES_TO_DEGREES(posControl.actualState.cog) : DECIDEGREES_TO_DEGREES(osdGetHeading());
259+
}
260+
253261
bool osdIsNotMetric(void) {
254262
return !(osdConfig()->units == OSD_UNIT_METRIC || osdConfig()->units == OSD_UNIT_METRIC_MPH);
255263
}
@@ -1979,8 +1987,7 @@ static bool osdDrawSingleElement(uint8_t item)
19791987
if (!(osdConfig()->pan_servo_pwm2centideg == 0)){
19801988
panHomeDirOffset = osdGetPanServoOffset();
19811989
}
1982-
int16_t flightDirection = STATE(AIRPLANE) ? CENTIDEGREES_TO_DEGREES(posControl.actualState.cog) : DECIDEGREES_TO_DEGREES(osdGetHeading());
1983-
int homeDirection = GPS_directionToHome - flightDirection + panHomeDirOffset;
1990+
int homeDirection = GPS_directionToHome - getFlightDirection() + panHomeDirOffset;
19841991
osdDrawDirArrow(osdDisplayPort, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX, elemPosY), homeDirection);
19851992
}
19861993
} else {
@@ -2170,22 +2177,25 @@ static bool osdDrawSingleElement(uint8_t item)
21702177
#ifdef USE_ADSB
21712178
case OSD_ADSB_WARNING:
21722179
{
2180+
if (!isEnvironmentOkForCalculatingADSBDistanceBearing() || !isImuHeadingValid()) {
2181+
break;
2182+
}
2183+
21732184
static uint8_t adsbLengthForClearFirstLine = 0;
21742185
static uint8_t adsbLengthForClearSecondLine = 0;
21752186

21762187
uint8_t buffIndexFirstLine = 0;
21772188
uint8_t arrowIndexIndex = 0;
21782189
adsbVehicle_t *vehicle = findVehicleClosestLimit(METERS_TO_CENTIMETERS(osdConfig()->adsb_ignore_plane_above_me_limit));
2179-
if(vehicle != NULL)
2180-
{
2190+
if (vehicle != NULL) {
21812191
recalculateVehicle(vehicle);
21822192
}
21832193

21842194
if (
21852195
vehicle != NULL &&
21862196
(vehicle->calculatedVehicleValues.dist > 0 &&
21872197
vehicle->calculatedVehicleValues.dist < METERS_TO_CENTIMETERS(osdConfig()->adsb_distance_warning))
2188-
){
2198+
) {
21892199
adsbLengthForClearFirstLine = 11;
21902200

21912201
buff[buffIndexFirstLine++] = SYM_ADSB;
@@ -2219,21 +2229,20 @@ static bool osdDrawSingleElement(uint8_t item)
22192229
//////////////////////////////////////////////////////
22202230
// ALT diff to ADSB vehicle draw
22212231
int16_t panServoDirOffset = 0;
2222-
if (osdConfig()->pan_servo_pwm2centideg != 0){
2232+
if (osdConfig()->pan_servo_pwm2centideg != 0) {
22232233
panServoDirOffset = osdGetPanServoOffset();
22242234
}
22252235

2226-
if(arrowIndexIndex > 0)
2227-
{
2236+
if (arrowIndexIndex > 0) {
22282237
//[direction to vehicle]
2229-
int directionToPeerError = osdGetHeadingAngle(CENTIDEGREES_TO_DEGREES(vehicle->calculatedVehicleValues.dir)) + panServoDirOffset - (int)DECIDEGREES_TO_DEGREES(osdGetHeading());
2238+
int directionToPeerError = osdGetHeadingAngle(CENTIDEGREES_TO_DEGREES(vehicle->calculatedVehicleValues.dir)) + panServoDirOffset - getFlightDirection();
22302239
osdDrawDirCardinal(osdDisplayPort, elemPosX + arrowIndexIndex, elemPosY, directionToPeerError, elemAttr);
22312240
}
22322241
//////////////////////////////////////////////////////
22332242

22342243
//////////////////////////////////////////////////////
22352244
// Second line, extra info
2236-
if(osdConfig()->adsb_warning_style == OSD_ADSB_WARNING_STYLE_EXTENDED){
2245+
if (osdConfig()->adsb_warning_style == OSD_ADSB_WARNING_STYLE_EXTENDED) {
22372246
// Vehicle type
22382247
tfp_sprintf(buff, "%s", getAdsbEmitterTypeString(vehicle->vehicleValues.emitterType));
22392248

@@ -2245,41 +2254,40 @@ static bool osdDrawSingleElement(uint8_t item)
22452254
displayWriteWithAttr(osdDisplayPort, elemPosX, elemPosY + 1, buff, elemAttr);
22462255

22472256
// Vehicle direction
2248-
int16_t flightDirection = STATE(AIRPLANE) ? CENTIDEGREES_TO_DEGREES(posControl.actualState.cog) : DECIDEGREES_TO_DEGREES(osdGetHeading());
2249-
osdDrawDirArrow(osdDisplayPort, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX + 6, elemPosY + 1), (float)(CENTIDEGREES_TO_DEGREES(vehicle->vehicleValues.heading) - flightDirection + panServoDirOffset));
2257+
osdDrawDirArrow(osdDisplayPort, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX + 6, elemPosY + 1), (float)(CENTIDEGREES_TO_DEGREES(vehicle->vehicleValues.heading) - getFlightDirection() + panServoDirOffset));
22502258

22512259
adsbLengthForClearSecondLine += 7;
22522260
}
22532261
///////////////////////////////////////////////////
2254-
}
2255-
else
2256-
{
2262+
} else {
22572263
//clear first line
2258-
if(adsbLengthForClearFirstLine > 0){
2264+
if(adsbLengthForClearFirstLine > 0) {
22592265
memset(buff, SYM_BLANK, constrain(adsbLengthForClearFirstLine, 0, 20));
22602266
displayWrite(osdDisplayPort, elemPosX, elemPosY, buff);
22612267
adsbLengthForClearFirstLine = 0;
22622268
}
22632269

22642270
//clear second line
2265-
if(adsbLengthForClearSecondLine > 0){
2271+
if(adsbLengthForClearSecondLine > 0) {
22662272
memset(buff, SYM_BLANK, constrain(adsbLengthForClearSecondLine, 0, 20));
22672273
displayWrite(osdDisplayPort, elemPosX, elemPosY + 1, buff);
22682274
adsbLengthForClearSecondLine = 0;
22692275
}
22702276
}
2271-
22722277
return true;
22732278
}
22742279
case OSD_ADSB_INFO:
22752280
{
22762281
buff[0] = SYM_ADSB;
2277-
if(getAdsbStatus()->vehiclesMessagesTotal > 0 || getAdsbStatus()->heartbeatMessagesTotal > 0){
2278-
tfp_sprintf(buff + 1, "%1d", getActiveVehiclesCount());
2279-
}else{
2282+
if (getAdsbStatus()->vehiclesMessagesTotal == 0 && getAdsbStatus()->heartbeatMessagesTotal == 0) {
22802283
buff[1] = '-';
2284+
} else if (!isEnvironmentOkForCalculatingADSBDistanceBearing()) {
2285+
buff[1] = 'G';
2286+
} else if (!isImuHeadingValid()) {
2287+
buff[1] = 'H';
2288+
} else {
2289+
tfp_sprintf(buff + 1, "%1d", getActiveVehiclesCount());
22812290
}
2282-
22832291
break;
22842292
}
22852293

@@ -3996,8 +4004,7 @@ static bool osdDrawSingleElement(uint8_t item)
39964004
if (!(osdConfig()->pan_servo_pwm2centideg == 0)){
39974005
panHomeDirOffset = osdGetPanServoOffset();
39984006
}
3999-
int16_t flightDirection = STATE(AIRPLANE) ? CENTIDEGREES_TO_DEGREES(posControl.actualState.cog) : DECIDEGREES_TO_DEGREES(osdGetHeading());
4000-
int direction = CENTIDEGREES_TO_DEGREES(geozone.directionToNearestZone) - flightDirection + panHomeDirOffset;
4007+
int direction = CENTIDEGREES_TO_DEGREES(geozone.directionToNearestZone) - getFlightDirection() + panHomeDirOffset;
40014008
osdDrawDirArrow(osdDisplayPort, osdGetDisplayPortCanvas(), OSD_DRAW_POINT_GRID(elemPosX, elemPosY), direction);
40024009
} else {
40034010
if (isGeozoneActive()) {

0 commit comments

Comments
 (0)