Skip to content

Mcu ID for vtx tables #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/SCRIPTS/BF/PAGES/vtx.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local md = model.getInfo();
local vtx_tables = loadScript("/BF/VTX/"..md.name..".lua")
if vtx_tables then
vtx_tables = vtx_tables()
local vtx_tables
if apiVersion >= 1.042 then
vtx_tables = assert(loadScript("/BF/VTX/"..mcuId..".lua"))()
else
vtx_tables = assert(loadScript("/BF/VTX/vtx_defaults.lua"))()
end
Expand Down
37 changes: 37 additions & 0 deletions src/SCRIPTS/BF/mcu_id.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local MSP_UID = 160

local MCUIdReceived = false

local lastRunTS = 0
local INTERVAL = 100

local function processMspReply(cmd, payload)
if cmd == MSP_UID then
local i = 1
local id = ""
for j = 1, 3 do
local s = ""
for k = 1, 4 do
s = string.format("%02x", payload[i])..s
i = i + 1
end
id = id..s
end
mcuId = id
MCUIdReceived = true
end
end

local function getMCUId()
if lastRunTS + INTERVAL < getTime() then
lastRunTS = getTime()
if not MCUIdReceived then
protocol.mspRead(MSP_UID)
end
end
mspProcessTxQ()
processMspReply(mspPollReply())
return MCUIdReceived
end

return getMCUId
2 changes: 1 addition & 1 deletion src/SCRIPTS/BF/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ local function getVtxTables()
uiState = uiStatus.init
PageFiles = nil
invalidatePages()
io.close(io.open("/BF/VTX/"..model.getInfo().name..".lua", 'w'))
io.close(io.open("/BF/VTX/"..mcuId..".lua", 'w'))
return 0
end

Expand Down
23 changes: 14 additions & 9 deletions src/SCRIPTS/BF/ui_init.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
local apiVersionReceived = false
local vtxTablesReceived = false
local data_init, getVtxTables
local vtxTables = loadScript("/BF/VTX/"..model.getInfo().name..".lua")

if vtxTables and vtxTables() then
vtxTablesReceived = true
vtxTables = nil
collectgarbage()
end
local data_init, getVtxTables, getMCUId

local function init()
if apiVersion == 0 then
Expand All @@ -18,6 +11,18 @@ local function init()
data_init = nil
apiVersionReceived = true
collectgarbage()
elseif apiVersion >= 1.042 and not mcuId then
lcd.drawText(6, radio.yMinLimit, "Waiting for device ID")
getMCUId = getMCUId or assert(loadScript("mcu_id.lua"))()
if getMCUId() then
getMCUId = nil
local vtxTables = loadScript("/BF/VTX/"..mcuId..".lua")
if vtxTables and vtxTables() then
vtxTablesReceived = true
vtxTables = nil
end
collectgarbage()
end
elseif apiVersion >= 1.042 and not vtxTablesReceived then
lcd.drawText(6, radio.yMinLimit, "Downloading VTX Tables")
getVtxTables = getVtxTables or assert(loadScript("vtx_tables.lua"))()
Expand All @@ -29,7 +34,7 @@ local function init()
else
return true
end
return apiVersionReceived and vtxTablesReceived
return apiVersionReceived and vtxTablesReceived and mcuId
end

return init
4 changes: 2 additions & 2 deletions src/SCRIPTS/BF/vtx_tables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local function getVtxTables()
end
end
if vtxTablesReceived then
local f = io.open("/BF/VTX/"..model.getInfo().name..".lua", 'w')
local f = io.open("/BF/VTX/"..mcuId..".lua", 'w')
io.write(f, "return {", "\n")
io.write(f, " frequencyTable = {", "\n")
for i = 1, #frequencyTable do
Expand All @@ -109,7 +109,7 @@ local function getVtxTables()
io.write(f, powerString, "\n")
io.write(f, "}", "\n")
io.close(f)
assert(loadScript("/BF/VTX/"..model.getInfo().name..".lua", 'c'))
assert(loadScript("/BF/VTX/"..mcuId..".lua", 'c'))
end
mspProcessTxQ()
processMspReply(mspPollReply())
Expand Down
1 change: 1 addition & 0 deletions src/SCRIPTS/TOOLS/bf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local toolName = "TNS|Betaflight setup|TNE"
chdir("/SCRIPTS/BF")

apiVersion = 0
mcuId = nil

local run = nil
local scriptsCompiled = assert(loadScript("COMPILE/scripts_compiled.lua"))()
Expand Down