File tree Expand file tree Collapse file tree 6 files changed +56
-14
lines changed Expand file tree Collapse file tree 6 files changed +56
-14
lines changed Original file line number Diff line number Diff line change 1
- local md = model .getInfo ();
2
- local vtx_tables = loadScript (" /BF/VTX/" .. md .name .. " .lua" )
1
+ local vtx_tables = loadScript (" /BF/VTX/" .. mcuId .. " .lua" )
3
2
if vtx_tables then
4
3
vtx_tables = vtx_tables ()
5
4
else
Original file line number Diff line number Diff line change
1
+ local MSP_UID = 160
2
+
3
+ local MCUIdReceived = false
4
+
5
+ local lastRunTS = 0
6
+ local INTERVAL = 100
7
+
8
+ local function processMspReply (cmd , payload )
9
+ if cmd == MSP_UID then
10
+ local i = 1
11
+ local id = " "
12
+ for j = 1 , 3 do
13
+ local s = " "
14
+ for k = 1 , 4 do
15
+ s = string.format (" %02x" , payload [i ]).. s
16
+ i = i + 1
17
+ end
18
+ id = id .. s
19
+ end
20
+ mcuId = id
21
+ MCUIdReceived = true
22
+ end
23
+ end
24
+
25
+ local function getMCUId ()
26
+ if lastRunTS + INTERVAL < getTime () then
27
+ lastRunTS = getTime ()
28
+ if not MCUIdReceived then
29
+ protocol .mspRead (MSP_UID )
30
+ end
31
+ end
32
+ mspProcessTxQ ()
33
+ processMspReply (mspPollReply ())
34
+ return MCUIdReceived
35
+ end
36
+
37
+ return getMCUId
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ local function getVtxTables()
76
76
uiState = uiStatus .init
77
77
PageFiles = nil
78
78
invalidatePages ()
79
- io.close (io.open (" /BF/VTX/" .. model . getInfo (). name .. " .lua" , ' w' ))
79
+ io.close (io.open (" /BF/VTX/" .. mcuId .. " .lua" , ' w' ))
80
80
return 0
81
81
end
82
82
Original file line number Diff line number Diff line change 1
1
local apiVersionReceived = false
2
2
local vtxTablesReceived = false
3
- local data_init , getVtxTables
4
- local vtxTables = loadScript (" /BF/VTX/" .. model .getInfo ().name .. " .lua" )
5
-
6
- if vtxTables and vtxTables () then
7
- vtxTablesReceived = true
8
- vtxTables = nil
9
- collectgarbage ()
10
- end
3
+ local data_init , getVtxTables , getMCUId
11
4
12
5
local function init ()
13
6
if apiVersion == 0 then
@@ -18,6 +11,18 @@ local function init()
18
11
data_init = nil
19
12
apiVersionReceived = true
20
13
collectgarbage ()
14
+ elseif not mcuId then
15
+ lcd .drawText (6 , radio .yMinLimit , " Waiting for unique device ID" )
16
+ getMCUId = getMCUId or assert (loadScript (" mcu_id.lua" ))()
17
+ if getMCUId () then
18
+ getMCUId = nil
19
+ local vtxTables = loadScript (" /BF/VTX/" .. mcuId .. " .lua" )
20
+ if vtxTables and vtxTables () then
21
+ vtxTablesReceived = true
22
+ vtxTables = nil
23
+ end
24
+ collectgarbage ()
25
+ end
21
26
elseif apiVersion >= 1.042 and not vtxTablesReceived then
22
27
lcd .drawText (6 , radio .yMinLimit , " Downloading VTX Tables" )
23
28
getVtxTables = getVtxTables or assert (loadScript (" vtx_tables.lua" ))()
@@ -29,7 +34,7 @@ local function init()
29
34
else
30
35
return true
31
36
end
32
- return apiVersionReceived and vtxTablesReceived
37
+ return apiVersionReceived and vtxTablesReceived and mcuId
33
38
end
34
39
35
40
return init
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ local function getVtxTables()
82
82
end
83
83
end
84
84
if vtxTablesReceived then
85
- local f = io.open (" /BF/VTX/" .. model . getInfo (). name .. " .lua" , ' w' )
85
+ local f = io.open (" /BF/VTX/" .. mcuId .. " .lua" , ' w' )
86
86
io.write (f , " return {" , " \n " )
87
87
io.write (f , " frequencyTable = {" , " \n " )
88
88
for i = 1 , # frequencyTable do
@@ -109,7 +109,7 @@ local function getVtxTables()
109
109
io.write (f , powerString , " \n " )
110
110
io.write (f , " }" , " \n " )
111
111
io.close (f )
112
- assert (loadScript (" /BF/VTX/" .. model . getInfo (). name .. " .lua" , ' c' ))
112
+ assert (loadScript (" /BF/VTX/" .. mcuId .. " .lua" , ' c' ))
113
113
end
114
114
mspProcessTxQ ()
115
115
processMspReply (mspPollReply ())
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ local toolName = "TNS|Betaflight setup|TNE"
2
2
chdir (" /SCRIPTS/BF" )
3
3
4
4
apiVersion = 0
5
+ mcuId = nil
5
6
6
7
local run = nil
7
8
local scriptsCompiled = assert (loadScript (" COMPILE/scripts_compiled.lua" ))()
You can’t perform that action at this time.
0 commit comments