@@ -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
@@ -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 - osdGetFlightDirection () + 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,21 @@ 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 -
2239+ osdGetFlightDirection ();
22302240 osdDrawDirCardinal (osdDisplayPort , elemPosX + arrowIndexIndex , elemPosY , directionToPeerError , elemAttr );
22312241 }
22322242 //////////////////////////////////////////////////////
22332243
22342244 //////////////////////////////////////////////////////
22352245 // Second line, extra info
2236- if (osdConfig ()-> adsb_warning_style == OSD_ADSB_WARNING_STYLE_EXTENDED ){
2246+ if (osdConfig ()-> adsb_warning_style == OSD_ADSB_WARNING_STYLE_EXTENDED ) {
22372247 // Vehicle type
22382248 tfp_sprintf (buff , "%s" , getAdsbEmitterTypeString (vehicle -> vehicleValues .emitterType ));
22392249
@@ -2245,41 +2255,41 @@ static bool osdDrawSingleElement(uint8_t item)
22452255 displayWriteWithAttr (osdDisplayPort , elemPosX , elemPosY + 1 , buff , elemAttr );
22462256
22472257 // 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 ));
2258+ osdDrawDirArrow ( osdDisplayPort , osdGetDisplayPortCanvas (), OSD_DRAW_POINT_GRID ( elemPosX + 6 , elemPosY + 1 ), ( float )( CENTIDEGREES_TO_DEGREES ( vehicle -> vehicleValues . heading ) -
2259+ osdGetFlightDirection () + panServoDirOffset ));
22502260
22512261 adsbLengthForClearSecondLine += 7 ;
22522262 }
22532263 ///////////////////////////////////////////////////
2254- }
2255- else
2256- {
2264+ } else {
22572265 //clear first line
2258- if (adsbLengthForClearFirstLine > 0 ){
2266+ if (adsbLengthForClearFirstLine > 0 ) {
22592267 memset (buff , SYM_BLANK , constrain (adsbLengthForClearFirstLine , 0 , 20 ));
22602268 displayWrite (osdDisplayPort , elemPosX , elemPosY , buff );
22612269 adsbLengthForClearFirstLine = 0 ;
22622270 }
22632271
22642272 //clear second line
2265- if (adsbLengthForClearSecondLine > 0 ){
2273+ if (adsbLengthForClearSecondLine > 0 ) {
22662274 memset (buff , SYM_BLANK , constrain (adsbLengthForClearSecondLine , 0 , 20 ));
22672275 displayWrite (osdDisplayPort , elemPosX , elemPosY + 1 , buff );
22682276 adsbLengthForClearSecondLine = 0 ;
22692277 }
22702278 }
2271-
22722279 return true;
22732280 }
22742281 case OSD_ADSB_INFO :
22752282 {
22762283 buff [0 ] = SYM_ADSB ;
2277- if (getAdsbStatus ()-> vehiclesMessagesTotal > 0 || getAdsbStatus ()-> heartbeatMessagesTotal > 0 ){
2278- tfp_sprintf (buff + 1 , "%1d" , getActiveVehiclesCount ());
2279- }else {
2284+ if (getAdsbStatus ()-> vehiclesMessagesTotal == 0 && getAdsbStatus ()-> heartbeatMessagesTotal == 0 ) {
22802285 buff [1 ] = '-' ;
2286+ } else if (!isEnvironmentOkForCalculatingADSBDistanceBearing ()) {
2287+ buff [1 ] = 'G' ;
2288+ } else if (!isImuHeadingValid ()) {
2289+ buff [1 ] = 'H' ;
2290+ } else {
2291+ tfp_sprintf (buff + 1 , "%1d" , getActiveVehiclesCount ());
22812292 }
2282-
22832293 break ;
22842294 }
22852295
@@ -3996,8 +4006,7 @@ static bool osdDrawSingleElement(uint8_t item)
39964006 if (!(osdConfig ()-> pan_servo_pwm2centideg == 0 )){
39974007 panHomeDirOffset = osdGetPanServoOffset ();
39984008 }
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 ;
4009+ int direction = CENTIDEGREES_TO_DEGREES (geozone .directionToNearestZone ) - osdGetFlightDirection () + panHomeDirOffset ;
40014010 osdDrawDirArrow (osdDisplayPort , osdGetDisplayPortCanvas (), OSD_DRAW_POINT_GRID (elemPosX , elemPosY ), direction );
40024011 } else {
40034012 if (isGeozoneActive ()) {
0 commit comments