Skip to content

Commit 6fe5a84

Browse files
committed
External script can return init-function, add trigger home event, cleanup
1 parent 5c66bc9 commit 6fe5a84

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/SCRIPTS/BF/ui.lua

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ local actionsIndex = {
4343
}
4444

4545
function setState(name)
46-
if pageStatus[name] ~= nil then
46+
if pageStatus[name] then
4747
if name == "displayMenu" then
4848
-- open menu
4949
menuActive = 1
@@ -63,7 +63,6 @@ function setLock(x) lockedInp = x end
6363

6464
function isInpLocked(x)
6565
if lockedInp == x then
66-
print("logging: input was locked and is released!! ", x)
6766
lockedInp = 0
6867
return 1
6968
end
@@ -182,7 +181,7 @@ function stepPage(inc)
182181
end
183182

184183
function gotoPage(x)
185-
if PageFiles[x] ~= nil then
184+
if PageFiles[x] then
186185
currentPage = x
187186
Page = nil
188187
currentLine = 1
@@ -228,7 +227,7 @@ local function drawScreen()
228227
local screen_title = Page.title
229228
local val = "---"
230229

231-
if Page.fields[currentLine] ~= nil then
230+
if Page.fields[currentLine] then
232231
local currentLineY = Page.fields[currentLine].y
233232
if currentLineY <= Page.fields[1].y then
234233
scrollPixelsY = 0
@@ -361,9 +360,9 @@ function run_ui(event)
361360
if currentState == pageStatus[st] then
362361
for t, action in pairs(actionsIndex[i]) do
363362
local actionTbl = ctrlSchema[st][action]
364-
if actionTbl.cond ~= nil then
363+
if actionTbl.cond then
365364
if actionTbl.cond(event, userEvent) then
366-
if actionTbl.func ~= nil and not isInpLocked(st.."."..action) then
365+
if actionTbl.func and not isInpLocked(st.."."..action) then
367366
actionTbl.func(event, userEvent)
368367
end
369368
break
@@ -418,17 +417,25 @@ function pre_ui(event)
418417
Page = assert(loadScript(radio.templateHome .. PageFiles[currentPage]))()
419418
end
420419

421-
if Page.run ~= nil and type(Page.run) == "function" then
420+
if not Page.didInit and Page.init then
421+
Page.init()
422+
Page.didInit = 1
423+
end
424+
425+
if Page.run then
422426
if ctrlSchema.display.prevPage.cond(event, userEvent) or
423-
ctrlSchema.display.nextPage.cond(event, userEvent) then
427+
ctrlSchema.display.nextPage.cond(event, userEvent) or
428+
ctrlSchema.display.home.cond(event, userEvent) then
424429
return run_ui(event)
425430
end
426431

427432
-- reset locked state from home action
428433
isInpLocked("display.menu")
429434

430435
lcd.clear()
431-
return assert(Page.run)(event)
436+
collectgarbage()
437+
438+
return Page.run(event)
432439
else
433440
return run_ui(event)
434441
end

0 commit comments

Comments
 (0)