Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMS fixes #424

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions src/SCRIPTS/BF/CMS/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,26 @@ screen = {
data = {},
batchId = 0,
sequence = 0,
redraws = 2,
reset = function()
screen.buffer = {}
screen.data = {}
screen.batchId = 0
screen.sequence = 0
end,
draw = function()
if (screen.buffer ~= nil and screen.config ~= nil and #screen.buffer > 0) then
screen.clear()
for char = 1, #screen.buffer do
if (screen.buffer[char] ~= 32) then -- skip spaces to avoid CPU spikes
c = string.char(screen.buffer[char])
row = math.ceil(char / screen.config.cols)
col = char - ((row - 1) * screen.config.cols)
xPos = ((col - 1) * screen.config.pixelsPerChar) + screen.config.xIndent + 1
yPos = ((row - 1) * screen.config.pixelsPerRow) + screen.config.yOffset + 1
lcd.drawText(xPos, yPos, c, screen.config.textSize)
end
lcd.clear()
lcd.drawText(screen.config.refresh.left, screen.config.refresh.top, screen.config.refresh.text, screen.config.textSize)
for char = 1, #screen.buffer do
if (screen.buffer[char] ~= 32) then -- skip spaces to avoid CPU spikes
local c = string.char(screen.buffer[char])
local row = math.ceil(char / screen.config.cols)
local col = char - ((row - 1) * screen.config.cols)
local xPos = ((col - 1) * screen.config.pixelsPerChar) + screen.config.xIndent + 1
local yPos = ((row - 1) * screen.config.pixelsPerRow) + screen.config.yOffset + 1
lcd.drawText(xPos, yPos, c, screen.config.textSize)
end
end
end,
clear = function()
lcd.clear()
lcd.drawText(screen.config.refresh.left, screen.config.refresh.top, screen.config.refresh.text, screen.config.textSize)
end
}

cms = {
Expand All @@ -91,27 +86,23 @@ cms = {
update = function()
local command, data = protocol.cms.poll()
if (command == "update") then
local firstChunk = bit32.band(data[CONST.offset.meta], CONST.bitmask.firstChunk)
local lastChunk = bit32.band(data[CONST.offset.meta], CONST.bitmask.lastChunk)
local firstChunk = bit32.btest(data[CONST.offset.meta], CONST.bitmask.firstChunk)
local lastChunk = bit32.btest(data[CONST.offset.meta], CONST.bitmask.lastChunk)
local batchId = bit32.band(data[CONST.offset.meta], CONST.bitmask.batchId)
local sequence = data[CONST.offset.sequence]
local frameData = {}
for i = CONST.offset.data, #data do
frameData[#frameData + 1] = data[i]
end
if (firstChunk ~= 0) then
local sequence = data[CONST.offset.sequence]
if firstChunk then
screen.reset()
screen.batchId = batchId
screen.sequence = 0
end
if (screen.batchId == batchId) and (screen.sequence == sequence) then
screen.sequence = sequence + 1
for i = 1, #frameData do
screen.data[#screen.data + 1] = frameData[i]
for i = CONST.offset.data, #data do
screen.data[#screen.data + 1] = data[i]
end
if (lastChunk ~= 0) then
if lastChunk then
screen.buffer = cRleDecode(screen.data)
screen.draw()
screen.redraws = 2
screen.reset()
cms.synced = true
end
Expand All @@ -122,5 +113,9 @@ cms = {
elseif (command == "clear") then
screen.reset()
end
if screen.redraws > 0 then
screen.draw()
screen.redraws = screen.redraws - 1
end
end
}
26 changes: 12 additions & 14 deletions src/SCRIPTS/BF/cms.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local lastMenuEventTime = 0
local INTERVAL = 80
local firstRun = true

local function init()
cms.init(radio)
Expand All @@ -12,25 +11,24 @@ local function stickMovement()
end

local function run(event)
if firstRun then
screen.clear()
firstRun = false
end
if stickMovement() then
cms.synced = false
lastMenuEventTime = getTime()
end
cms.update()
if (cms.menuOpen == false) then
if cms.menuOpen == false then
cms.open()
end
if (event == radio.refresh.event) or (lastMenuEventTime + INTERVAL < getTime() and not cms.synced) then
cms.refresh()
end
if (event == EVT_VIRTUAL_EXIT) then
if event == radio.refresh.event then
cms.synced = false
lastMenuEventTime = 0
elseif stickMovement() then
cms.synced = false
lastMenuEventTime = getTime()
elseif event == EVT_VIRTUAL_EXIT then
cms.close()
return 1
end
if lastMenuEventTime + INTERVAL < getTime() and not cms.synced then
lastMenuEventTime = getTime()
cms.refresh()
end
return 0
end

Expand Down