@@ -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,26 +313,26 @@ function run_ui(event)
301
313
mspProcessTxQ ()
302
314
-- navigation
303
315
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
306
318
elseif (not isTelemetryScript ) and event == EVT_VIRTUAL_ENTER_LONG then -- standalone
307
- menuActive = 1
319
+ popupMenuActive = 1
308
320
killEnterBreak = 1
309
- currentState = pageStatus .displayMenu
321
+ currentState = pageStatus .popupMenu
310
322
-- menu is currently displayed
311
- elseif currentState == pageStatus .displayMenu then
323
+ elseif currentState == pageStatus .popupMenu then
312
324
if event == EVT_VIRTUAL_EXIT then
313
325
currentState = pageStatus .display
314
326
elseif event == EVT_VIRTUAL_PREV then
315
- incMenu (- 1 )
327
+ incPopupMenu (- 1 )
316
328
elseif event == EVT_VIRTUAL_NEXT then
317
- incMenu (1 )
329
+ incPopupMenu (1 )
318
330
elseif event == EVT_VIRTUAL_ENTER then
319
331
if killEnterBreak == 1 then
320
332
killEnterBreak = 0
321
333
else
322
334
currentState = pageStatus .display
323
- menuList [ menuActive ].f ()
335
+ popupMenuList [ popupMenuActive ].f ()
324
336
end
325
337
end
326
338
-- normal page viewing
@@ -341,7 +353,11 @@ function run_ui(event)
341
353
currentState = pageStatus .editing
342
354
end
343
355
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
345
361
end
346
362
-- editing value
347
363
elseif currentState == pageStatus .editing then
@@ -356,7 +372,7 @@ function run_ui(event)
356
372
end
357
373
local nextPage = currentPage
358
374
while Page == nil do
359
- Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]))()
375
+ Page = assert (loadScript (radio .templateHome .. PageFiles [currentPage ]. script ))()
360
376
if Page .requiredVersion and apiVersion > 0 and Page .requiredVersion > apiVersion then
361
377
incPage (1 )
362
378
@@ -379,8 +395,8 @@ function run_ui(event)
379
395
if protocol .rssi () == 0 then
380
396
lcd .drawText (NoTelem [1 ],NoTelem [2 ],NoTelem [3 ],NoTelem [4 ])
381
397
end
382
- if currentState == pageStatus .displayMenu then
383
- drawMenu ()
398
+ if currentState == pageStatus .popupMenu then
399
+ drawPopupMenu ()
384
400
elseif currentState == pageStatus .saving then
385
401
lcd .drawFilledRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,backgroundFill )
386
402
lcd .drawRectangle (SaveBox .x ,SaveBox .y ,SaveBox .w ,SaveBox .h ,SOLID )
@@ -390,6 +406,42 @@ function run_ui(event)
390
406
lcd .drawText (SaveBox .x + SaveBox .x_offset ,SaveBox .y + SaveBox .h_offset ," Retrying" ,DBLSIZE + (globalTextOptions ))
391
407
end
392
408
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
393
445
processMspReply (mspPollReply ())
394
446
return 0
395
447
end
0 commit comments