|
1 | 1 | local MSP_GPS_CONFIG = 135
|
2 | 2 | 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 |
3 | 10 |
|
4 | 11 | local isGpsRead = false
|
5 | 12 | local isVtxRead = false
|
| 13 | +local isOsdSDRead = false |
6 | 14 |
|
7 | 15 | local lastRunTS = 0
|
8 | 16 | local INTERVAL = 100
|
| 17 | +local isInFlight = false |
9 | 18 |
|
10 | 19 | local returnTable = {
|
11 | 20 | f = nil,
|
12 | 21 | t = "",
|
13 | 22 | }
|
14 | 23 |
|
| 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 | + |
15 | 48 | local function processMspReply(cmd, payload, err)
|
| 49 | + isInFlight = false |
16 | 50 | 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 |
18 | 59 | isGpsRead = true
|
19 | 60 | local providerSet = payload[1] ~= 0
|
20 | 61 | features.gps = isOkay and providerSet
|
21 | 62 | elseif cmd == MSP_VTX_CONFIG then
|
22 | 63 | isVtxRead = true
|
23 | 64 | local vtxTableAvailable = payload[12] ~= 0
|
24 | 65 | 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 |
25 | 70 | end
|
26 | 71 | end
|
27 | 72 |
|
28 | 73 | local function updateFeatures()
|
29 | 74 | if lastRunTS + INTERVAL < getTime() then
|
30 | 75 | lastRunTS = getTime()
|
31 | 76 | 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 |
33 | 81 | cmd = MSP_GPS_CONFIG
|
34 | 82 | returnTable.t = "Checking GPS..."
|
35 | 83 | elseif not isVtxRead then
|
36 | 84 | cmd = MSP_VTX_CONFIG
|
37 | 85 | returnTable.t = "Checking VTX..."
|
| 86 | + elseif not isOsdSDRead then |
| 87 | + cmd = MSP_OSD_CONFIG |
| 88 | + returnTable.t = "Checking OSD (SD)..." |
38 | 89 | end
|
39 |
| - if cmd then |
| 90 | + if cmd and not isInFlight then |
40 | 91 | protocol.mspRead(cmd)
|
41 |
| - else |
42 |
| - return true |
| 92 | + isInFlight = true |
43 | 93 | end
|
44 | 94 | end
|
45 | 95 | mspProcessTxQ()
|
46 | 96 | processMspReply(mspPollReply())
|
47 |
| - return false |
| 97 | + return isGpsRead and isVtxRead and isOsdSDRead |
48 | 98 | end
|
49 | 99 |
|
50 | 100 | returnTable.f = updateFeatures
|
|
0 commit comments