@@ -3,7 +3,8 @@ local pageStatus =
3
3
display = 2 ,
4
4
editing = 3 ,
5
5
saving = 4 ,
6
- displayMenu = 5 ,
6
+ popupMenu = 5 ,
7
+ mainMenu = 6 ,
7
8
}
8
9
9
10
local uiMsp =
@@ -12,7 +13,8 @@ local uiMsp =
12
13
eepromWrite = 250
13
14
}
14
15
15
- local currentState = pageStatus .display
16
+ local menuLine = 1
17
+ local currentState = pageStatus .mainMenu
16
18
local requestTimeout = 80 -- 800ms request timeout
17
19
local currentPage = 1
18
20
local currentLine = 1
@@ -22,9 +24,10 @@ local saveRetries = 0
22
24
local saveMaxRetries = 0
23
25
local pageRequested = false
24
26
local telemetryScreenActive = false
25
- local menuActive = false
27
+ local popupMenuActive = false
26
28
local lastRunTS = 0
27
29
local killEnterBreak = 0
30
+ local stopDisplay = true
28
31
local scrollPixelsY = 0
29
32
30
33
local Page = nil
@@ -72,7 +75,7 @@ local function eepromWrite()
72
75
protocol .mspRead (uiMsp .eepromWrite )
73
76
end
74
77
75
- local menuList = {
78
+ local popupMenuList = {
76
79
{
77
80
t = " save page" ,
78
81
f = saveSettings
@@ -151,8 +154,12 @@ local function incLine(inc)
151
154
currentLine = clipValue (currentLine + inc , 1 , # (Page .fields ))
152
155
end
153
156
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 ))
156
163
end
157
164
158
165
local function requestPage ()
@@ -258,21 +265,21 @@ local function incValue(inc)
258
265
end
259
266
end
260
267
261
- local function drawMenu ()
268
+ local function drawPopupMenu ()
262
269
local x = MenuBox .x
263
270
local y = MenuBox .y
264
271
local w = MenuBox .w
265
272
local h_line = MenuBox .h_line
266
273
local h_offset = MenuBox .h_offset
267
- local h = # (menuList ) * h_line + h_offset * 2
274
+ local h = # (popupMenuList ) * h_line + h_offset * 2
268
275
269
276
lcd .drawFilledRectangle (x ,y ,w ,h ,backgroundFill )
270
277
lcd .drawRectangle (x ,y ,w - 1 ,h - 1 ,foregroundColor )
271
278
lcd .drawText (x + h_line / 2 ,y + h_offset ," Menu:" ,globalTextOptions )
272
279
273
- for i ,e in ipairs (menuList ) do
280
+ for i ,e in ipairs (popupMenuList ) do
274
281
local text_options = globalTextOptions
275
- if menuActive == i then
282
+ if popupMenuActive == i then
276
283
text_options = text_options + INVERS
277
284
end
278
285
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)
284
291
-- if lastRunTS old than 500ms
285
292
if lastRunTS + 50 < now then
286
293
invalidatePages ()
294
+ if useMenu then
295
+ currentState = pageStatus .mainMenu
296
+ else
297
+ currentState = pageStatus .display
298
+ end
287
299
end
288
300
lastRunTS = now
289
301
if (currentState == pageStatus .saving ) then
@@ -301,24 +313,24 @@ function run_ui(event)
301
313
mspProcessTxQ ()
302
314
-- navigation
303
315
if (event == EVT_VIRTUAL_ENTER_LONG ) then
304
- menuActive = 1
316
+ popupMenuActive = 1
305
317
killEnterBreak = 1
306
- currentState = pageStatus .displayMenu
318
+ currentState = pageStatus .popupMenu
307
319
killEvents (event )
308
320
-- menu is currently displayed
309
- elseif currentState == pageStatus .displayMenu then
321
+ elseif currentState == pageStatus .popupMenu then
310
322
if event == EVT_VIRTUAL_EXIT then
311
323
currentState = pageStatus .display
312
324
elseif event == EVT_VIRTUAL_PREV then
313
- incMenu (- 1 )
325
+ incPopupMenu (- 1 )
314
326
elseif event == EVT_VIRTUAL_NEXT then
315
- incMenu (1 )
327
+ incPopupMenu (1 )
316
328
elseif event == EVT_VIRTUAL_ENTER then
317
329
if killEnterBreak == 1 then
318
330
killEnterBreak = 0
319
331
else
320
332
currentState = pageStatus .display
321
- menuList [ menuActive ].f ()
333
+ popupMenuList [ popupMenuActive ].f ()
322
334
end
323
335
end
324
336
-- normal page viewing
@@ -339,7 +351,11 @@ function run_ui(event)
339
351
currentState = pageStatus .editing
340
352
end
341
353
elseif event == EVT_VIRTUAL_EXIT then
342
- return protocol .exitFunc ();
354
+ if useMenu then
355
+ stopDisplay = true
356
+ else
357
+ return protocol .exitFunc ();
358
+ end
343
359
end
344
360
-- editing value
345
361
elseif currentState == pageStatus .editing then
@@ -353,7 +369,7 @@ function run_ui(event)
353
369
end
354
370
local nextPage = currentPage
355
371
while Page == nil do
356
- Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]))()
372
+ Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]. script ))()
357
373
if Page .requiredVersion and apiVersion > 0 and Page .requiredVersion > apiVersion then
358
374
incPage (1 )
359
375
@@ -376,8 +392,8 @@ function run_ui(event)
376
392
if protocol .rssi () == 0 then
377
393
lcd .drawText (NoTelem [1 ],NoTelem [2 ],NoTelem [3 ],NoTelem [4 ])
378
394
end
379
- if currentState == pageStatus .displayMenu then
380
- drawMenu ()
395
+ if currentState == pageStatus .popupMenu then
396
+ drawPopupMenu ()
381
397
elseif currentState == pageStatus .saving then
382
398
lcd .drawFilledRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,backgroundFill )
383
399
lcd .drawRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,SOLID )
@@ -387,6 +403,42 @@ function run_ui(event)
387
403
lcd .drawText (SaveBox .x + SaveBox .x_offset ,SaveBox .y + SaveBox .h_offset ," Retrying" ,DBLSIZE + (globalTextOptions ))
388
404
end
389
405
end
406
+ if currentState == pageStatus .mainMenu and useMenu then
407
+ if event == EVT_VIRTUAL_EXIT then
408
+ return 2
409
+ elseif event == EVT_VIRTUAL_NEXT then
410
+ incMainMenu (1 )
411
+ elseif event == EVT_VIRTUAL_PREV then
412
+ incMainMenu (- 1 )
413
+ end
414
+ lcd .clear ()
415
+ lcd .drawScreenTitle (" Betaflight Config" , 0 , 0 )
416
+ for i = 1 , # PageFiles do
417
+ local yMinLim = 10
418
+ local yMaxLim = LCD_H - 8
419
+ local currentLineY = (menuLine - 1 )* 8 + yMinLim
420
+ if currentLineY <= yMaxLim then
421
+ scrollPixelsY = 0
422
+ elseif currentLineY - scrollPixelsY <= yMinLim then
423
+ scrollPixelsY = currentLineY - yMinLim * 2
424
+ elseif currentLineY - scrollPixelsY >= yMaxLim then
425
+ scrollPixelsY = currentLineY - yMaxLim + 6
426
+ end
427
+ local attr = (menuLine == i and INVERS or 0 )
428
+ if event == EVT_VIRTUAL_ENTER and attr == INVERS then
429
+ Page = assert (loadScript (radio .templateHome .. PageFiles [i ].script ))()
430
+ currentPage = i
431
+ currentState = pageStatus .display
432
+ end
433
+ if ((i - 1 )* 8 + yMinLim - scrollPixelsY ) >= yMinLim and ((i - 1 )* 8 + yMinLim - scrollPixelsY ) <= yMaxLim then
434
+ lcd .drawText (6 , (i - 1 )* 8 + yMinLim - scrollPixelsY , PageFiles [i ].title , attr )
435
+ end
436
+ end
437
+ end
438
+ if stopDisplay then
439
+ currentState = pageStatus .mainMenu
440
+ stopDisplay = false
441
+ end
390
442
processMspReply (mspPollReply ())
391
443
return 0
392
444
end
0 commit comments