Skip to content

Commit

Permalink
Support MSP_RADIO_SETUP
Browse files Browse the repository at this point in the history
  • Loading branch information
atomgomba committed Feb 5, 2024
1 parent 5b8891e commit 3e35b9d
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/SCRIPTS/BF/features_info.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
local MSP_GPS_CONFIG = 135
local MSP_VTX_CONFIG = 88
local MSP_GPS_CONFIG = 135
local MSP_OSD_CONFIG = 84
local MSP_BUILD_INFO = 5

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

local BUILD_OPTION_VTX = bit32.lshift(1, 0)
local BUILD_OPTION_GPS = bit32.lshift(1, 1)
local BUILD_OPTION_OSD_SD = bit32.lshift(1, 2)

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

local lastRunTS = 0
Expand All @@ -20,29 +21,31 @@ local returnTable = {
t = "",
}

local function processBuildInfoReply(payload)
-- TODO: parse build options
local function processRadioSetupReply(payload)
isVtxRead = true
isGpsRead = true
isOsdSDRead = true

features.vtx = bit32.band(payload[1], BUILD_OPTION_VTX) ~= 0
features.gps = bit32.band(payload[1], BUILD_OPTION_GPS) ~= 0
features.osdSD = bit32.band(payload[1], BUILD_OPTION_OSD_SD) ~= 0
end

local function processMspReply(cmd, payload, err)
isInFlight = false
local isOkay = not err
if cmd == MSP_BUILD_INFO then
if not isOkay then
return
if cmd == MSP_RADIO_SETUP then
if isOkay then
processRadioSetupReply(payload)
end
isGpsRead = true
elseif cmd == MSP_VTX_CONFIG then
isVtxRead = true
isOsdSDRead = true
processBuildInfoReply(payload)
local vtxTableAvailable = payload[12] ~= 0
features.vtx = isOkay and vtxTableAvailable
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
Expand All @@ -55,14 +58,14 @@ local function updateFeatures()
lastRunTS = getTime()
local cmd
if apiVersion >= 1.47 then
cmd = MSP_BUILD_INFO
cmd = MSP_RADIO_SETUP
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 isGpsRead then
cmd = MSP_GPS_CONFIG
returnTable.t = "Checking GPS..."
elseif not isOsdSDRead then
cmd = MSP_OSD_CONFIG
returnTable.t = "Checking OSD (SD)..."
Expand All @@ -74,7 +77,7 @@ local function updateFeatures()
end
mspProcessTxQ()
processMspReply(mspPollReply())
return isGpsRead and isVtxRead and isOsdSDRead
return isVtxRead and isGpsRead and isOsdSDRead
end

returnTable.f = updateFeatures
Expand Down

0 comments on commit 3e35b9d

Please sign in to comment.