Skip to content

Commit

Permalink
Merge pull request #496 from atomgomba/hide-osd-sd-settings
Browse files Browse the repository at this point in the history
Hide OSD (SD) settings
  • Loading branch information
haslinghuis committed Mar 23, 2024
2 parents c6936dd + 61e8f4c commit de29b66
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/SCRIPTS/BF/PAGES/pos_osd.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local template = assert(loadScript(radio.template))()
local margin = template.margin
local indent = template.indent
local lineSpacing = template.lineSpacing
local tableSpacing = template.tableSpacing
local sp = template.listSpacing.field
local yMinLim = radio.yMinLimit
local x = margin
local y = yMinLim - lineSpacing
Expand Down Expand Up @@ -133,12 +131,12 @@ return {
self.values[3] = bit32.rshift(combineValue, 8)
return self.values
end,
checkProfile = function(self, value, profileFirst, profileSecond, profileThird)
checkProfile = function(_, value, profileFirst, profileSecond, profileThird)
local profiles = profileFirst + bit32.lshift(profileSecond, 1) + bit32.lshift(profileThird, 2)
local output = bit32.replace(value, profiles, 11, 3)
return output
end,
splitVal = function(self, inputFirstVal, inputSecondVal)
splitVal = function(_, inputFirstVal, inputSecondVal)
local inputVal = inputFirstVal + bit32.lshift(inputSecondVal, 8)
local profiles = bit32.extract(inputVal, 11, 3)
local fieldPos = bit32.extract(inputVal, 0, 11)
Expand Down
6 changes: 4 additions & 2 deletions src/SCRIPTS/BF/features.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local features = {
vtx = true,
gps = true,
vtx = true,
gps = true,
osdSD = true,
blackbox = true,
}

return features
62 changes: 56 additions & 6 deletions src/SCRIPTS/BF/features_info.lua
Original file line number Diff line number Diff line change
@@ -1,50 +1,100 @@
local MSP_GPS_CONFIG = 135
local MSP_VTX_CONFIG = 88
local MSP_OSD_CONFIG = 84

local MSP_BUILD_INFO = 5

local BUILD_OPTION_GPS = 16412
local BUILD_OPTION_VTX = 16421
local BUILD_OPTION_OSD_SD = 16416

local isGpsRead = false
local isVtxRead = false
local isOsdSDRead = false

local lastRunTS = 0
local INTERVAL = 100
local isInFlight = false

local returnTable = {
f = nil,
t = "",
}

local function processBuildInfoReply(payload)
local headLength = 26 -- DATE(11) + TIME(8) + REVISION(7)
local optionsLength = #payload - headLength
if (optionsLength <= 0) or ((optionsLength % 2) ~= 0) then
return -- invalid payload
end

features.gps = false
features.vtx = false
features.osdSD = false
for i = headLength + 1, #payload, 2 do
local byte1 = bit32.lshift(payload[i], 0)
local byte2 = bit32.lshift(payload[i + 1], 8)
local word = bit32.bor(byte1, byte2)
if word == BUILD_OPTION_GPS then
features.gps = true
elseif word == BUILD_OPTION_VTX then
features.vtx = true
elseif word == BUILD_OPTION_OSD_SD then
features.osdSD = true
end
end
end

local function processMspReply(cmd, payload, err)
isInFlight = false
local isOkay = not err
if cmd == MSP_GPS_CONFIG then
if cmd == MSP_BUILD_INFO then
isGpsRead = true
isVtxRead = true
isOsdSDRead = true
if isOkay then
processBuildInfoReply(payload)
end
elseif cmd == MSP_GPS_CONFIG then
isGpsRead = true
local providerSet = payload[1] ~= 0
features.gps = isOkay and providerSet
elseif cmd == MSP_VTX_CONFIG then
isVtxRead = true
local vtxTableAvailable = payload[12] ~= 0
features.vtx = isOkay and vtxTableAvailable
elseif cmd == MSP_OSD_CONFIG then
isOsdSDRead = true
local osdSDAvailable = payload[1] ~= 0
features.osdSD = isOkay and osdSDAvailable
end
end

local function updateFeatures()
if lastRunTS + INTERVAL < getTime() then
lastRunTS = getTime()
local cmd
if not isGpsRead then
if apiVersion >= 1.46 then
cmd = MSP_BUILD_INFO
returnTable.t = "Checking options..."
elseif not isGpsRead then
cmd = MSP_GPS_CONFIG
returnTable.t = "Checking GPS..."
elseif not isVtxRead then
cmd = MSP_VTX_CONFIG
returnTable.t = "Checking VTX..."
elseif not isOsdSDRead then
cmd = MSP_OSD_CONFIG
returnTable.t = "Checking OSD (SD)..."
end
if cmd then
if cmd and not isInFlight then
protocol.mspRead(cmd)
else
return true
isInFlight = true
end
end
mspProcessTxQ()
processMspReply(mspPollReply())
return false
return isGpsRead and isVtxRead and isOsdSDRead
end

returnTable.f = updateFeatures
Expand Down
2 changes: 1 addition & 1 deletion src/SCRIPTS/BF/pages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if apiVersion >= 1.16 then
PageFiles[#PageFiles + 1] = { title = "Trim Accelerometer", script = "acc_trim.lua" }
end

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

Expand Down

0 comments on commit de29b66

Please sign in to comment.