--################################################################ -- written by CrisOHara -- Version 2 -- 3 January 2022 -- This software is free -- -- The script is developed for x9lite-S openTx 2.3.11 (but likely to run on some other radio) -- Cause some of the used values depend on "magic" numbers it may be nessesary to adapt for other radios -- The hardware dependency is base on the fact that different type of radios do have a different amount of switches. -- Also different software version may have an effect. -- So please check on companion first (or at least use a copy of an existing model) -- -- Script can be used as telemetry script in a telemetry view (but has to run only once so it should be removed after first run) -- or with execute when selected from the file menu direct from sdcard (that's what I prefer) -- Be aware that you have to select to model as active model first. -- Some definitions can only be created if specific sensor values are available. -- -- But anyway this script can be used as an example/template how to do your standard setup for logical switches and special functions. -- -- Hints: -- Many of the numbers used in the functions model.setLogicalSwitch or model.setCustomFunction (like the switch index) are difficult to find out. -- One possible way to find out is: -- Define the logical switch or special function manually in your radio. -- Then use the model.getLogicalSwitch or model.getCustomFunction and read out the values. -- If you need a switch like "|L01 (NOT L01)" try a negativ value (for xLite L02=37 ; |L02=-37) -- To find the number of the hardware switch or functions you can also count through the scroll menu when you select the -- hardwareswitch/function on the radio. (does work for hardwareswitches if they are the first in the scroll list -- and does work for "func") -- -- this example script creates: -- (standard) logical switches 1 to 7 and 11 to 14 and 62 to 64 -- (standard) spezial functions 1 to 5 -- This is the standard I use for all my models. -- -- no warranty: script is to be used on your own risk -- --###################################################################### --############################ looking for sensor ###################### local function my_lookForSens(sensorName) for i=0, 40 do k_sensor = model.getSensor(i); if (k_sensor ~= nil) and (k_sensor.name == sensorName) then return i ; end end return -1; end -- ############################# init function ################## local function modDef_init() local valueName = " "; local indexL01 = 36; -- switch-index of first logical switch (L01) ### depends on radio Type ### x9Lite = 36 --#### L01 L02 -> SF01 SF02 --#### check engine voltage ################################################ valueName = "VFAS"; sensListID = my_lookForSens(valueName); if sensListID >= 0 then valueID = getFieldInfo(valueName) and getFieldInfo(valueName).id or nil model.setLogicalSwitch (0, {func=4, v1=valueID, v2=110, delay=100, ["and"]=-37 }); model.setCustomFunction(0, {switch=(indexL01 + 0), func=12, value=valueID, active=10 }); model.setLogicalSwitch (1, {func=4, v1=valueID, v2=104, delay=50 }); model.setCustomFunction(1, {switch=(indexL01 + 1), func=12, value=valueID, active=5 }); else valueName = "A2"; sensListID = my_lookForSens(valueName); if sensListID >= 0 then valueID = getFieldInfo(valueName) and getFieldInfo(valueName).id or nil model.setLogicalSwitch (0, {func=4, v1=valueID, v2=110, delay=100, ["and"]=-37 }); model.setCustomFunction(0, {switch=(indexL01 + 0), func=12, value=valueID, active=10 }); model.setLogicalSwitch (1, {func=4, v1=valueID, v2=104, delay=50 }); model.setCustomFunction(1, {switch=(indexL01 + 1), func=12, value=valueID, active=5 }); end end --#### L03 -> SF03 --#### check receiver voltage ################################################## valueName = "RxBt"; sensListID = my_lookForSens(valueName); if sensListID >= 0 then valueID = getFieldInfo(valueName) and getFieldInfo(valueName).id or nil model.setLogicalSwitch (2, {func=4, v1=valueID, v2=48, delay=1 }); model.setCustomFunction(2, {switch=(indexL01 + 2), func=12, value=valueID, active=5 }); end --#### L04 -> SF04 SF05 --#### reset timer ############################################################# model.setLogicalSwitch (3, {func=11, v1=12, v2=(-129), v3=-1}); model.setCustomFunction(3, {switch=(indexL01 + 3), func=3, value=0, active=1 }); model.setCustomFunction(4, {switch=(indexL01 + 3), func=3, value=1, active=1 }); --#### L05 SF06 --#### reset telemetry ALT and VSpd three seconds after receiver GR6 switch on #### L05 ################## valueName = "Alt"; sensListID = my_lookForSens(valueName); if sensListID >= 0 then valueID = 111; model.setLogicalSwitch (4, {func=11, v1=valueID, v2=(-129+24), v3=-1}); model.setCustomFunction(5, {switch=(indexL01 + 4), func=3, value=(sensListID + 5), active=1 }); end valueName = "VSpd"; sensListID = my_lookForSens(valueName); if sensListID >= 0 then valueID = 111; model.setLogicalSwitch (4, {func=11, v1=valueID, v2=(-129+24), v3=-1}); model.setCustomFunction(6, {switch=(indexL01 + 4), func=3, value=(sensListID + 5), active=1 }); end --#### L06 L07 --#### Save engine cut off #### L06 L07 ##################################################### valueID = getFieldInfo("thr") and getFieldInfo("thr").id or nil model.setLogicalSwitch (5, {func=4, v1=valueID, v2=-99, ["and"]=12}); model.setLogicalSwitch (6, {func=18, v1=(indexL01 + 5), v2=10, delay=1}); --#### L11 L12 l13 l14 --#### Trainer ##################################################### valueID = getFieldInfo("ail") and getFieldInfo("ail").id or nil model.setLogicalSwitch (10, {func=2, v1=valueID, v2=-0, ["and"]=2, delay=10 }); valueID = getFieldInfo("ele") and getFieldInfo("ele").id or nil model.setLogicalSwitch (11, {func=2, v1=valueID, v2=-0, ["and"]=2, delay=10 }); valueID = getFieldInfo("thr") and getFieldInfo("thr").id or nil model.setLogicalSwitch (12, {func=4, v1=valueID, v2=-98, ["and"]=2, delay=10 }); valueID = getFieldInfo("rud") and getFieldInfo("rud").id or nil model.setLogicalSwitch (13, {func=2, v1=valueID, v2=-0, ["and"]=2, delay=10 }); --#### L62 L63 l64 --#### TelSxx script (telemetry announcement) ############################################## model.setLogicalSwitch (61, {func=11, v1=18, v2=(-129), v3=3, duration=0 }); model.setLogicalSwitch (62, {func=11, v1=18, v2=(-126), v3=-1, duration=0 }); model.setLogicalSwitch (63, {func=9, v1=21, v2=21 }); --#### SF06, SF07, SF08 --#### multSX script (Multi telemetry script ajust globale variable gavr8 entspricht param=7) ###### -- model.setCustomFunction(6, {switch=(7), func=5, value=0, param=7, active=1 }); -- model.setCustomFunction(7, {switch=(8), func=5, value=1, param=7, active=1 }); -- model.setCustomFunction(8, {switch=(9), func=5, value=2, param=7, active=1 }); end -- ############################### run function ##################### local function modDef_run(event) lcd.clear(); lcd.drawText (0, 0,"Logical switches", MIDSIZE); lcd.drawText (0, 20,"Special functions", MIDSIZE); lcd.drawText (0, 40,"## Created ##", MIDSIZE+INVERS); return 0; end return { init=modDef_init, run=modDef_run };