Skip to content

Commit 7285a67

Browse files
committed
tidy-up and cms screen buffer logic fix
1 parent a845bb8 commit 7285a67

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

src/SCRIPTS/BF/CMS/common.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local _ = {
1+
local CONST = {
22
bitmask = {
33
firstChunk = 0x80,
44
lastChunk = 0x40,
@@ -17,16 +17,16 @@ local function cRleDecode(buf)
1717
local dest = {}
1818
local rpt = false
1919
local c = nil
20-
for i=1, #buf do
20+
for i = 1, #buf do
2121
if (rpt == false) then
22-
c = bit32.band(buf[i], _.bitmask.rleCharValueMask)
23-
if (bit32.band(buf[i], _.bitmask.rleCharRepeatedMask) > 0) then
22+
c = bit32.band(buf[i], CONST.bitmask.rleCharValueMask)
23+
if (bit32.band(buf[i], CONST.bitmask.rleCharRepeatedMask) > 0) then
2424
rpt = true
2525
else
2626
dest[#dest + 1] = c
2727
end
2828
else
29-
for j=1, buf[i] do
29+
for j = 1, buf[i] do
3030
dest[#dest + 1] = c
3131
end
3232
rpt = false
@@ -48,15 +48,15 @@ screen = {
4848
screen.sequence = 0
4949
end,
5050
draw = function()
51-
if (#screen.buffer ~= nil and screen.config ~= nil and #screen.buffer > 0) then
51+
if (screen.buffer ~= nil and screen.config ~= nil and #screen.buffer > 0) then
5252
lcd.clear()
53-
for char=1,#screen.buffer do
53+
for char = 1, #screen.buffer do
5454
if (screen.buffer[char] ~= 32) then -- skip spaces to avoid CPU spikes
5555
c = string.char(screen.buffer[char])
56-
row = math.ceil(char/screen.config.cols)
57-
col = char-((row-1)*screen.config.cols)
58-
xPos = ((col-1)*screen.config.pixelsPerChar)+screen.config.xIndent+1
59-
yPos = ((row-1)*screen.config.pixelsPerRow)+screen.config.yOffset+1
56+
row = math.ceil(char / screen.config.cols)
57+
col = char - ((row - 1) * screen.config.cols)
58+
xPos = ((col - 1) * screen.config.pixelsPerChar) + screen.config.xIndent + 1
59+
yPos = ((row - 1) * screen.config.pixelsPerRow) + screen.config.yOffset + 1
6060
lcd.drawText(xPos, yPos, c, screen.config.textSize)
6161
end
6262
end
@@ -86,13 +86,13 @@ cms = {
8686
update = function()
8787
local command, data = protocol.cms.poll()
8888
if (command == "update") then
89-
local firstChunk = bit32.band(data[_.offset.meta], _.bitmask.firstChunk)
90-
local lastChunk = bit32.band(data[_.offset.meta], _.bitmask.lastChunk)
91-
local batchId = bit32.band(data[_.offset.meta], _.bitmask.batchId)
92-
local sequence = data[_.offset.sequence]
89+
local firstChunk = bit32.band(data[CONST.offset.meta], CONST.bitmask.firstChunk)
90+
local lastChunk = bit32.band(data[CONST.offset.meta], CONST.bitmask.lastChunk)
91+
local batchId = bit32.band(data[CONST.offset.meta], CONST.bitmask.batchId)
92+
local sequence = data[CONST.offset.sequence]
9393
local frameData = {}
94-
for i=_.offset.data, #data do
95-
frameData[#frameData+1] = data[i]
94+
for i = CONST.offset.data, #data do
95+
frameData[#frameData + 1] = data[i]
9696
end
9797
if (firstChunk ~= 0) then
9898
screen.reset()
@@ -101,7 +101,7 @@ cms = {
101101
end
102102
if (screen.batchId == batchId) and (screen.sequence == sequence) then
103103
screen.sequence = sequence + 1
104-
for i=1,#frameData do
104+
for i = 1, #frameData do
105105
screen.data[#screen.data + 1] = frameData[i]
106106
end
107107
if (lastChunk ~= 0) then

src/SCRIPTS/BF/CMS/crsf.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local _ = {
1+
local CONST = {
22
frame = {
33
destination = 1,
44
source = 2,
@@ -22,43 +22,43 @@ local _ = {
2222
}
2323

2424
local function crsfDisplayPortCmd(cmd, data)
25-
local payloadOut = { _.address.betaflight, _.address.transmitter, cmd }
25+
local payloadOut = { CONST.address.betaflight, CONST.address.transmitter, cmd }
2626
if data ~= nil then
27-
for i=1,#(data) do
28-
payloadOut[3+i] = data[i]
27+
for i = 1, #(data) do
28+
payloadOut[3 + i] = data[i]
2929
end
3030
end
31-
return crossfireTelemetryPush(_.frameType.displayPort, payloadOut)
31+
return crossfireTelemetryPush(CONST.frameType.displayPort, payloadOut)
3232
end
3333

3434
protocol.cms.poll = function()
3535
local command = nil
3636
local dataOut = {}
3737
local frameType, data = crossfireTelemetryPop()
3838
if (data ~= nil) and (#data > 2) then
39-
if (frameType == _.frameType.displayPort) and (data[_.frame.destination] == _.address.transmitter) and (data[_.frame.source] == _.address.betaflight) then
40-
for k,v in pairs(_.command) do
41-
if (v == data[_.frame.command]) then
39+
if (frameType == CONST.frameType.displayPort) and (data[CONST.frame.destination] == CONST.address.transmitter) and (data[CONST.frame.source] == CONST.address.betaflight) then
40+
for k,v in pairs(CONST.command) do
41+
if (v == data[CONST.frame.command]) then
4242
command = k
4343
end
4444
end
45-
for i=_.frame.content, #data do
46-
dataOut[#dataOut+1] = data[i]
45+
for i = CONST.frame.content, #data do
46+
dataOut[#dataOut + 1] = data[i]
4747
end
4848
end
4949
end
5050
return command, dataOut
5151
end
5252

5353
protocol.cms.open = function(rows, cols)
54-
return crsfDisplayPortCmd(_.command.open, { rows, cols })
54+
return crsfDisplayPortCmd(CONST.command.open, { rows, cols })
5555
end
5656

5757
protocol.cms.close = function()
58-
return crsfDisplayPortCmd(_.command.close, nil)
58+
return crsfDisplayPortCmd(CONST.command.close, nil)
5959
end
6060

6161
protocol.cms.refresh = function()
62-
return crsfDisplayPortCmd(_.command.refresh, nil)
62+
return crsfDisplayPortCmd(CONST.command.refresh, nil)
6363
end
6464

src/SCRIPTS/FUNCTIONS/bfbkgd.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
chdir("/SCRIPTS/BF")
22
apiVersion = 0
33
protocol = assert(loadScript("protocols.lua"))()
4-
assert(loadScript(protocol.transport))()
4+
assert(loadScript(protocol.mspTransport))()
55
assert(loadScript("MSP/common.lua"))()
66
local background = assert(loadScript("background.lua"))()
77

0 commit comments

Comments
 (0)