@@ -25,7 +25,6 @@ SX1280Driver Radio;
2525#include " config.h"
2626#include " hwTimer.h"
2727#include " LQCALC.h"
28- #include " LowPassFilter.h"
2928#include " telemetry_protocol.h"
3029#include " stubborn_receiver.h"
3130#include " stubborn_sender.h"
@@ -81,19 +80,17 @@ bool NextPacketIsMspData = false; // if true the next packet will contain the m
8180
8281// //////////SYNC PACKET/////////
8382// / sync packet spamming on mode change vars ///
84- #define syncSpamAResidualTimeMS 1500 // we spam some more after rate change to help link get up to speed
83+ #define syncSpamAResidualTimeMS 500 // we spam some more after rate change to help link get up to speed
8584#define syncSpamAmount 3
8685volatile uint8_t syncSpamCounter = 0 ;
8786uint32_t rfModeLastChangedMS = 0 ;
88- // //////////////////////////////////////////////
89-
9087uint32_t SyncPacketLastSent = 0 ;
88+ // //////////////////////////////////////////////
9189
9290volatile uint32_t LastTLMpacketRecvMillis = 0 ;
9391uint32_t TLMpacketReported = 0 ;
9492
9593LQCALC<10 > LQCalc;
96- LPF LPD_DownlinkLQ (1 );
9794
9895volatile bool busyTransmitting;
9996volatile bool UpdateModelReq = false ;
@@ -248,7 +245,6 @@ void ICACHE_RAM_ATTR ProcessTLMpacket()
248245 if (connectionState != connected)
249246 {
250247 connectionState = connected;
251- LPD_DownlinkLQ.init (100 );
252248 VtxConfigReadyToSend = true ;
253249 DBGLN (" got downlink conn" );
254250 }
@@ -270,7 +266,7 @@ void ICACHE_RAM_ATTR ProcessTLMpacket()
270266 // crsf.LinkStatistics.uplink_TX_Power = POWERMGNT.powerToCrsfPower(POWERMGNT.currPower()); // TX power is updated when sent
271267 crsf.LinkStatistics .downlink_SNR = Radio.LastPacketSNR ;
272268 crsf.LinkStatistics .downlink_RSSI = Radio.LastPacketRSSI ;
273- crsf.LinkStatistics .downlink_Link_quality = LPD_DownlinkLQ. update ( LQCalc.getLQ ()) + 1 ; // +1 fixes rounding issues with filter and makes it consistent with RX LQ Calculation
269+ crsf.LinkStatistics .downlink_Link_quality = LQCalc.getLQ ();
274270 crsf.LinkStatistics .rf_Mode = (uint8_t )RATE_4HZ - (uint8_t )ExpressLRS_currAirRate_Modparams->enum_rate ;
275271 MspSender.ConfirmCurrentPayload (Radio.RXdataBuffer [6 ] == 1 );
276272
@@ -398,27 +394,30 @@ void ICACHE_RAM_ATTR SendRCdataToRF()
398394 }
399395 }
400396
401- uint32_t SyncInterval ;
402-
397+ uint32_t now = millis () ;
398+ static uint8_t syncSlot;
403399#if defined(NO_SYNC_ON_ARM)
404- SyncInterval = 250 ;
400+ uint32_t SyncInterval = 250 ;
405401 bool skipSync = IsArmed ();
406402#else
407- SyncInterval = (connectionState == connected) ? ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalConnected : ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalDisconnected ;
403+ uint32_t SyncInterval = (connectionState == connected) ? ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalConnected : ExpressLRS_currAirRate_RFperfParams->SyncPktIntervalDisconnected ;
408404 bool skipSync = false ;
409405#endif
410406
411407 uint8_t NonceFHSSresult = NonceTX % ExpressLRS_currAirRate_Modparams->FHSShopInterval ;
412- bool NonceFHSSresultWindow = (NonceFHSSresult == 1 || NonceFHSSresult == 2 ) ? true : false ; // restrict to the middle nonce ticks (not before or after freq chance)
413- bool WithinSyncSpamResidualWindow = (millis () - rfModeLastChangedMS < syncSpamAResidualTimeMS) ? true : false ;
408+ bool WithinSyncSpamResidualWindow = now - rfModeLastChangedMS < syncSpamAResidualTimeMS;
414409
415- if ((syncSpamCounter || WithinSyncSpamResidualWindow) && NonceFHSSresultWindow)
410+ // Sync spam only happens on slot 1 and 2 and can't be disabled
411+ if ((syncSpamCounter || WithinSyncSpamResidualWindow) && (NonceFHSSresult == 1 || NonceFHSSresult == 2 ))
416412 {
417413 GenerateSyncPacketData ();
418414 }
419- else if ((!skipSync) && ((millis () > (SyncPacketLastSent + SyncInterval)) && (Radio.currFreq == GetInitialFreq ()) && NonceFHSSresultWindow)) // don't sync just after we changed freqs (helps with hwTimer.init() being in sync from the get go)
415+ // Regular sync rotates through 4x slots, twice on each slot, and telemetry pushes it to the next slot up
416+ // But only on the sync FHSS channel and with a timed delay between them
417+ else if ((!skipSync) && ((syncSlot / 2 ) <= NonceFHSSresult) && (now - SyncPacketLastSent > SyncInterval) && (Radio.currFreq == GetInitialFreq ()))
420418 {
421419 GenerateSyncPacketData ();
420+ syncSlot = (syncSlot + 1 ) % (ExpressLRS_currAirRate_Modparams->FHSShopInterval * 2 );
422421 }
423422 else
424423 {
@@ -603,7 +602,7 @@ void registerLuaParameters() {
603602 {
604603 // confirm run on ELRSv2.lua or start command from CRSF configurator,
605604 // since ELRS LUA can do 2 step confirmation, it needs confirmation to start wifi to prevent stuck on
606- // unintentional button press.
605+ // unintentional button press.
607606 setLuaCommandValue (&luaWebUpdate,2 ); // running status
608607 webUpdateMode = true ;
609608 DBGLN (" Wifi Update Mode Requested!" );
@@ -614,7 +613,7 @@ void registerLuaParameters() {
614613 setLuaCommandValue (&luaWebUpdate,0 );
615614 }
616615 });
617-
616+
618617 registerLUAParameter (&luaBLEJoystick, [](uint8_t id, uint8_t arg){
619618 if (arg > 0 && arg < 4 ) // start command, 1 = start
620619 // 2 = running
@@ -626,7 +625,7 @@ void registerLuaParameters() {
626625 {
627626 // confirm run on ELRSv2.lua or start command from CRSF configurator,
628627 // since ELRS LUA can do 2 step confirmation, it needs confirmation to start wifi to prevent stuck on
629- // unintentional button press.
628+ // unintentional button press.
630629 setLuaCommandValue (&luaBLEJoystick,2 ); // running status
631630 BLEjoystickActive = true ;
632631 #ifndef DEBUG_SUPPRESS
@@ -669,7 +668,7 @@ void resetLuaParams(){
669668
670669 uint8_t dynamic = config.GetDynamicPower () ? config.GetBoostChannel () + 1 : 0 ;
671670 setLuaTextSelectionValue (&luaDynamicPower,dynamic);
672-
671+
673672 setLuaTextSelectionValue (&luaVtxBand,config.GetVtxBand ());
674673 setLuaTextSelectionValue (&luaVtxChannel,config.GetVtxChannel ());
675674 setLuaTextSelectionValue (&luaVtxPwr,config.GetVtxPower ());
@@ -721,7 +720,7 @@ void UARTconnected()
721720static void ChangeRadioParams ()
722721{
723722 config.SetModelId (crsf.getModelID ());
724-
723+
725724 SetRFLinkRate (config.GetRate ());
726725 POWERMGNT.setPower ((PowerLevels_e)config.GetPower ());
727726 OtaSetSwitchMode ((OtaSwitchMode_e)config.GetSwitchMode ());
@@ -1029,7 +1028,7 @@ void loop()
10291028 msp.markPacketReceived ();
10301029 }
10311030 }
1032-
1031+
10331032 if (VtxConfigReadyToSend)
10341033 {
10351034 VtxConfigReadyToSend = false ;
0 commit comments