1
1
local uiStatus =
2
2
{
3
3
init = 1 ,
4
- pages = 2 ,
5
- mainMenu = 3 ,
4
+ mainMenu = 2 ,
5
+ pages = 3 ,
6
+ confirm = 4 ,
6
7
}
7
8
8
9
local pageStatus =
9
10
{
10
- display = 2 ,
11
- editing = 3 ,
12
- saving = 4 ,
13
- popupMenu = 5 ,
11
+ display = 1 ,
12
+ editing = 2 ,
13
+ saving = 3 ,
14
14
}
15
15
16
16
local uiMsp =
@@ -20,6 +20,7 @@ local uiMsp =
20
20
}
21
21
22
22
local uiState = uiStatus .init
23
+ local prevUiState
23
24
local pageState = pageStatus .display
24
25
local requestTimeout = 80
25
26
local currentPage = 1
@@ -32,7 +33,7 @@ local popupMenuActive = 1
32
33
local killEnterBreak = 0
33
34
local pageScrollY = 0
34
35
local mainMenuScrollY = 0
35
- local PageFiles , Page , init , popupMenuList
36
+ local PageFiles , Page , init , popupMenu
36
37
37
38
local backgroundFill = TEXT_BGCOLOR or ERASE
38
39
local foregroundColor = LINE_COLOR or SOLID
@@ -72,30 +73,26 @@ local function eepromWrite()
72
73
protocol .mspRead (uiMsp .eepromWrite )
73
74
end
74
75
75
- local function accCal ()
76
+ local function confirm (page )
77
+ prevUiState = uiState
78
+ uiState = uiStatus .confirm
76
79
invalidatePages ()
77
80
currentField = 1
78
- Page = assert (loadScript (" Pages/accelerometer.lua " ))()
81
+ Page = assert (loadScript (page ))()
79
82
collectgarbage ()
80
83
end
81
84
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
-
90
85
local 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 }
97
94
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 }
99
96
end
100
97
end
101
98
@@ -162,7 +159,7 @@ local function incMainMenu(inc)
162
159
end
163
160
164
161
local function incPopupMenu (inc )
165
- popupMenuActive = clipValue (popupMenuActive + inc , 1 , # popupMenuList )
162
+ popupMenuActive = clipValue (popupMenuActive + inc , 1 , # popupMenu )
166
163
end
167
164
168
165
local function requestPage ()
@@ -251,13 +248,13 @@ local function drawPopupMenu()
251
248
local w = radio .MenuBox .w
252
249
local h_line = radio .MenuBox .h_line
253
250
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
255
252
256
253
lcd .drawFilledRectangle (x ,y ,w ,h ,backgroundFill )
257
254
lcd .drawRectangle (x ,y ,w - 1 ,h - 1 ,foregroundColor )
258
255
lcd .drawText (x + h_line / 2 ,y + h_offset ," Menu:" ,globalTextOptions )
259
256
260
- for i ,e in ipairs (popupMenuList ) do
257
+ for i ,e in ipairs (popupMenu ) do
261
258
local textOptions = globalTextOptions
262
259
if popupMenuActive == i then
263
260
textOptions = textOptions + INVERS
@@ -267,18 +264,35 @@ local function drawPopupMenu()
267
264
end
268
265
269
266
local 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
271
284
lcd .clear ()
272
285
drawScreenTitle (" Betaflight Config" )
273
286
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
275
289
return 0
276
290
end
277
291
init = nil
278
- createPopupMenu ()
279
292
PageFiles = assert (loadScript (" pages.lua" ))()
280
293
invalidatePages ()
281
- uiState = uiStatus .mainMenu
294
+ uiState = prevUiState or uiStatus .mainMenu
295
+ prevUiState = nil
282
296
elseif uiState == uiStatus .mainMenu then
283
297
if event == EVT_VIRTUAL_EXIT then
284
298
return 2
@@ -288,6 +302,9 @@ local function run_ui(event)
288
302
incMainMenu (- 1 )
289
303
elseif event == EVT_VIRTUAL_ENTER then
290
304
uiState = uiStatus .pages
305
+ elseif event == EVT_VIRTUAL_ENTER_LONG then
306
+ killEnterBreak = 1
307
+ createPopupMenu ()
291
308
end
292
309
lcd .clear ()
293
310
local yMinLim = radio .yMinLimit
@@ -322,21 +339,6 @@ local function run_ui(event)
322
339
invalidatePages ()
323
340
end
324
341
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
340
342
elseif pageState == pageStatus .display then
341
343
if event == EVT_VIRTUAL_PREV_PAGE then
342
344
incPage (- 1 )
@@ -350,17 +352,13 @@ local function run_ui(event)
350
352
elseif event == EVT_VIRTUAL_ENTER then
351
353
if Page then
352
354
local f = Page .fields [currentField ]
353
- if f .onClick then
354
- f .onClick (Page )
355
- end
356
355
if Page .values and f .vals and Page .values [f .vals [# f .vals ]] and not f .ro then
357
356
pageState = pageStatus .editing
358
357
end
359
358
end
360
359
elseif event == EVT_VIRTUAL_ENTER_LONG then
361
- popupMenuActive = 1
362
360
killEnterBreak = 1
363
- pageState = pageStatus . popupMenu
361
+ createPopupMenu ()
364
362
elseif event == EVT_VIRTUAL_EXIT then
365
363
invalidatePages ()
366
364
currentField = 1
@@ -380,17 +378,15 @@ local function run_ui(event)
380
378
end
381
379
end
382
380
if not Page then
383
- Page = assert (loadScript (" Pages /" .. PageFiles [currentPage ].script ))()
381
+ Page = assert (loadScript (" PAGES /" .. PageFiles [currentPage ].script ))()
384
382
collectgarbage ()
385
383
end
386
384
if not Page .values and pageState == pageStatus .display then
387
385
requestPage ()
388
386
end
389
387
lcd .clear ()
390
388
drawScreen ()
391
- if pageState == pageStatus .popupMenu then
392
- drawPopupMenu ()
393
- elseif pageState == pageStatus .saving then
389
+ if pageState == pageStatus .saving then
394
390
local saveMsg = " Saving..."
395
391
if saveRetries > 0 then
396
392
saveMsg = " Retrying"
@@ -399,6 +395,18 @@ local function run_ui(event)
399
395
lcd .drawRectangle (radio .SaveBox .x ,radio .SaveBox .y ,radio .SaveBox .w ,radio .SaveBox .h ,SOLID )
400
396
lcd .drawText (radio .SaveBox .x + radio .SaveBox .x_offset ,radio .SaveBox .y + radio .SaveBox .h_offset ,saveMsg ,DBLSIZE + globalTextOptions )
401
397
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
402
410
end
403
411
if protocol .rssi () == 0 then
404
412
lcd .drawText (radio .NoTelem [1 ],radio .NoTelem [2 ],radio .NoTelem [3 ],radio .NoTelem [4 ])
0 commit comments