@@ -316,6 +316,14 @@ static void osdFormatDistanceSymbol(char *buff, int32_t dist, uint8_t decimals,
316316 }
317317}
318318
319+ /**
320+ * return flight direction on degrees
321+ */
322+ static int16_t osdGetFlightDirection (void )
323+ {
324+ return STATE (AIRPLANE ) ? CENTIDEGREES_TO_DEGREES (posControl .actualState .cog ) : DECIDEGREES_TO_DEGREES (osdGetHeading ());
325+ }
326+
319327/**
320328 * Converts distance into a string based on the current unit system.
321329 * @param dist Distance in centimeters
@@ -2061,8 +2069,7 @@ static bool osdDrawSingleElement(uint8_t item)
20612069 if (!(osdConfig ()-> pan_servo_pwm2centideg == 0 )){
20622070 panHomeDirOffset = osdGetPanServoOffset ();
20632071 }
2064- int16_t flightDirection = STATE (AIRPLANE ) ? CENTIDEGREES_TO_DEGREES (posControl .actualState .cog ) : DECIDEGREES_TO_DEGREES (osdGetHeading ());
2065- int homeDirection = GPS_directionToHome - flightDirection + panHomeDirOffset ;
2072+ int homeDirection = GPS_directionToHome - osdGetFlightDirection () + panHomeDirOffset ;
20662073 osdDrawDirArrow (osdDisplayPort , osdGetDisplayPortCanvas (), OSD_DRAW_POINT_GRID (elemPosX , elemPosY ), homeDirection );
20672074 }
20682075 } else {
@@ -2258,16 +2265,17 @@ static bool osdDrawSingleElement(uint8_t item)
22582265 uint8_t buffIndexFirstLine = 0 ;
22592266 uint8_t arrowIndexIndex = 0 ;
22602267 adsbVehicle_t * vehicle = findVehicleClosestLimit (METERS_TO_CENTIMETERS (osdConfig ()-> adsb_ignore_plane_above_me_limit ));
2261- if (vehicle != NULL )
2262- {
2268+ if (vehicle != NULL ) {
22632269 recalculateVehicle (vehicle );
22642270 }
22652271
22662272 if (
2267- vehicle != NULL &&
2268- (vehicle -> calculatedVehicleValues .dist > 0 &&
2269- vehicle -> calculatedVehicleValues .dist < METERS_TO_CENTIMETERS (osdConfig ()-> adsb_distance_warning ))
2270- ){
2273+ vehicle != NULL
2274+ && (vehicle -> calculatedVehicleValues .dist > 0
2275+ && vehicle -> calculatedVehicleValues .dist < METERS_TO_CENTIMETERS (osdConfig ()-> adsb_distance_warning ))
2276+ && isEnvironmentOkForCalculatingADSBDistanceBearing ()
2277+
2278+ ) {
22712279 adsbLengthForClearFirstLine = 11 ;
22722280
22732281 buff [buffIndexFirstLine ++ ] = SYM_ADSB ;
@@ -2301,21 +2309,20 @@ static bool osdDrawSingleElement(uint8_t item)
23012309 //////////////////////////////////////////////////////
23022310 // ALT diff to ADSB vehicle draw
23032311 int16_t panServoDirOffset = 0 ;
2304- if (osdConfig ()-> pan_servo_pwm2centideg != 0 ){
2312+ if (osdConfig ()-> pan_servo_pwm2centideg != 0 ) {
23052313 panServoDirOffset = osdGetPanServoOffset ();
23062314 }
23072315
2308- if (arrowIndexIndex > 0 )
2309- {
2316+ if (arrowIndexIndex > 0 && isImuHeadingValid ()) {
23102317 //[direction to vehicle]
2311- int directionToPeerError = osdGetHeadingAngle (CENTIDEGREES_TO_DEGREES (vehicle -> calculatedVehicleValues .dir )) + panServoDirOffset - ( int ) DECIDEGREES_TO_DEGREES ( osdGetHeading () );
2318+ int directionToPeerError = osdGetHeadingAngle (CENTIDEGREES_TO_DEGREES (vehicle -> calculatedVehicleValues .dir )) + panServoDirOffset - osdGetFlightDirection ( );
23122319 osdDrawDirCardinal (osdDisplayPort , elemPosX + arrowIndexIndex , elemPosY , directionToPeerError , elemAttr );
23132320 }
23142321 //////////////////////////////////////////////////////
23152322
23162323 //////////////////////////////////////////////////////
23172324 // Second line, extra info
2318- if (osdConfig ()-> adsb_warning_style == OSD_ADSB_WARNING_STYLE_EXTENDED ){
2325+ if (osdConfig ()-> adsb_warning_style == OSD_ADSB_WARNING_STYLE_EXTENDED ) {
23192326 // Vehicle type
23202327 tfp_sprintf (buff , "%s" , getAdsbEmitterTypeString (vehicle -> vehicleValues .emitterType ));
23212328
@@ -2327,41 +2334,43 @@ static bool osdDrawSingleElement(uint8_t item)
23272334 displayWriteWithAttr (osdDisplayPort , elemPosX , elemPosY + 1 , buff , elemAttr );
23282335
23292336 // Vehicle direction
2330- int16_t flightDirection = STATE (AIRPLANE ) ? CENTIDEGREES_TO_DEGREES (posControl .actualState .cog ) : DECIDEGREES_TO_DEGREES (osdGetHeading ());
2331- osdDrawDirArrow (osdDisplayPort , osdGetDisplayPortCanvas (), OSD_DRAW_POINT_GRID (elemPosX + 6 , elemPosY + 1 ), (float )(CENTIDEGREES_TO_DEGREES (vehicle -> vehicleValues .heading ) - flightDirection + panServoDirOffset ));
2337+ if (isImuHeadingValid ())
2338+ {
2339+ osdDrawDirArrow (osdDisplayPort , osdGetDisplayPortCanvas (), OSD_DRAW_POINT_GRID (elemPosX + 6 , elemPosY + 1 ), (float )(CENTIDEGREES_TO_DEGREES (vehicle -> vehicleValues .heading ) - osdGetFlightDirection () + panServoDirOffset ));
2340+ }
23322341
23332342 adsbLengthForClearSecondLine += 7 ;
23342343 }
23352344 ///////////////////////////////////////////////////
2336- }
2337- else
2338- {
2345+ } else {
23392346 //clear first line
2340- if (adsbLengthForClearFirstLine > 0 ){
2347+ if (adsbLengthForClearFirstLine > 0 ) {
23412348 memset (buff , SYM_BLANK , constrain (adsbLengthForClearFirstLine , 0 , 20 ));
23422349 displayWrite (osdDisplayPort , elemPosX , elemPosY , buff );
23432350 adsbLengthForClearFirstLine = 0 ;
23442351 }
23452352
23462353 //clear second line
2347- if (adsbLengthForClearSecondLine > 0 ){
2354+ if (adsbLengthForClearSecondLine > 0 ) {
23482355 memset (buff , SYM_BLANK , constrain (adsbLengthForClearSecondLine , 0 , 20 ));
23492356 displayWrite (osdDisplayPort , elemPosX , elemPosY + 1 , buff );
23502357 adsbLengthForClearSecondLine = 0 ;
23512358 }
23522359 }
2353-
23542360 return true;
23552361 }
23562362 case OSD_ADSB_INFO :
23572363 {
23582364 buff [0 ] = SYM_ADSB ;
2359- if (getAdsbStatus ()-> vehiclesMessagesTotal > 0 || getAdsbStatus ()-> heartbeatMessagesTotal > 0 ){
2360- tfp_sprintf (buff + 1 , "%1d" , getActiveVehiclesCount ());
2361- }else {
2365+ if (getAdsbStatus ()-> vehiclesMessagesTotal == 0 && getAdsbStatus ()-> heartbeatMessagesTotal == 0 ) {
23622366 buff [1 ] = '-' ;
2367+ } else if (!isEnvironmentOkForCalculatingADSBDistanceBearing ()) {
2368+ buff [1 ] = 'G' ;
2369+ } else if (!isImuHeadingValid ()) {
2370+ buff [1 ] = 'H' ;
2371+ } else {
2372+ tfp_sprintf (buff + 1 , "%1d" , getActiveVehiclesCount ());
23632373 }
2364-
23652374 break ;
23662375 }
23672376
@@ -4081,8 +4090,7 @@ static bool osdDrawSingleElement(uint8_t item)
40814090 if (!(osdConfig ()-> pan_servo_pwm2centideg == 0 )){
40824091 panHomeDirOffset = osdGetPanServoOffset ();
40834092 }
4084- int16_t flightDirection = STATE (AIRPLANE ) ? CENTIDEGREES_TO_DEGREES (posControl .actualState .cog ) : DECIDEGREES_TO_DEGREES (osdGetHeading ());
4085- int direction = CENTIDEGREES_TO_DEGREES (geozone .directionToNearestZone ) - flightDirection + panHomeDirOffset ;
4093+ int direction = CENTIDEGREES_TO_DEGREES (geozone .directionToNearestZone ) - osdGetFlightDirection () + panHomeDirOffset ;
40864094 osdDrawDirArrow (osdDisplayPort , osdGetDisplayPortCanvas (), OSD_DRAW_POINT_GRID (elemPosX , elemPosY ), direction );
40874095 } else {
40884096 if (isGeozoneActive ()) {
0 commit comments