-- ##################################################################################################### -- Multi Script --- Telemetry script to run more than one telemetry scripts on the same screen -- -- Author origin: Jesper Frickmann -- modified by: ChrisOhara -- version 1 -- 13.01.2022 -- This software is free -- -- This version is limited to 3 scripts because a 3-position switch is used, -- You can modify the script and try to use more scripts. -- This would require a 6-position switch or using a global variable instead; -- ( see varibales: switchID and switchPos) -- -- Running the script in one single telemetry screen you can select the disired script -- by switch and logical switch (and therefore by flightmode or global variable ...) -- -- ##################################################################################################### local script = {}; local scriptAmount = 0; -- ########## start - list of scripts (maximum of 3 because that's the amount of switch positions available) ### script[scriptAmount] = "/SCRIPTS/TELEMETRY/TelSxx.lua"; scriptAmount = scriptAmount + 1; --script[scriptAmount] = "/SCRIPTS/TELEMETRY/inav.lua"; scriptAmount = scriptAmount + 1; -- inav only works on radio, not ion companion script[scriptAmount] = "/SCRIPTS/TELEMETRY/gplusl.lua"; scriptAmount = scriptAmount + 1; -- ########## end - list of scripts ########################################################################### local error = {}; local switchID = getFieldInfo("sc").id -- defines the switch that is used -- #################################################################### local function init() local chunk for i=0, scriptAmount-1 do chunk, error[i] = loadScript(script[i]) if chunk then script[i] = chunk() -- Saving memory by re-using script var if script[i].init then script[i].init() script[i].init = nil -- Not needed anymore, save memory end end end end -- ##################################################################### local function background() for i=0, scriptAmount-1 do if not error[i] and script[i].background then script[i].background() end end end -- #################################################################### local function display(event, i) if error[i] then lcd.drawText(0, 10, error[i], SMLSIZE) else script[i].run(event) end end -- ##################################################################### local function run(event) local switchPos = 1 + (getValue(switchID)/1024); -- in this case (taranis x9liteS, 3-position switch) valid values are 0,1,2 if switchPos < 0 then switchPos = 0; else if switchPos > (scriptAmount - 1) then switchPos = scriptAmount - 1; end end display (event, switchPos); end return { init = init, background = background, run = run }