Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions src/SCRIPTS/BF/MSP/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ local MSP_STARTFLAG = bit32.lshift(1,4)
local mspSeq = 0
local mspRemoteSeq = 0
local mspRxBuf = {}
local mspRxIdx = 1
local mspRxCRC = 0
local mspRxReq = 0
local mspStarted = false
local mspLastReq = 0
local mspTxBuf = {}
local mspTxIdx = 1
local mspTxCRC = 0
local mspTxPk = 0

function mspProcessTxQ()
if (#(mspTxBuf) == 0) then
Expand All @@ -31,10 +29,7 @@ function mspProcessTxQ()
payload[1] = payload[1] + MSP_STARTFLAG
end
local i = 2
while (i <= protocol.maxTxBufferSize) do
if mspTxIdx > #(mspTxBuf) then
break
end
while (i <= protocol.maxTxBufferSize) and mspTxIdx <= #mspTxBuf do
payload[i] = mspTxBuf[mspTxIdx]
mspTxIdx = mspTxIdx + 1
mspTxCRC = bit32.bxor(mspTxCRC,payload[i])
Expand All @@ -48,17 +43,13 @@ function mspProcessTxQ()
payload[i] = 0
i = i + 1
end
if protocol.mspSend(payload) then
mspTxPk = mspTxPk + 1
end
protocol.mspSend(payload)
mspTxBuf = {}
mspTxIdx = 1
mspTxCRC = 0
mspTxCRC = 0
return false
end
if protocol.mspSend(payload) then
mspTxPk = mspTxPk + 1
end
protocol.mspSend(payload)
return true
end

Expand Down Expand Up @@ -90,7 +81,6 @@ function mspReceivedReply(payload)
local seq = bit32.band(head,0x0F)
if start then
-- start flag set
mspRxIdx = 1
mspRxBuf = {}
mspRxSize = payload[idx]
mspRxCRC = bit32.bxor(mspRxSize,mspLastReq)
Expand All @@ -103,28 +93,26 @@ function mspReceivedReply(payload)
mspStarted = false
return nil
end
while (idx <= protocol.maxRxBufferSize) and (mspRxIdx <= mspRxSize) do
mspRxBuf[mspRxIdx] = payload[idx]
while (idx <= protocol.maxRxBufferSize) and (#mspRxBuf < mspRxSize) do
mspRxBuf[#mspRxBuf + 1] = payload[idx]
mspRxCRC = bit32.bxor(mspRxCRC,payload[idx])
mspRxIdx = mspRxIdx + 1
idx = idx + 1
end
if idx > protocol.maxRxBufferSize then
mspRemoteSeq = seq
return true
end
mspStarted = false
-- check CRC
if mspRxCRC ~= payload[idx] then
mspStarted = false
return nil
end
mspStarted = false
return mspRxBuf
end

function mspPollReply()
while true do
ret = protocol.mspPoll()
local ret = protocol.mspPoll()
if type(ret) == "table" then
mspLastReq = 0
return mspRxReq, ret
Expand Down
2 changes: 1 addition & 1 deletion src/SCRIPTS/BF/MSP/crsf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol.mspSend = function(payload)
for i=1, #(payload) do
payloadOut[i+2] = payload[i]
end
return crossfireTelemetryPush(crsfMspCmd, payloadOut)
return protocol.push(crsfMspCmd, payloadOut)
end

protocol.mspRead = function(cmd)
Expand Down
17 changes: 7 additions & 10 deletions src/SCRIPTS/BF/MSP/sp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ local REPLY_FRAME_ID = 0x32
local lastSensorId, lastFrameId, lastDataId, lastValue

protocol.mspSend = function(payload)
local dataId = 0
dataId = payload[1] + bit32.lshift(payload[2],8)
local value = 0
value = payload[3] + bit32.lshift(payload[4],8)
local dataId = payload[1] + bit32.lshift(payload[2],8)
local value = payload[3] + bit32.lshift(payload[4],8)
+ bit32.lshift(payload[5],16) + bit32.lshift(payload[6],24)
return sportTelemetryPush(LOCAL_SENSOR_ID, REQUEST_FRAME_ID, dataId, value)
return protocol.push(LOCAL_SENSOR_ID, REQUEST_FRAME_ID, dataId, value)
end

protocol.mspRead = function(cmd)
Expand All @@ -23,15 +21,14 @@ protocol.mspWrite = function(cmd, payload)
return mspSendRequest(cmd, payload)
end

--Discards duplicate data from lua input buffer
-- Discards duplicate data from lua input buffer
local function smartPortTelemetryPop()
local sensorId, frameId, dataId, value
while true do
sensorId, frameId, dataId, value = sportTelemetryPop()
if sensorId == nil then
local sensorId, frameId, dataId, value = sportTelemetryPop()
if not sensorId then
return nil
elseif (lastSensorId == sensorId) and (lastFrameId == frameId) and (lastDataId == dataId) and (lastValue == value) then
--Keep checking
-- Keep checking
else
lastSensorId = sensorId
lastFrameId = frameId
Expand Down
4 changes: 2 additions & 2 deletions src/SCRIPTS/BF/background.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local function run_bg()
-- assuming when sensor value higher than 0 there is an telemetry connection
if not dataInitialised then
if not data_init then
data_init = assert(loadScript(SCRIPT_HOME .. "/data_init.lua"))()
data_init = assert(loadScript("data_init.lua"))()
end

dataInitialised = data_init()
Expand All @@ -37,7 +37,7 @@ local function run_bg()
end
elseif rssiEnabled and apiVersion >= 1.037 then
if not rssiTask then
rssiTask = assert(loadScript(SCRIPT_HOME.."/rssi.lua"))()
rssiTask = assert(loadScript("rssi.lua"))()
end

rssiEnabled = rssiTask()
Expand Down
4 changes: 2 additions & 2 deletions src/SCRIPTS/BF/protocols.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local supportedProtocols =
{
smartPort =
{
transport = SCRIPT_HOME.."/MSP/sp.lua",
transport = "MSP/sp.lua",
rssi = function() return getValue("RSSI") end,
stateSensor = "Tmp1",
push = sportTelemetryPush,
Expand All @@ -13,7 +13,7 @@ local supportedProtocols =
},
crsf =
{
transport = SCRIPT_HOME.."/MSP/crsf.lua",
transport = "MSP/crsf.lua",
rssi = function() return getValue("TQly") end,
stateSensor = "1RSS",
push = crossfireTelemetryPush,
Expand Down
21 changes: 6 additions & 15 deletions src/SCRIPTS/BF/radios.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
lcdResolution =
{
low = 0,
high = 1
}

local supportedRadios =
{
["128x64"] =
{
templateHome = SCRIPT_HOME.."/TEMPLATES/128x64/",
resolution = lcdResolution.low,
templateHome = "TEMPLATES/128x64/",
MenuBox = { x=15, y=12, w=100, x_offset=36, h_line=8, h_offset=3 },
SaveBox = { x=15, y=12, w=100, x_offset=4, h=30, h_offset=5 },
NoTelem = { 30, 55, "No Telemetry", BLINK },
Expand All @@ -19,8 +12,7 @@ local supportedRadios =
},
["212x64"] =
{
templateHome = SCRIPT_HOME.."/TEMPLATES/212x64/",
resolution = lcdResolution.low,
templateHome = "TEMPLATES/212x64/",
MenuBox = { x=40, y=12, w=120, x_offset=36, h_line=8, h_offset=3 },
SaveBox = { x=40, y=12, w=120, x_offset=4, h=30, h_offset=5 },
NoTelem = { 70, 55, "No Telemetry", BLINK },
Expand All @@ -30,8 +22,8 @@ local supportedRadios =
},
["480x272"] =
{
templateHome = SCRIPT_HOME.."/TEMPLATES/480x272/",
resolution = lcdResolution.high,
templateHome = "TEMPLATES/480x272/",
highRes = true,
MenuBox = { x=120, y=100, w=200, x_offset=68, h_line=20, h_offset=6 },
SaveBox = { x=120, y=100, w=180, x_offset=12, h=60, h_offset=12 },
NoTelem = { 192, LCD_H - 28, "No Telemetry", (TEXT_COLOR or 0) + INVERS + BLINK },
Expand All @@ -41,8 +33,8 @@ local supportedRadios =
},
["320x480"] =
{
templateHome = SCRIPT_HOME.."/TEMPLATES/320x480/",
resolution = lcdResolution.high,
templateHome = "TEMPLATES/320x480/",
highRes = true,
MenuBox = { x= (LCD_W -200)/2, y=LCD_H/2, w=200, x_offset=68, h_line=20, h_offset=6 },
SaveBox = { x= (LCD_W -200)/2, y=LCD_H/2, w=180, x_offset=12, h=60, h_offset=12 },
NoTelem = { LCD_W/2 - 50, LCD_H - 28, "No Telemetry", (TEXT_COLOR or 0) + INVERS + BLINK },
Expand All @@ -52,7 +44,6 @@ local supportedRadios =
},
}

local ver, rad, maj, min, rev = getVersion()
local radio = supportedRadios[tostring(LCD_W) .. "x" .. tostring(LCD_H)]

if not radio then
Expand Down
Loading