11local uiStatus =
22{
33 init = 1 ,
4- pages = 2 ,
5- mainMenu = 3 ,
4+ mainMenu = 2 ,
5+ pages = 3 ,
6+ confirm = 4 ,
67}
78
89local pageStatus =
910{
10- display = 2 ,
11- editing = 3 ,
12- saving = 4 ,
13- popupMenu = 5 ,
11+ display = 1 ,
12+ editing = 2 ,
13+ saving = 3 ,
1414}
1515
1616local uiMsp =
@@ -20,6 +20,7 @@ local uiMsp =
2020}
2121
2222local uiState = uiStatus .init
23+ local prevUiState
2324local pageState = pageStatus .display
2425local requestTimeout = 80
2526local currentPage = 1
@@ -32,7 +33,7 @@ local popupMenuActive = 1
3233local killEnterBreak = 0
3334local pageScrollY = 0
3435local mainMenuScrollY = 0
35- local PageFiles , Page , init , popupMenuList
36+ local PageFiles , Page , init , popupMenu
3637
3738local backgroundFill = TEXT_BGCOLOR or ERASE
3839local foregroundColor = LINE_COLOR or SOLID
@@ -72,30 +73,26 @@ local function eepromWrite()
7273 protocol .mspRead (uiMsp .eepromWrite )
7374end
7475
75- local function accCal ()
76+ local function confirm (page )
77+ prevUiState = uiState
78+ uiState = uiStatus .confirm
7679 invalidatePages ()
7780 currentField = 1
78- Page = assert (loadScript (" Pages/accelerometer.lua " ))()
81+ Page = assert (loadScript (page ))()
7982 collectgarbage ()
8083end
8184
82- local function getVtxTables ()
83- uiState = uiStatus .init
84- PageFiles = nil
85- invalidatePages ()
86- io.close (io.open (" /BF/VTX/" .. mcuId .. " .lua" , ' w' ))
87- return 0
88- end
89-
9085local function createPopupMenu ()
91- popupMenuList = {
92- { t = " save page" , f = saveSettings },
93- { t = " reload" , f = invalidatePages },
94- { t = " reboot" , f = rebootFc },
95- { t = " acc cal" , f = accCal },
96- }
86+ popupMenuActive = 1
87+ popupMenu = {}
88+ if uiState == uiStatus .pages then
89+ popupMenu [# popupMenu + 1 ] = { t = " save page" , f = saveSettings }
90+ popupMenu [# popupMenu + 1 ] = { t = " reload" , f = invalidatePages }
91+ end
92+ popupMenu [# popupMenu + 1 ] = { t = " reboot" , f = rebootFc }
93+ popupMenu [# popupMenu + 1 ] = { t = " acc cal" , f = function () confirm (" CONFIRM/acc_cal.lua" ) end }
9794 if apiVersion >= 1.042 then
98- popupMenuList [ # popupMenuList + 1 ] = { t = " vtx tables" , f = getVtxTables }
95+ popupMenu [ # popupMenu + 1 ] = { t = " vtx tables" , f = function () confirm ( " CONFIRM/vtx_tables.lua " ) end }
9996 end
10097end
10198
@@ -162,7 +159,7 @@ local function incMainMenu(inc)
162159end
163160
164161local function incPopupMenu (inc )
165- popupMenuActive = clipValue (popupMenuActive + inc , 1 , # popupMenuList )
162+ popupMenuActive = clipValue (popupMenuActive + inc , 1 , # popupMenu )
166163end
167164
168165local function requestPage ()
@@ -251,13 +248,13 @@ local function drawPopupMenu()
251248 local w = radio .MenuBox .w
252249 local h_line = radio .MenuBox .h_line
253250 local h_offset = radio .MenuBox .h_offset
254- local h = # popupMenuList * h_line + h_offset * 2
251+ local h = # popupMenu * h_line + h_offset * 2
255252
256253 lcd .drawFilledRectangle (x ,y ,w ,h ,backgroundFill )
257254 lcd .drawRectangle (x ,y ,w - 1 ,h - 1 ,foregroundColor )
258255 lcd .drawText (x + h_line / 2 ,y + h_offset ," Menu:" ,globalTextOptions )
259256
260- for i ,e in ipairs (popupMenuList ) do
257+ for i ,e in ipairs (popupMenu ) do
261258 local textOptions = globalTextOptions
262259 if popupMenuActive == i then
263260 textOptions = textOptions + INVERS
@@ -267,18 +264,35 @@ local function drawPopupMenu()
267264end
268265
269266local function run_ui (event )
270- if uiState == uiStatus .init then
267+ if popupMenu then
268+ drawPopupMenu ()
269+ if event == EVT_VIRTUAL_EXIT then
270+ popupMenu = nil
271+ elseif event == EVT_VIRTUAL_PREV then
272+ incPopupMenu (- 1 )
273+ elseif event == EVT_VIRTUAL_NEXT then
274+ incPopupMenu (1 )
275+ elseif event == EVT_VIRTUAL_ENTER then
276+ if killEnterBreak == 1 then
277+ killEnterBreak = 0
278+ else
279+ popupMenu [popupMenuActive ].f ()
280+ popupMenu = nil
281+ end
282+ end
283+ elseif uiState == uiStatus .init then
271284 lcd .clear ()
272285 drawScreenTitle (" Betaflight Config" )
273286 init = init or assert (loadScript (" ui_init.lua" ))()
274- if not init () then
287+ lcd .drawText (6 , radio .yMinLimit , init .t )
288+ if not init .f () then
275289 return 0
276290 end
277291 init = nil
278- createPopupMenu ()
279292 PageFiles = assert (loadScript (" pages.lua" ))()
280293 invalidatePages ()
281- uiState = uiStatus .mainMenu
294+ uiState = prevUiState or uiStatus .mainMenu
295+ prevUiState = nil
282296 elseif uiState == uiStatus .mainMenu then
283297 if event == EVT_VIRTUAL_EXIT then
284298 return 2
@@ -288,6 +302,9 @@ local function run_ui(event)
288302 incMainMenu (- 1 )
289303 elseif event == EVT_VIRTUAL_ENTER then
290304 uiState = uiStatus .pages
305+ elseif event == EVT_VIRTUAL_ENTER_LONG then
306+ killEnterBreak = 1
307+ createPopupMenu ()
291308 end
292309 lcd .clear ()
293310 local yMinLim = radio .yMinLimit
@@ -322,21 +339,6 @@ local function run_ui(event)
322339 invalidatePages ()
323340 end
324341 end
325- elseif pageState == pageStatus .popupMenu then
326- if event == EVT_VIRTUAL_EXIT then
327- pageState = pageStatus .display
328- elseif event == EVT_VIRTUAL_PREV then
329- incPopupMenu (- 1 )
330- elseif event == EVT_VIRTUAL_NEXT then
331- incPopupMenu (1 )
332- elseif event == EVT_VIRTUAL_ENTER then
333- if killEnterBreak == 1 then
334- killEnterBreak = 0
335- else
336- pageState = pageStatus .display
337- return popupMenuList [popupMenuActive ].f () or 0
338- end
339- end
340342 elseif pageState == pageStatus .display then
341343 if event == EVT_VIRTUAL_PREV_PAGE then
342344 incPage (- 1 )
@@ -350,17 +352,13 @@ local function run_ui(event)
350352 elseif event == EVT_VIRTUAL_ENTER then
351353 if Page then
352354 local f = Page .fields [currentField ]
353- if f .onClick then
354- f .onClick (Page )
355- end
356355 if Page .values and f .vals and Page .values [f .vals [# f .vals ]] and not f .ro then
357356 pageState = pageStatus .editing
358357 end
359358 end
360359 elseif event == EVT_VIRTUAL_ENTER_LONG then
361- popupMenuActive = 1
362360 killEnterBreak = 1
363- pageState = pageStatus . popupMenu
361+ createPopupMenu ()
364362 elseif event == EVT_VIRTUAL_EXIT then
365363 invalidatePages ()
366364 currentField = 1
@@ -380,17 +378,15 @@ local function run_ui(event)
380378 end
381379 end
382380 if not Page then
383- Page = assert (loadScript (" Pages /" .. PageFiles [currentPage ].script ))()
381+ Page = assert (loadScript (" PAGES /" .. PageFiles [currentPage ].script ))()
384382 collectgarbage ()
385383 end
386384 if not Page .values and pageState == pageStatus .display then
387385 requestPage ()
388386 end
389387 lcd .clear ()
390388 drawScreen ()
391- if pageState == pageStatus .popupMenu then
392- drawPopupMenu ()
393- elseif pageState == pageStatus .saving then
389+ if pageState == pageStatus .saving then
394390 local saveMsg = " Saving..."
395391 if saveRetries > 0 then
396392 saveMsg = " Retrying"
@@ -399,6 +395,18 @@ local function run_ui(event)
399395 lcd .drawRectangle (radio .SaveBox .x ,radio .SaveBox .y ,radio .SaveBox .w ,radio .SaveBox .h ,SOLID )
400396 lcd .drawText (radio .SaveBox .x + radio .SaveBox .x_offset ,radio .SaveBox .y + radio .SaveBox .h_offset ,saveMsg ,DBLSIZE + globalTextOptions )
401397 end
398+ elseif uiState == uiStatus .confirm then
399+ lcd .clear ()
400+ drawScreen ()
401+ if event == EVT_VIRTUAL_ENTER then
402+ uiState = uiStatus .init
403+ init = Page .init
404+ invalidatePages ()
405+ elseif event == EVT_VIRTUAL_EXIT then
406+ invalidatePages ()
407+ uiState = prevUiState
408+ prevUiState = nil
409+ end
402410 end
403411 if protocol .rssi () == 0 then
404412 lcd .drawText (radio .NoTelem [1 ],radio .NoTelem [2 ],radio .NoTelem [3 ],radio .NoTelem [4 ])
0 commit comments