@@ -45,13 +45,9 @@ local globalTextOptions = TEXT_COLOR or 0
4545
4646local function saveSettings (new )
4747 if Page .values then
48- local payload = {}
48+ local payload = Page . values
4949 if Page .preSave then
5050 payload = Page .preSave (Page )
51- else
52- for i = 1 ,(Page .outputBytes or # Page .values ) do
53- payload [i ] = Page .values [i ]
54- end
5551 end
5652 protocol .mspWrite (Page .write , payload )
5753 saveTS = getTime ()
@@ -123,11 +119,7 @@ local function processMspReply(cmd,rx_buf)
123119 return
124120 end
125121 if # (rx_buf ) > 0 then
126- Page .values = {}
127- for i = 1 ,# (rx_buf ) do
128- Page .values [i ] = rx_buf [i ]
129- end
130-
122+ Page .values = rx_buf
131123 for i = 1 ,# (Page .fields ) do
132124 if (# (Page .values ) or 0 ) >= Page .minBytes then
133125 local f = Page .fields [i ]
@@ -152,14 +144,23 @@ local function incMax(val, inc, base)
152144 return ((val + inc + base - 1 ) % base ) + 1
153145end
154146
147+ local function clipValue (val ,min ,max )
148+ if val < min then
149+ val = min
150+ elseif val > max then
151+ val = max
152+ end
153+ return val
154+ end
155+
155156local function incPage (inc )
156157 currentPage = incMax (currentPage , inc , # (PageFiles ))
157158 Page = nil
158159 currentField = 1
159160 collectgarbage ()
160161end
161162
162- local function incLine (inc )
163+ local function incField (inc )
163164 currentField = clipValue (currentField + inc , 1 , # (Page .fields ))
164165end
165166
@@ -178,7 +179,7 @@ local function requestPage()
178179 end
179180end
180181
181- function drawScreenTitle (screen_title )
182+ local function drawScreenTitle (screen_title )
182183 if radio .resolution == lcdResolution .low then
183184 lcd .drawFilledRectangle (0 , 0 , LCD_W , 10 )
184185 lcd .drawText (1 ,1 ,screen_title ,INVERS )
@@ -236,21 +237,12 @@ local function drawScreen()
236237 end
237238end
238239
239- function clipValue (val ,min ,max )
240- if val < min then
241- val = min
242- elseif val > max then
243- val = max
244- end
245- return val
246- end
247-
248240local function incValue (inc )
249241 local f = Page .fields [currentField ]
250242 local idx = f .i or currentField
251243 local scale = (f .scale or 1 )
252244 local mult = (f .mult or 1 )
253- f .value = clipValue (f .value + ((inc * mult )/ scale ), (f .min / scale ) or 0 , (f .max / scale ) or 255 )
245+ f .value = clipValue (f .value + ((inc * mult )/ scale ), (( f .min or 0 ) / scale ) , (( f .max or 255 ) / scale ) )
254246 f .value = math.floor ((f .value * scale )/ mult + 0.5 )/ (scale / mult )
255247 for idx = 1 , # (f .vals ) do
256248 Page .values [f .vals [idx ]] = bit32.rshift (math.floor (f .value * scale + 0.5 ), (idx - 1 )* 8 )
@@ -281,7 +273,7 @@ local function drawPopupMenu()
281273 end
282274end
283275
284- function run_ui (event )
276+ local function run_ui (event )
285277 local now = getTime ()
286278 -- if lastRunTS old than 500ms
287279 if lastRunTS + 50 < now then
@@ -297,10 +289,8 @@ function run_ui(event)
297289 if apiVersion == 0 then
298290 if not background then
299291 background = assert (loadScript (" /SCRIPTS/BF/background.lua" ))()
300- background .init ()
301- else
302- background .run_bg ()
303292 end
293+ background ()
304294 return 0
305295 else
306296 background = nil
@@ -319,6 +309,9 @@ function run_ui(event)
319309 incMainMenu (1 )
320310 elseif event == EVT_VIRTUAL_PREV then
321311 incMainMenu (- 1 )
312+ elseif event == EVT_VIRTUAL_ENTER then
313+ pageState = pageStatus .display
314+ uiState = uiStatus .pages
322315 end
323316 lcd .clear ()
324317 drawScreenTitle (" Betaflight Config" , 0 , 0 )
@@ -328,22 +321,16 @@ function run_ui(event)
328321 if radio .resolution == lcdResolution .high then
329322 lineSpacing = 25
330323 end
324+ local currentFieldY = (currentPage - 1 )* lineSpacing + yMinLim
325+ if currentFieldY <= yMinLim then
326+ mainMenuScrollY = 0
327+ elseif currentFieldY - mainMenuScrollY <= yMinLim then
328+ mainMenuScrollY = currentFieldY - yMinLim
329+ elseif currentFieldY - mainMenuScrollY >= yMaxLim then
330+ mainMenuScrollY = currentFieldY - yMaxLim
331+ end
331332 for i = 1 , # PageFiles do
332- local currentFieldY = (currentPage - 1 )* lineSpacing + yMinLim
333- if currentFieldY <= yMinLim then
334- mainMenuScrollY = 0
335- elseif currentFieldY - mainMenuScrollY <= yMinLim then
336- mainMenuScrollY = currentFieldY - yMinLim
337- elseif currentFieldY - mainMenuScrollY >= yMaxLim then
338- mainMenuScrollY = currentFieldY - yMaxLim
339- end
340333 local attr = (currentPage == i and INVERS or 0 )
341- if event == EVT_VIRTUAL_ENTER and attr == INVERS then
342- invalidatePages ()
343- currentPage = i
344- pageState = pageStatus .display
345- uiState = uiStatus .pages
346- end
347334 if ((i - 1 )* lineSpacing + yMinLim - mainMenuScrollY ) >= yMinLim and ((i - 1 )* lineSpacing + yMinLim - mainMenuScrollY ) <= yMaxLim then
348335 lcd .drawText (6 , (i - 1 )* lineSpacing + yMinLim - mainMenuScrollY , PageFiles [i ].title , attr )
349336 end
@@ -392,9 +379,9 @@ function run_ui(event)
392379 elseif (not isTelemetryScript and event == EVT_VIRTUAL_NEXT_PAGE ) or (isTelemetryScript and event == EVT_VIRTUAL_MENU ) then
393380 incPage (1 )
394381 elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_PREV_REPT then
395- incLine (- 1 )
382+ incField (- 1 )
396383 elseif event == EVT_VIRTUAL_NEXT or event == EVT_VIRTUAL_NEXT_REPT then
397- incLine (1 )
384+ incField (1 )
398385 elseif event == EVT_VIRTUAL_ENTER then
399386 if Page then
400387 local field = Page .fields [currentField ]
0 commit comments