MSP/SPORT: BFSetup LUA script fixes

- added MSP_EEPROM_WRITE after value upload.
- added timeout for saving (1.5s) + second retry.
- invalidate pages on telemetry lost.
- do not write values in LUA if reply set is empty.
- reset state on invalidatePages()
- removed “(…)” after the page title when loading.
This commit is contained in:
Raphael Coeffic 2016-11-15 22:25:12 +01:00
parent 837a17bbac
commit 4d92ce25d3
1 changed files with 41 additions and 25 deletions

View File

@ -255,6 +255,8 @@ local MSP_SET_RC_TUNING = 204
local MSP_PID_ADVANCED = 94 local MSP_PID_ADVANCED = 94
local MSP_SET_PID_ADVANCED = 95 local MSP_SET_PID_ADVANCED = 95
local MSP_EEPROM_WRITE = 250
local REQ_TIMEOUT = 80 -- 800ms request timeout local REQ_TIMEOUT = 80 -- 800ms request timeout
--local PAGE_REFRESH = 1 --local PAGE_REFRESH = 1
@ -317,13 +319,20 @@ local SetupPages = {
local currentPage = 1 local currentPage = 1
local currentLine = 1 local currentLine = 1
local saveTS = 0
local saveRetries = 0
local function saveSettings() local function saveSettings(new)
local page = SetupPages[currentPage] local page = SetupPages[currentPage]
if page.values then if page.values then
mspSendRequest(page.write,page.values) mspSendRequest(page.write,page.values)
saveTS = getTime()
if gState == PAGE_SAVING then
saveRetries = saveRetries + 1
else
gState = PAGE_SAVING gState = PAGE_SAVING
end end
end
end end
local function invalidatePages() local function invalidatePages()
@ -331,6 +340,8 @@ local function invalidatePages()
local page = SetupPages[i] local page = SetupPages[i]
page.values = nil page.values = nil
end end
gState = PAGE_DISPLAY
saveTS = 0
end end
local menuList = { local menuList = {
@ -344,7 +355,6 @@ local menuList = {
local telemetryScreenActive = false local telemetryScreenActive = false
local menuActive = false local menuActive = false
--local editingValue = false
local function processMspReply(cmd,rx_buf) local function processMspReply(cmd,rx_buf)
@ -356,8 +366,14 @@ local function processMspReply(cmd,rx_buf)
-- ignore replies to write requests for now -- ignore replies to write requests for now
if cmd == page.write then if cmd == page.write then
mspSendRequest(MSP_EEPROM_WRITE,{})
return
end
if cmd == MSP_EEPROM_WRITE then
gState = PAGE_DISPLAY gState = PAGE_DISPLAY
page.values = nil page.values = nil
saveTS = 0
return return
end end
@ -365,10 +381,12 @@ local function processMspReply(cmd,rx_buf)
return return
end end
if #(rx_buf) > 0 then
page.values = {} page.values = {}
for i=1,#(rx_buf) do for i=1,#(rx_buf) do
page.values[i] = rx_buf[i] page.values[i] = rx_buf[i]
end end
end
end end
local function MaxLines() local function MaxLines()
@ -414,10 +432,6 @@ local function drawScreen(page,page_locked)
local screen_title = page.title local screen_title = page.title
if page_locked then
screen_title = screen_title .. " (...)"
end
lcd.drawScreenTitle('Betaflight setup: '..screen_title,currentPage,#(SetupPages)) lcd.drawScreenTitle('Betaflight setup: '..screen_title,currentPage,#(SetupPages))
for i=1,#(page.text) do for i=1,#(page.text) do
@ -495,22 +509,31 @@ end
local EVT_MENU_LONG = bit32.bor(bit32.band(EVT_MENU_BREAK,0x1f),0x80) local EVT_MENU_LONG = bit32.bor(bit32.band(EVT_MENU_BREAK,0x1f),0x80)
local bgCounter = 0 local lastRunTS = 0
local function run(event) local function run(event)
local now = getTime() local now = getTime()
if not telemetryScreenActive then -- if lastRunTS old than 500ms
telemetryScreenActive = true if lastRunTS + 50 < now then
invalidatePages() invalidatePages()
end end
lastRunTS = now
-- TODO: implement retry + retry counter
if (gState == PAGE_SAVING) and (saveTS + 150 < now) then
if saveRetries < 2 then
saveSettings()
else
-- two retries and still no success
gState = PAGE_DISPLAY
saveTS = 0
end
end
if #(mspTxBuf) > 0 then if #(mspTxBuf) > 0 then
mspProcessTxQ() mspProcessTxQ()
--if (gState == PAGE_SAVING) and (#(mspTxBuf) == 0) then
-- gState = PAGE_REFRESH
--end
end end
-- navigation -- navigation
@ -574,11 +597,9 @@ local function run(event)
if getValue("RSSI") == 0 then if getValue("RSSI") == 0 then
-- No! -- No!
lcd.drawText(70,55,"No telemetry",BLINK) lcd.drawText(70,55,"No telemetry",BLINK)
invalidatePages()
end end
--lcd.drawNumber(10,56,mspRequestsSent)
--lcd.drawNumber(30,56,mspTxPk)
if gState == MENU_DISP then if gState == MENU_DISP then
drawMenu() drawMenu()
elseif gState == PAGE_SAVING then elseif gState == PAGE_SAVING then
@ -591,9 +612,4 @@ local function run(event)
return 0 return 0
end end
local function background() return {run=run}
-- telemetryScreenActive = false
-- bgCounter = bgCounter + 1
end
return {run=run,background=background}