@@ -3,7 +3,8 @@ local pageStatus =
33 display = 2 ,
44 editing = 3 ,
55 saving = 4 ,
6- displayMenu = 5 ,
6+ popupMenu = 5 ,
7+ mainMenu = 6 ,
78}
89
910local uiMsp =
@@ -12,7 +13,8 @@ local uiMsp =
1213 eepromWrite = 250
1314}
1415
15- local currentState = pageStatus .display
16+ local menuLine = 1
17+ local currentState = pageStatus .mainMenu
1618local requestTimeout = 80 -- 800ms request timeout
1719local currentPage = 1
1820local currentLine = 1
@@ -22,9 +24,10 @@ local saveRetries = 0
2224local saveMaxRetries = 0
2325local pageRequested = false
2426local telemetryScreenActive = false
25- local menuActive = false
27+ local popupMenuActive = false
2628local lastRunTS = 0
2729local killEnterBreak = 0
30+ local stopDisplay = true
2831local scrollPixelsY = 0
2932
3033local Page = nil
@@ -72,7 +75,7 @@ local function eepromWrite()
7275 protocol .mspRead (uiMsp .eepromWrite )
7376end
7477
75- local menuList = {
78+ local popupMenuList = {
7679 {
7780 t = " save page" ,
7881 f = saveSettings
@@ -151,8 +154,12 @@ local function incLine(inc)
151154 currentLine = clipValue (currentLine + inc , 1 , # (Page .fields ))
152155end
153156
154- local function incMenu (inc )
155- menuActive = clipValue (menuActive + inc , 1 , # (menuList ))
157+ local function incMainMenu (inc )
158+ menuLine = clipValue (menuLine + inc , 1 , # (PageFiles ))
159+ end
160+
161+ local function incPopupMenu (inc )
162+ popupMenuActive = clipValue (popupMenuActive + inc , 1 , # (popupMenuList ))
156163end
157164
158165local function requestPage ()
@@ -258,21 +265,21 @@ local function incValue(inc)
258265 end
259266end
260267
261- local function drawMenu ()
268+ local function drawPopupMenu ()
262269 local x = MenuBox .x
263270 local y = MenuBox .y
264271 local w = MenuBox .w
265272 local h_line = MenuBox .h_line
266273 local h_offset = MenuBox .h_offset
267- local h = # (menuList ) * h_line + h_offset * 2
274+ local h = # (popupMenuList ) * h_line + h_offset * 2
268275
269276 lcd .drawFilledRectangle (x ,y ,w ,h ,backgroundFill )
270277 lcd .drawRectangle (x ,y ,w - 1 ,h - 1 ,foregroundColor )
271278 lcd .drawText (x + h_line / 2 ,y + h_offset ," Menu:" ,globalTextOptions )
272279
273- for i ,e in ipairs (menuList ) do
280+ for i ,e in ipairs (popupMenuList ) do
274281 local text_options = globalTextOptions
275- if menuActive == i then
282+ if popupMenuActive == i then
276283 text_options = text_options + INVERS
277284 end
278285 lcd .drawText (x + MenuBox .x_offset ,y + (i - 1 )* h_line + h_offset ,e .t ,text_options )
@@ -284,6 +291,11 @@ function run_ui(event)
284291 -- if lastRunTS old than 500ms
285292 if lastRunTS + 50 < now then
286293 invalidatePages ()
294+ if useMenu then
295+ currentState = pageStatus .mainMenu
296+ else
297+ currentState = pageStatus .display
298+ end
287299 end
288300 lastRunTS = now
289301 if (currentState == pageStatus .saving ) then
@@ -301,26 +313,26 @@ function run_ui(event)
301313 mspProcessTxQ ()
302314 -- navigation
303315 if isTelemetryScript and event == EVT_VIRTUAL_MENU_LONG then -- telemetry script
304- menuActive = 1
305- currentState = pageStatus .displayMenu
316+ popupMenuActive = 1
317+ currentState = pageStatus .popupMenu
306318 elseif (not isTelemetryScript ) and event == EVT_VIRTUAL_ENTER_LONG then -- standalone
307- menuActive = 1
319+ popupMenuActive = 1
308320 killEnterBreak = 1
309- currentState = pageStatus .displayMenu
321+ currentState = pageStatus .popupMenu
310322 -- menu is currently displayed
311- elseif currentState == pageStatus .displayMenu then
323+ elseif currentState == pageStatus .popupMenu then
312324 if event == EVT_VIRTUAL_EXIT then
313325 currentState = pageStatus .display
314326 elseif event == EVT_VIRTUAL_PREV then
315- incMenu (- 1 )
327+ incPopupMenu (- 1 )
316328 elseif event == EVT_VIRTUAL_NEXT then
317- incMenu (1 )
329+ incPopupMenu (1 )
318330 elseif event == EVT_VIRTUAL_ENTER then
319331 if killEnterBreak == 1 then
320332 killEnterBreak = 0
321333 else
322334 currentState = pageStatus .display
323- menuList [ menuActive ].f ()
335+ popupMenuList [ popupMenuActive ].f ()
324336 end
325337 end
326338 -- normal page viewing
@@ -341,7 +353,11 @@ function run_ui(event)
341353 currentState = pageStatus .editing
342354 end
343355 elseif event == EVT_VIRTUAL_EXIT then
344- return protocol .exitFunc ();
356+ if useMenu then
357+ stopDisplay = true
358+ else
359+ return protocol .exitFunc ();
360+ end
345361 end
346362 -- editing value
347363 elseif currentState == pageStatus .editing then
@@ -355,7 +371,7 @@ function run_ui(event)
355371 end
356372 local nextPage = currentPage
357373 while Page == nil do
358- Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]))()
374+ Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]. script ))()
359375 if Page .requiredVersion and apiVersion > 0 and Page .requiredVersion > apiVersion then
360376 incPage (1 )
361377
@@ -378,8 +394,8 @@ function run_ui(event)
378394 if protocol .rssi () == 0 then
379395 lcd .drawText (NoTelem [1 ],NoTelem [2 ],NoTelem [3 ],NoTelem [4 ])
380396 end
381- if currentState == pageStatus .displayMenu then
382- drawMenu ()
397+ if currentState == pageStatus .popupMenu then
398+ drawPopupMenu ()
383399 elseif currentState == pageStatus .saving then
384400 lcd .drawFilledRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,backgroundFill )
385401 lcd .drawRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,SOLID )
@@ -389,6 +405,42 @@ function run_ui(event)
389405 lcd .drawText (SaveBox .x + SaveBox .x_offset ,SaveBox .y + SaveBox .h_offset ," Retrying" ,DBLSIZE + (globalTextOptions ))
390406 end
391407 end
408+ if currentState == pageStatus .mainMenu and useMenu then
409+ if event == EVT_VIRTUAL_EXIT then
410+ return 2
411+ elseif event == EVT_VIRTUAL_NEXT then
412+ incMainMenu (1 )
413+ elseif event == EVT_VIRTUAL_PREV then
414+ incMainMenu (- 1 )
415+ end
416+ lcd .clear ()
417+ lcd .drawScreenTitle (" Betaflight Config" , 0 , 0 )
418+ for i = 1 , # PageFiles do
419+ local yMinLim = 10
420+ local yMaxLim = LCD_H - 8
421+ local currentLineY = (menuLine - 1 )* 8 + yMinLim
422+ if currentLineY <= yMaxLim then
423+ scrollPixelsY = 0
424+ elseif currentLineY - scrollPixelsY <= yMinLim then
425+ scrollPixelsY = currentLineY - yMinLim * 2
426+ elseif currentLineY - scrollPixelsY >= yMaxLim then
427+ scrollPixelsY = currentLineY - yMaxLim + 6
428+ end
429+ local attr = (menuLine == i and INVERS or 0 )
430+ if event == EVT_VIRTUAL_ENTER and attr == INVERS then
431+ Page = assert (loadScript (radio .templateHome .. PageFiles [i ].script ))()
432+ currentPage = i
433+ currentState = pageStatus .display
434+ end
435+ if ((i - 1 )* 8 + yMinLim - scrollPixelsY ) >= yMinLim and ((i - 1 )* 8 + yMinLim - scrollPixelsY ) <= yMaxLim then
436+ lcd .drawText (6 , (i - 1 )* 8 + yMinLim - scrollPixelsY , PageFiles [i ].title , attr )
437+ end
438+ end
439+ end
440+ if stopDisplay then
441+ currentState = pageStatus .mainMenu
442+ stopDisplay = false
443+ end
392444 processMspReply (mspPollReply ())
393445 return 0
394446end
0 commit comments