Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/SCRIPTS/RF2/COMPILE/compile.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local i = 1
local scripts = assert(loadScript("COMPILE/scripts.lua"))
local scripts = assert(loadScript("/SCRIPTS/RF2/COMPILE/scripts.lua"))
collectgarbage()

local function deleteOrTruncateFile(filepath)
Expand Down Expand Up @@ -33,10 +33,10 @@ local function compile()
assert(loadScript(script, 'cd')) -- The 'd' flags gets removed in by minimize.lua
return 0
end
local file = io.open("COMPILE/scripts_compiled.lua", 'w')
local file = io.open("/SCRIPTS/RF2/COMPILE/scripts_compiled.lua", 'w')
io.write(file, "return true")
io.close(file)
assert(loadScript("COMPILE/scripts_compiled.lua", 'c'))
assert(loadScript("/SCRIPTS/RF2/COMPILE/scripts_compiled.lua", 'c'))
return 1
end

Expand Down
7 changes: 6 additions & 1 deletion src/SCRIPTS/RF2/LVGL/page.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ local function show(page)
{
type = "page",
title = "Rotorflight " .. rf2.luaVersion,
subtitle = page.title,
subtitle = function()
if rf2.widget and rf2.widget.options then
return page.title .. " - " .. rf2.widget.options:getText()
end
return page.title
end,
icon = rf2.baseDir .. "rf2.png",
back = function()
if page.back then
Expand Down
2 changes: 1 addition & 1 deletion src/SCRIPTS/RF2/MSP/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ end

local function mspPollReply()
local startTime = rf2.clock()
while (rf2.clock() - startTime < 0.05) do
while (rf2.clock() - startTime < 0.01) do
local mspData = mspPoll()
if mspData ~= nil and mspReceivedReply(mspData) then
mspLastReq = 0
Expand Down
32 changes: 25 additions & 7 deletions src/SCRIPTS/RF2/background.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ end

local hasSensor = rf2.executeScript("F/hasSensor")

local function run()
if rf2.runningInSimulator then
modelIsConnected = true
elseif isInitialized and customTelemetryTask and not hasSensor("*Cnt") then
local function setState(widget, state)
if widget == nil then return end
widget:setState(state)
end

--local lastHelloTime = nil
local function run(widget)
-- if lastHelloTime == nil or rf2.clock() - lastHelloTime > 1 then
-- rf2.print("Background says hello!")
-- lastHelloTime = rf2.clock()
-- end

if isInitialized and customTelemetryTask and not hasSensor("*Cnt") then
isInitialized = false -- user probably deleted all sensors on TX
elseif getRSSI() > 0 then
lastTimeRssi = rf2.clock()
Expand All @@ -27,10 +36,11 @@ local function run()
if lastTimeRssi and rf2.clock() - lastTimeRssi < 5 then
-- Do not re-initialise if the RSSI is 0 for less than 5 seconds.
-- This is also a work-around for https://github.com/ExpressLRS/ExpressLRS/issues/3207 (AUX channel bug in ELRS TX < 3.5.5)
-- setState(widget, "telemetry lost") -- also needs telemetry recoverede/connected
return
end
rf2.executeScript("F/pilotConfigReset")()
if modelIsConnected then
rf2.executeScript("F/pilotConfigReset")()
if initTask then
initTask.reset()
initTask = nil
Expand All @@ -51,6 +61,11 @@ local function run()
local initTaskResult = initTask.run(modelIsConnected)
if not initTaskResult.isInitialized then
--rf2.print("Not initialized yet")
if getRSSI() == 0 then
setState(widget, "disconnected")
else
setState(widget, "initializing")
end
return
end
if initTaskResult.crsfCustomTelemetryEnabled then
Expand All @@ -62,6 +77,7 @@ local function run()
end
initTask = nil
isInitialized = true
setState(widget, "connected")
end

if getRSSI() == 0 and not rf2.runningInSimulator then
Expand All @@ -78,8 +94,10 @@ local function run()
end
end

local function runProtected()
local status, err = pcall(run)
-- widget is optional and will be provided by the RfTool widget.
-- If the background script runs as a special function, widget will be nil.
local function runProtected(widget)
local status, err = pcall(run, widget)
--[NIR
if not status then rf2.print(err) end
--]]
Expand Down
5 changes: 4 additions & 1 deletion src/SCRIPTS/RF2/background_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ local function initializeQueue()
if autoSetName then
setModelName(rf2.modelName)
end
playTone(1600, 300, 0, PLAY_BACKGROUND)
playTone(523, 200, 0, PLAY_NOW) -- C5
playTone(659, 200, 0) -- E5
playTone(784, 200, 0) -- G5
playTone(1047, 200, 0) -- C6
--rf2.print("RTC set")
rf2.mspQueue.maxRetries = 3
initializationDone = true
Expand Down
2 changes: 2 additions & 0 deletions src/SCRIPTS/RF2/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ if scriptsCompiled then
run = rf2.executeScript("ui_lcd")
end
--rf2.showMemoryUsage("ui loaded")

