--################################################################ -- written by CrisOHara -- Version 1 -- 6 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 the model as active model first. -- -- 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.insertInput or model.insertMix (like the source index) are difficult to find out. -- One possible way to find out is: -- Define the input or mixer manually in your radio. -- Then use the model.getInput or model.getMix 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 hardware switches if they are the first in the scroll list -- and does work for "func") -- -- this example script creates: -- (standard) Inputs I10 to I14 (Brake/Flap max, and input for trainer) -- (standard) Mixer for Trainer and save engine switch -- 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_lookForMixer (channelNr, sourceNr) local result = -1; lineAmount = model.getMixesCount(channelNr); if lineAmount == 0 then return lineAmount, result; end for i=0, lineAmount-1 do mixerData = model.getMix( channelNr, i ); if mixerData.source == sourceNr then result = 1; end end return lineAmount, result; end -- ############################# init function ################## local function InpMix_init() local inputData = { name, inputName, source, weight, offset, switch, curveType, curveValue, carryTrim, 'flightModes' } local inpNR = 0; -- ###### Input Section ####################################### -- creating input10 (brake or flaps) inpNR = 10; inputStatus = model.getInput( (inpNR-1), 0 ) or nil; if inputStatus == nil then inputData = { name="Brake", inputName="Bra", source=80, weight=100, offset=0, switch=0, curveType=0, curveValue=0, carryTrim=FALSE, flightModes=512}; model.insertInput(inpNR-1, 0, inputData); end -- creating input11 (trainer aileron) inpNR = 11; inputStatus = model.getInput( (inpNR-1), 0 ) or nil; if inputStatus == nil then inputData = { name="TrAile", inputName="TrA", source=159, weight=100, offset=0, switch=0, curveType=1, curveValue=50, carryTrim=FALSE, flightModes=512}; model.insertInput(inpNR-1, 0, inputData); end -- creating input12 (trainer elevator) inpNR = 12; inputStatus = model.getInput( (inpNR-1), 0 ) or nil; if inputStatus == nil then inputData = { name="TrElev", inputName="TrE", source=160, weight=100, offset=0, switch=0, curveType=1, curveValue=50, carryTrim=FALSE, flightModes=512}; model.insertInput(inpNR-1, 0, inputData); end -- creating input15 (trainer Trottle) inpNR = 13; inputStatus = model.getInput( (inpNR-1), 0 ) or nil; if inputStatus == nil then inputData = { name="TrTrot", inputName="TrT", source=162, weight=100, offset=0, switch=0, curveType=0, curveValue=0, carryTrim=FALSE, flightModes=512}; model.insertInput(inpNR-1, 0, inputData); end -- creating input16 (trainer ruder) inpNR = 14; inputStatus = model.getInput( (inpNR-1), 0 ) or nil; if inputStatus == nil then inputData = { name="TrRude", inputName="TrR", source=161, weight=100, offset=0, switch=0, curveType=1, curveValue=50, carryTrim=FALSE, flightModes=512}; model.insertInput(inpNR-1, 0, inputData); end -- ###### Mixer Section ###################################### local mixerData = { name, source, weight, offset, switch, multiplex, curveType, curveValue, flightModes, carryTrim, mixWarn, delayUp, delayDown, speedUp, speedDown} local sourceNr = 0; -- creating Mixer Ch1 (Aileron) channelNr = 1; sourceNr = 11; lineAmount, status = my_lookForMixer (channelNr-1, sourceNr); if status == -1 then mixerData = { name="TrAile", source=sourceNr, weight=100, offset=0, switch=(36+10), multiplex=2, curveType=0, curveValue0, flightModes=512, carryTrim=0, mixWarn=0, delayUp=0, delayDown=0, speedUp=0, speedDown=0} model.insertMix(channelNr-1, lineAmount, mixerData); end -- creating Mixer Ch2 (Elevator) channelNr = 2; sourceNr = 12; lineAmount, status = my_lookForMixer (channelNr-1, sourceNr); if status == -1 then mixerData = { name="TrElev", source=sourceNr, weight=100, offset=0, switch=(36+11), multiplex=2, curveType=0, curveValue0, flightModes=512, carryTrim=0, mixWarn=0, delayUp=0, delayDown=0, speedUp=0, speedDown=0} model.insertMix(channelNr-1, lineAmount, mixerData); end -- creating Mixer Ch3 (Trottle) channelNr = 3; sourceNr = 13; lineAmount, status = my_lookForMixer (channelNr-1, sourceNr); if status == -1 then mixerData = { name="TrTrott", source=sourceNr, weight=100, offset=0, switch=(36+12), multiplex=2, curveType=0, curveValue0, flightModes=512, carryTrim=0, mixWarn=0, delayUp=0, delayDown=0, speedUp=0, speedDown=0} model.insertMix(channelNr-1, lineAmount, mixerData); end --creating Mixer Ch3 (save) channelNr = 3; sourceNr = 80; lineAmount, status = my_lookForMixer (channelNr-1, sourceNr); if status == -1 then mixerData = { name="Save", source=sourceNr, weight=-100, offset=0, switch=-(35+7), multiplex=2, curveType=0, curveValue0, flightModes=512, carryTrim=0, mixWarn=0, delayUp=0, delayDown=0, speedUp=0, speedDown=0} model.insertMix(channelNr-1, lineAmount, mixerData); end -- creating Mixer Ch4 (Ruder) channelNr = 4; sourceNr = 14; lineAmount, status = my_lookForMixer (channelNr-1, sourceNr); if status == -1 then mixerData = { name="TrRude", source=sourceNr, weight=100, offset=0, switch=(36+13), multiplex=2, curveType=0, curveValue0, flightModes=512, carryTrim=0, mixWarn=0, delayUp=0, delayDown=0, speedUp=0, speedDown=0} model.insertMix(channelNr-1, lineAmount, mixerData); end -- creating Mixer Ch1 (Aileron) channelNr = 5; sourceNr = 11; lineAmount, status = my_lookForMixer (channelNr-1, sourceNr); if status == -1 then mixerData = { name="TrAile", source=sourceNr, weight=-100, offset=0, switch=(36+10), multiplex=2, curveType=0, curveValue0, flightModes=512, carryTrim=0, mixWarn=0, delayUp=0, delayDown=0, speedUp=0, speedDown=0} model.insertMix(channelNr-1, lineAmount, mixerData); end end -- ############################### run function ##################### local function InpMix_run(event) lcd.clear(); lcd.drawText (0, 0,"Inputs", MIDSIZE); lcd.drawText (0, 20,"Mixers", MIDSIZE); lcd.drawText (0, 40,"## Created ##", MIDSIZE+INVERS); return 0; end return { init=InpMix_init, run=InpMix_run };