Skip to content

Commit cdcbe30

Browse files
authored
Minor Lua fixes following RC2 (ExpressLRS#1100)
* Fix field not actually refreshing after save * Fix connect status not appearing until second update * Only request linkstats if no other telem pushed * Prioritize linkstat over fieldupdate * Delay going to disconnected when TLM ratio increases
1 parent a8d405a commit cdcbe30

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/lua/elrsV2.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ local function parseParameterInfoMessage(data)
533533
allParamsLoaded = 1
534534
fieldId = 1
535535
createDeviceFields()
536-
else
536+
elseif allParamsLoaded == 0 then
537+
-- advance to the next field if doing a full load
537538
fieldId = 1 + (fieldId % (#fields-1))
538539
end
539540
fieldTimeout = getTime() + 200
@@ -554,11 +555,11 @@ local function parseElrsInfoMessage(data)
554555

555556
local badPkt = data[3]
556557
local goodPkt = (data[4]*256) + data[5]
557-
local state = (bit32.btest(elrsFlags, 1) and "C") or "-"
558-
goodBadPkt = string.format("%u/%u %s", badPkt, goodPkt, state)
559-
560558
elrsFlags = data[6]
561559
elrsFlagsInfo = fieldGetString(data, 7)
560+
561+
local state = (bit32.btest(elrsFlags, 1) and "C") or "-"
562+
goodBadPkt = string.format("%u/%u %s", badPkt, goodPkt, state)
562563
end
563564

564565
local function refreshNext()
@@ -583,14 +584,7 @@ local function refreshNext()
583584
elseif time > devicesRefreshTimeout and fields_count < 1 then
584585
devicesRefreshTimeout = time + 100 -- 1s
585586
crossfireTelemetryPush(0x28, { 0x00, 0xEA })
586-
elseif time > fieldTimeout and fields_count ~= 0 and not edit then
587-
if allParamsLoaded < 1 or statusComplete == 0 then
588-
crossfireTelemetryPush(0x2C, { deviceId, handsetId, fieldId, fieldChunk })
589-
fieldTimeout = time + 50 -- 0.5s
590-
end
591-
end
592-
593-
if time > linkstatTimeout then
587+
elseif time > linkstatTimeout then
594588
if not deviceIsELRS_TX and allParamsLoaded == 1 then
595589
goodBadPkt = ""
596590
-- enable both line below to do what the legacy lua is doing which is reloading all params in an interval
@@ -600,7 +594,13 @@ local function refreshNext()
600594
crossfireTelemetryPush(0x2D, { deviceId, handsetId, 0x0, 0x0 }) --request linkstat
601595
end
602596
linkstatTimeout = time + 100
597+
elseif time > fieldTimeout and fields_count ~= 0 and not edit then
598+
if allParamsLoaded < 1 or statusComplete == 0 then
599+
crossfireTelemetryPush(0x2C, { deviceId, handsetId, fieldId, fieldChunk })
600+
fieldTimeout = time + 50 -- 0.5s
601+
end
603602
end
603+
604604
if time > titleShowWarnTimeout then
605605
-- if elrsFlags bit set is bit higher than bit 0 and bit 1, it is warning flags
606606
titleShowWarn = (elrsFlags > 3 and not titleShowWarn) or nil
@@ -729,7 +729,7 @@ local function handleDevicePageEvent(event)
729729
-- data again, with a short delay to allow the module EEPROM to
730730
-- commit. Do this before save() to allow save to override
731731
fieldTimeout = getTime() + 20
732-
fieldId, fieldChunk = field.id, 0
732+
fieldId, fieldChunk, statusComplete = field.id, 0, 0
733733
fieldData = {}
734734
end
735735
functions[field.type+1].save(field)

src/src/tx_main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,21 @@ void ICACHE_RAM_ATTR GenerateSyncPacketData()
292292
Index = (ExpressLRS_currAirRate_Modparams->index & 0b11);
293293
}
294294

295+
if (syncSpamCounter)
296+
--syncSpamCounter;
297+
SyncPacketLastSent = millis();
298+
295299
// TLM ratio is boosted for one sync cycle when the MspSender goes active
296-
if (MspSender.IsActive())
297-
ExpressLRS_currAirRate_Modparams->TLMinterval = TLM_RATIO_1_2;
298-
else
299-
ExpressLRS_currAirRate_Modparams->TLMinterval = (expresslrs_tlm_ratio_e)config.GetTlm();
300-
uint8_t TLMrate = (ExpressLRS_currAirRate_Modparams->TLMinterval & 0b111);
300+
expresslrs_tlm_ratio_e newRatio = (MspSender.IsActive()) ? TLM_RATIO_1_2 : (expresslrs_tlm_ratio_e)config.GetTlm();
301+
// Delay going into disconnected state when the TLM ratio increases
302+
if (connectionState == connected && ExpressLRS_currAirRate_Modparams->TLMinterval < newRatio)
303+
LastTLMpacketRecvMillis = SyncPacketLastSent;
304+
ExpressLRS_currAirRate_Modparams->TLMinterval = newRatio;
301305

302306
Radio.TXdataBuffer[0] = SYNC_PACKET & 0b11;
303307
Radio.TXdataBuffer[1] = FHSSgetCurrIndex();
304308
Radio.TXdataBuffer[2] = NonceTX;
305-
Radio.TXdataBuffer[3] = (Index << 6) + (TLMrate << 3) + (SwitchEncMode << 1);
309+
Radio.TXdataBuffer[3] = (Index << 6) + (newRatio << 3) + (SwitchEncMode << 1);
306310
Radio.TXdataBuffer[4] = UID[3];
307311
Radio.TXdataBuffer[5] = UID[4];
308312
Radio.TXdataBuffer[6] = UID[5];
@@ -311,10 +315,6 @@ void ICACHE_RAM_ATTR GenerateSyncPacketData()
311315
{
312316
Radio.TXdataBuffer[6] ^= (~crsf.getModelID()) & MODELMATCH_MASK;
313317
}
314-
315-
SyncPacketLastSent = millis();
316-
if (syncSpamCounter)
317-
--syncSpamCounter;
318318
}
319319

320320
uint8_t adjustPacketRateForBaud(uint8_t rate)

0 commit comments

Comments
 (0)