rf2.isTool = true
else
run = assert(loadScript("COMPILE/compile.lua"))()
collectgarbage()
Expand Down
17 changes: 11 additions & 6 deletions src/SCRIPTS/RF2/ui_lvgl_runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ local IsInitialized = false
local InitTask
local IgnoreNextKeyEvent = false

local function run(event, touchState)
ui.update()
local function run(event, touchState, noUi)
if not noUi then ui.update() end

if not IsInitialized then
rf2.mspQueue.maxRetries = -1 -- retry indefinitely
Expand All @@ -17,8 +17,10 @@ local function run(event, touchState)
end
InitTask = nil
ui.clearWaitMessage()
ui.loadMainMenu()
ui.showMainMenu()
if not noUi then
ui.loadMainMenu()
ui.showMainMenu()
end
IsInitialized = true
end

Expand All @@ -40,7 +42,7 @@ local function run(event, touchState)
if event == 0x20D or event == EVT_VIRTUAL_PREV_PAGE or event == EVT_VIRTUAL_NEXT_PAGE then
-- For some reason the tool gets all key events twice, so we need to ignore the second one.
if not IgnoreNextKeyEvent then
IgnoreNextKeyEvent = true
if rf2.isTool then IgnoreNextKeyEvent = true end
if event == 0x20D then -- SYS break
ui.showPopupMenu()
elseif event == EVT_VIRTUAL_PREV_PAGE then
Expand All @@ -66,6 +68,9 @@ rf2.setWaitMessage = ui.setWaitMessage
rf2.clearWaitMessage = ui.clearWaitMessage
rf2.settingsSaved = ui.saveSettingsToEeprom
rf2.onPageReady = ui.onPageReady

rf2.showMainMenu = function()
ui.loadMainMenu()
ui.showMainMenu()
end
-- Return the run function to be called by the RF2 tool
return run
60 changes: 60 additions & 0 deletions src/WIDGETS/RfModelName/app.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
-- RfModelName widget
local zone, options = ...

local w = {
zone = zone,
options = options
}

local function getModelName()
local modelName = rf2 and rf2.modelName or nil

if not modelName then
modelName = model.getInfo().name
end

return modelName or "Unknown"
end

local function showWidget(widget)
lvgl.clear();
lvgl.build({
{
type = "box", flexFlow = lvgl.FLOW_COLUMN, children =
{
{ type = "label", text = function() return getModelName() end, w = widget.zone.x, align = CENTER },
{ type = "label", text = function() return tostring(getValue("Vbat")) end, w = widget.zone.x, align = CENTER },
}
}
});
end

w.update = function(widget, options)
widget.options = options
showWidget(widget)
end

local timeLastPing = nil
w.background = function(widget)
if rf2 and rf2.widgetIsAlivePing and (timeLastPing == nil or (getTime() - timeLastPing) / 100 >= 1) then
rf2.widgetIsAlivePing(widget)
timeLastPing = getTime()
end
end

w.refresh = function(widget, event, touchState)
widget.background(widget)

local modelName = getModelName()

if not rf2 then return end
--print(modelName)

if not widget.registered then
widget.ping = function(w) rf2.print("Ping!!!") end
rf2.registerWidget(widget)
widget.registered = true
end
end

return w
50 changes: 50 additions & 0 deletions src/WIDGETS/RfModelName/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Keep main.lua as lightweight as possible, since main.lua gets loaded for **all** widgets at boot time. Even if a widget isn't used by a particular model.
local name = "RF Model Name"

if lvgl == nil then
return {
name = name,
options = { },
create = function() end,
refresh = function()
lcd.drawText(10, 10, "LVGL support required", COLOR_THEME_WARNING)
end,
}
end

local function create(zone, options)
--print("RfModelName: create called")
local widget = loadScript("/WIDGETS/RfModelName/app.lua")(zone, options)
return widget
end

local function update(widget, options)
--print("RfModelName: update called")
if widget and widget.update then widget.update(widget, options) end
end

local function refresh(widget, event, touchState)
--print("RfModelName: refresh called")
if widget and widget.refresh then widget.refresh(widget, event, touchState) end
end

local function background(widget)
--print("RfModelName: background called")
if widget and widget.background then widget.background(widget) end
end

-- local function translate(widget)
-- --print("RfModelName: translate called")
-- if widget and widget.translate then widget.translate(widget) end
-- end

return {
useLvgl = true,
name = name,
options = {},
create = create,
update = update,
refresh = refresh,
background = background,
--translate = translate
}
Loading