forked from betaflight/betaflight-tx-lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui_init.lua
51 lines (48 loc) · 1.75 KB
/
ui_init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local apiVersionReceived = false
local mcuIdReceived = false
local boardInfoReceived = false
local featuresReceived = false
local getApiVersion, getMCUId, getBoardInfo, getFeaturesInfo
local returnTable = { f = nil, t = "" }
local function init()
if getRSSI() == 0 then
returnTable.t = "Waiting for connection"
elseif not apiVersionReceived then
getApiVersion = getApiVersion or assert(loadScript("api_version.lua"))()
returnTable.t = getApiVersion.t
apiVersionReceived = getApiVersion.f()
if apiVersionReceived then
getApiVersion = nil
collectgarbage()
end
elseif not mcuIdReceived and apiVersion >= 1.42 then
getMCUId = getMCUId or assert(loadScript("mcu_id.lua"))()
returnTable.t = getMCUId.t
mcuIdReceived = getMCUId.f()
if mcuIdReceived then
getMCUId = nil
collectgarbage()
end
elseif not boardInfoReceived and apiVersion >= 1.44 then
getBoardInfo = getBoardInfo or assert(loadScript("board_info.lua"))()
returnTable.t = getBoardInfo.t
boardInfoReceived = getBoardInfo.f()
if boardInfoReceived then
getBoardInfo = nil
collectgarbage()
end
elseif not featuresReceived and apiVersion >= 1.41 then
getFeaturesInfo = getFeaturesInfo or assert(loadScript("features_info.lua"))()
returnTable.t = getFeaturesInfo.t
featuresReceived = getFeaturesInfo.f()
if featuresReceived then
getFeaturesInfo = nil
collectgarbage()
end
else
return true
end
return apiVersionReceived and vtxTablesReceived and mcuId and boardInfoReceived and featuresReceived
end
returnTable.f = init
return returnTable