Skip to content

Commit de29b66

Browse files
authored
Merge pull request #496 from atomgomba/hide-osd-sd-settings
Hide OSD (SD) settings
2 parents c6936dd + 61e8f4c commit de29b66

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

src/SCRIPTS/BF/PAGES/pos_osd.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
local template = assert(loadScript(radio.template))()
22
local margin = template.margin
3-
local indent = template.indent
43
local lineSpacing = template.lineSpacing
54
local tableSpacing = template.tableSpacing
6-
local sp = template.listSpacing.field
75
local yMinLim = radio.yMinLimit
86
local x = margin
97
local y = yMinLim - lineSpacing
@@ -133,12 +131,12 @@ return {
133131
self.values[3] = bit32.rshift(combineValue, 8)
134132
return self.values
135133
end,
136-
checkProfile = function(self, value, profileFirst, profileSecond, profileThird)
134+
checkProfile = function(_, value, profileFirst, profileSecond, profileThird)
137135
local profiles = profileFirst + bit32.lshift(profileSecond, 1) + bit32.lshift(profileThird, 2)
138136
local output = bit32.replace(value, profiles, 11, 3)
139137
return output
140138
end,
141-
splitVal = function(self, inputFirstVal, inputSecondVal)
139+
splitVal = function(_, inputFirstVal, inputSecondVal)
142140
local inputVal = inputFirstVal + bit32.lshift(inputSecondVal, 8)
143141
local profiles = bit32.extract(inputVal, 11, 3)
144142
local fieldPos = bit32.extract(inputVal, 0, 11)

src/SCRIPTS/BF/features.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
local features = {
2-
vtx = true,
3-
gps = true,
2+
vtx = true,
3+
gps = true,
4+
osdSD = true,
5+
blackbox = true,
46
}
57

68
return features

src/SCRIPTS/BF/features_info.lua

+56-6
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,100 @@
11
local MSP_GPS_CONFIG = 135
22
local MSP_VTX_CONFIG = 88
3+
local MSP_OSD_CONFIG = 84
4+
5+
local MSP_BUILD_INFO = 5
6+
7+
local BUILD_OPTION_GPS = 16412
8+
local BUILD_OPTION_VTX = 16421
9+
local BUILD_OPTION_OSD_SD = 16416
310

411
local isGpsRead = false
512
local isVtxRead = false
13+
local isOsdSDRead = false
614

715
local lastRunTS = 0
816
local INTERVAL = 100
17+
local isInFlight = false
918

1019
local returnTable = {
1120
f = nil,
1221
t = "",
1322
}
1423

24+
local function processBuildInfoReply(payload)
25+
local headLength = 26 -- DATE(11) + TIME(8) + REVISION(7)
26+
local optionsLength = #payload - headLength
27+
if (optionsLength <= 0) or ((optionsLength % 2) ~= 0) then
28+
return -- invalid payload
29+
end
30+
31+
features.gps = false
32+
features.vtx = false
33+
features.osdSD = false
34+
for i = headLength + 1, #payload, 2 do
35+
local byte1 = bit32.lshift(payload[i], 0)
36+
local byte2 = bit32.lshift(payload[i + 1], 8)
37+
local word = bit32.bor(byte1, byte2)
38+
if word == BUILD_OPTION_GPS then
39+
features.gps = true
40+
elseif word == BUILD_OPTION_VTX then
41+
features.vtx = true
42+
elseif word == BUILD_OPTION_OSD_SD then
43+
features.osdSD = true
44+
end
45+
end
46+
end
47+
1548
local function processMspReply(cmd, payload, err)
49+
isInFlight = false
1650
local isOkay = not err
17-
if cmd == MSP_GPS_CONFIG then
51+
if cmd == MSP_BUILD_INFO then
52+
isGpsRead = true
53+
isVtxRead = true
54+
isOsdSDRead = true
55+
if isOkay then
56+
processBuildInfoReply(payload)
57+
end
58+
elseif cmd == MSP_GPS_CONFIG then
1859
isGpsRead = true
1960
local providerSet = payload[1] ~= 0
2061
features.gps = isOkay and providerSet
2162
elseif cmd == MSP_VTX_CONFIG then
2263
isVtxRead = true
2364
local vtxTableAvailable = payload[12] ~= 0
2465
features.vtx = isOkay and vtxTableAvailable
66+
elseif cmd == MSP_OSD_CONFIG then
67+
isOsdSDRead = true
68+
local osdSDAvailable = payload[1] ~= 0
69+
features.osdSD = isOkay and osdSDAvailable
2570
end
2671
end
2772

2873
local function updateFeatures()
2974
if lastRunTS + INTERVAL < getTime() then
3075
lastRunTS = getTime()
3176
local cmd
32-
if not isGpsRead then
77+
if apiVersion >= 1.46 then
78+
cmd = MSP_BUILD_INFO
79+
returnTable.t = "Checking options..."
80+
elseif not isGpsRead then
3381
cmd = MSP_GPS_CONFIG
3482
returnTable.t = "Checking GPS..."
3583
elseif not isVtxRead then
3684
cmd = MSP_VTX_CONFIG
3785
returnTable.t = "Checking VTX..."
86+
elseif not isOsdSDRead then
87+
cmd = MSP_OSD_CONFIG
88+
returnTable.t = "Checking OSD (SD)..."
3889
end
39-
if cmd then
90+
if cmd and not isInFlight then
4091
protocol.mspRead(cmd)
41-
else
42-
return true
92+
isInFlight = true
4393
end
4494
end
4595
mspProcessTxQ()
4696
processMspReply(mspPollReply())
47-
return false
97+
return isGpsRead and isVtxRead and isOsdSDRead
4898
end
4999

50100
returnTable.f = updateFeatures

src/SCRIPTS/BF/pages.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if apiVersion >= 1.16 then
6060
PageFiles[#PageFiles + 1] = { title = "Trim Accelerometer", script = "acc_trim.lua" }
6161
end
6262

63-
if apiVersion >= 1.45 then
63+
if apiVersion >= 1.45 and features.osdSD then
6464
PageFiles[#PageFiles + 1] = { title = "OSD Elements", script = "pos_osd.lua" }
6565
end
6666

0 commit comments

Comments
 (0)