@@ -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
@@ -356,7 +372,7 @@ function run_ui(event)
356372 end
357373 local nextPage = currentPage
358374 while Page == nil do
359- Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]))()
375+ Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]. script ))()
360376 if Page .requiredVersion and apiVersion > 0 and Page .requiredVersion > apiVersion then
361377 incPage (1 )
362378
@@ -379,8 +395,8 @@ function run_ui(event)
379395 if protocol .rssi () == 0 then
380396 lcd .drawText (NoTelem [1 ],NoTelem [2 ],NoTelem [3 ],NoTelem [4 ])
381397 end
382- if currentState == pageStatus .displayMenu then
383- drawMenu ()
398+ if currentState == pageStatus .popupMenu then
399+ drawPopupMenu ()
384400 elseif currentState == pageStatus .saving then
385401 lcd .drawFilledRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,backgroundFill )
386402 lcd .drawRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,SOLID )
@@ -390,6 +406,42 @@ function run_ui(event)
390406 lcd .drawText (SaveBox .x + SaveBox .x_offset ,SaveBox .y + SaveBox .h_offset ," Retrying" ,DBLSIZE + (globalTextOptions ))
391407 end
392408 end
409+ if currentState == pageStatus .mainMenu and useMenu then
410+ if event == EVT_VIRTUAL_EXIT then
411+ return 2
412+ elseif event == EVT_VIRTUAL_NEXT then
413+ incMainMenu (1 )
414+ elseif event == EVT_VIRTUAL_PREV then
415+ incMainMenu (- 1 )
416+ end
417+ lcd .clear ()
418+ lcd .drawScreenTitle (" Betaflight Config" , 0 , 0 )
419+ for i = 1 , # PageFiles do
420+ local yMinLim = 10
421+ local yMaxLim = LCD_H - 8
422+ local currentLineY = (menuLine - 1 )* 8 + yMinLim
423+ if currentLineY <= yMaxLim then
424+ scrollPixelsY = 0
425+ elseif currentLineY - scrollPixelsY <= yMinLim then
426+ scrollPixelsY = currentLineY - yMinLim * 2
427+ elseif currentLineY - scrollPixelsY >= yMaxLim then
428+ scrollPixelsY = currentLineY - yMaxLim + 6
429+ end
430+ local attr = (menuLine == i and INVERS or 0 )
431+ if event == EVT_VIRTUAL_ENTER and attr == INVERS then
432+ Page = assert (loadScript (radio .templateHome .. PageFiles [i ].script ))()
433+ currentPage = i
434+ currentState = pageStatus .display
435+ end
436+ if ((i - 1 )* 8 + yMinLim - scrollPixelsY ) >= yMinLim and ((i - 1 )* 8 + yMinLim - scrollPixelsY ) <= yMaxLim then
437+ lcd .drawText (6 , (i - 1 )* 8 + yMinLim - scrollPixelsY , PageFiles [i ].title , attr )
438+ end
439+ end
440+ end
441+ if stopDisplay then
442+ currentState = pageStatus .mainMenu
443+ stopDisplay = false
444+ end
393445 processMspReply (mspPollReply ())
394446 return 0
395447end
0 commit comments