@@ -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+
253261bool 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