@@ -170,9 +170,13 @@ static unsigned currentLayout = 0;
170170static int layoutOverride = -1 ;
171171static bool hasExtendedFont = false; // Wether the font supports characters > 256
172172static timeMs_t layoutOverrideUntil = 0 ;
173- static pt1Filter_t GForceFilter , GForceFilterAxis [XYZ_AXIS_COUNT ];
174173static float GForce , GForceAxis [XYZ_AXIS_COUNT ];
175174
175+ // OSD Filters
176+ static pt1Filter_t GForceFilter , GForceFilterAxis [XYZ_AXIS_COUNT ];
177+ static pt1Filter_t glideTimeFilterState , glideSlopeFilterState ;
178+ static pt1Filter_t climbEffFilterState , mahEffFilterState , whEffFilterState ;
179+
176180typedef struct statistic_s {
177181 uint16_t max_speed ;
178182 uint16_t max_3D_speed ;
@@ -1234,11 +1238,9 @@ static inline int32_t osdGetAltitudeMsl(void)
12341238
12351239uint16_t osdGetRemainingGlideTime (void ) {
12361240 float value = getEstimatedActualVelocity (Z );
1237- static pt1Filter_t glideTimeFilterState ;
12381241 const timeMs_t curTimeMs = millis ();
12391242 static timeMs_t glideTimeUpdatedMs ;
12401243
1241- if (!glideTimeFilterState .RC ) pt1FilterSetCutoff (& glideTimeFilterState , 0.5f );
12421244 value = pt1FilterApply3 (& glideTimeFilterState , isnormal (value ) ? value : 0 , MS2S (curTimeMs - glideTimeUpdatedMs ));
12431245 glideTimeUpdatedMs = curTimeMs ;
12441246
@@ -1787,7 +1789,6 @@ static int32_t osdUpdateEfficiencyFilter(pt1Filter_t *state, timeUs_t *lastUpdat
17871789 timeUs_t currentTimeUs = micros ();
17881790 timeDelta_t delta = cmpTimeUs (currentTimeUs , * lastUpdated );
17891791 if (delta >= EFFICIENCY_UPDATE_INTERVAL ) {
1790- if (!state -> RC ) pt1FilterSetCutoff (state , 1.0f );
17911792 pt1FilterApply3 (state , rawValue , US2S (delta ));
17921793 * lastUpdated = currentTimeUs ;
17931794 }
@@ -1994,13 +1995,11 @@ static bool osdDrawSingleElement(uint8_t item)
19941995 {
19951996 float horizontalSpeed = gpsSol .groundSpeed ;
19961997 float sinkRate = - getEstimatedActualVelocity (Z );
1997- static pt1Filter_t gsFilterState ;
19981998 const timeMs_t currentTimeMs = millis ();
19991999 static timeMs_t gsUpdatedTimeMs ;
20002000 float glideSlope = horizontalSpeed / sinkRate ;
20012001
2002- if (!gsFilterState .RC ) pt1FilterSetCutoff (& gsFilterState , 0.5f );
2003- glideSlope = pt1FilterApply3 (& gsFilterState , isnormal (glideSlope ) ? glideSlope : 200 , MS2S (currentTimeMs - gsUpdatedTimeMs ));
2002+ glideSlope = pt1FilterApply3 (& glideSlopeFilterState , isnormal (glideSlope ) ? glideSlope : 200 , MS2S (currentTimeMs - gsUpdatedTimeMs ));
20042003 gsUpdatedTimeMs = currentTimeMs ;
20052004
20062005 buff [0 ] = SYM_GLIDESLOPE ;
@@ -3093,20 +3092,18 @@ static bool osdDrawSingleElement(uint8_t item)
30933092 {
30943093 // amperage is in centi amps (10mA), vertical speed is in cms/s. We want
30953094 // Ah/dist only to show when vertical speed > 1m/s.
3096- static pt1Filter_t veFilterState ;
30973095 static timeUs_t vEfficiencyUpdated = 0 ;
30983096 int32_t value = 0 ;
30993097 timeUs_t currentTimeUs = micros ();
31003098 timeDelta_t vEfficiencyTimeDelta = cmpTimeUs (currentTimeUs , vEfficiencyUpdated );
31013099 if (getEstimatedActualVelocity (Z ) > 0 ) {
31023100 if (vEfficiencyTimeDelta >= EFFICIENCY_UPDATE_INTERVAL ) {
3103- // getAmperage() Centiamps (kept for osdFormatCentiNumber) / m/s - Will appear as A / m/s in OSD
3104- if (!veFilterState .RC ) pt1FilterSetCutoff (& veFilterState , 1.0f );
3105- value = pt1FilterApply3 (& veFilterState , (float )getAmperage () / (getEstimatedActualVelocity (Z ) / 100.0f ), US2S (vEfficiencyTimeDelta ));
3101+ // Centiamps (kept for osdFormatCentiNumber) / m/s - Will appear as A / m/s in OSD
3102+ value = pt1FilterApply3 (& climbEffFilterState , (float )getAmperage () / (getEstimatedActualVelocity (Z ) / 100.0f ), US2S (vEfficiencyTimeDelta ));
31063103
31073104 vEfficiencyUpdated = currentTimeUs ;
31083105 } else {
3109- value = veFilterState .state ;
3106+ value = climbEffFilterState .state ;
31103107 }
31113108 }
31123109 bool efficiencyValid = (value > 0 ) && (getEstimatedActualVelocity (Z ) > 100 );
@@ -3536,16 +3533,16 @@ static bool osdDrawSingleElement(uint8_t item)
35363533 case OSD_EFFICIENCY_MAH_PER_KM :
35373534 {
35383535 // amperage is in centi amps, speed is in cms/s. We want mah/km.
3539- static pt1Filter_t eFilterState ;
35403536 static timeUs_t efficiencyUpdated = 0 ;
35413537 bool moreThanAh = false;
35423538 uint8_t digits = 3U ;
35433539#ifndef DISABLE_MSP_DJI_COMPAT
35443540 if (isDJICompatibleVideoSystem (osdConfig ())) digits = 4U ;
35453541#endif
35463542 float rawEff = gpsSol .groundSpeed > 0 ? ((float )getAmperage () / gpsSol .groundSpeed ) / 0.0036f : 0.0f ; // div/0 guard only; helper owns the GPS guard
3547- int32_t value = osdUpdateEfficiencyFilter (& eFilterState , & efficiencyUpdated , rawEff );
3543+ int32_t value = osdUpdateEfficiencyFilter (& mahEffFilterState , & efficiencyUpdated , rawEff );
35483544 bool efficiencyValid = (value > 0 ) && (gpsSol .groundSpeed > 100 );
3545+
35493546 switch (osdConfig ()-> units ) {
35503547 case OSD_UNIT_UK :
35513548 FALLTHROUGH ;
@@ -3600,11 +3597,11 @@ static bool osdDrawSingleElement(uint8_t item)
36003597 case OSD_EFFICIENCY_WH_PER_KM :
36013598 {
36023599 // power is in mW, speed is in cms/s. We want mWh/km.
3603- static pt1Filter_t eFilterState ;
36043600 static timeUs_t efficiencyUpdated = 0 ;
36053601 float rawEff = gpsSol .groundSpeed > 0 ? ((float )getPower () / gpsSol .groundSpeed ) / 0.0036f : 0.0f ;
3606- int32_t value = osdUpdateEfficiencyFilter (& eFilterState , & efficiencyUpdated , rawEff );
3602+ int32_t value = osdUpdateEfficiencyFilter (& whEffFilterState , & efficiencyUpdated , rawEff );
36073603 bool efficiencyValid = (value > 0 ) && (gpsSol .groundSpeed > 100 );
3604+
36083605 switch (osdConfig ()-> units ) {
36093606 case OSD_UNIT_UK :
36103607 FALLTHROUGH ;
@@ -5736,8 +5733,13 @@ static void osdFilterData(timeUs_t currentTimeUs)
57365733 for (uint8_t axis = 0 ; axis < XYZ_AXIS_COUNT ; axis ++ ) {
57375734 GForceAxis [axis ] = pt1FilterApply3 (& GForceFilterAxis [axis ], GForceAxis [axis ], refresh_dT );
57385735 }
5739- } else {
5736+ } else { // init OSD filter f_cut values
57405737 pt1FilterSetCutoff (& GForceFilter , GFORCE_FILTER_T_CUT_HZ );
5738+ pt1FilterSetCutoff (& glideTimeFilterState , 0.5f );
5739+ pt1FilterSetCutoff (& glideSlopeFilterState , 0.5f );
5740+ pt1FilterSetCutoff (& climbEffFilterState , 1.0f );
5741+ pt1FilterSetCutoff (& mahEffFilterState , 1.0f );
5742+ pt1FilterSetCutoff (& whEffFilterState , 1.0f );
57415743
57425744 for (uint8_t axis = 0 ; axis < XYZ_AXIS_COUNT ; axis ++ ) {
57435745 pt1FilterSetCutoff (& GForceFilterAxis [axis ], GFORCE_FILTER_T_CUT_HZ );
0 commit comments