--FunctionScript to loop the mixer values to telemetry sensors to log it in the logfile --Copyright LShems --www.just.solutions --GPL -- --copy file to /SCRIPTS/FUNCTIONS -- --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --!!!! create special function with switch ON to run the script 'logchx' !!!! --!!!! this function MUST come before any channeloverride function !!!! --!!!! any channeloverridefunction MUST be triggered by a LOGICAL switch !!!! --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -- --detect sensors. --after detection, delete current logfile --this to allow the new columns to be created correctly in the new logfile. --Logs will contain ppm value --PPMCENTER WILL BE INCLUDED --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --improved help and gVar support available --typos fixed --V1.4 NO CURVES SUPPORTED --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --include ChannelOverRide detection --V1.5 NO CURVES SUPPORTED --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --!!!! LUA doesn't allow to get the channelOverRide function number !!!!!! --!!!! add in the BUGSOLVE list all SFlines with the ChannelOverRide # !!!!!! --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --include ChannelOverRide detection BUGSOLVE workaround --V1.6 NO CURVES SUPPORTED --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --!!!! LUA channelOverRide problem fixed, my fault, no LUA bug # !!!!!! --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --gVar debug mode removed --use 'ppmMode' line to toggle logging in ppm or % --gVar settings on output offset, min and max supported. --V1.7 NO CURVES SUPPORTED --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! local mix = true and false -- outputs mixes to sensors. If outputs wanted, uncomment 'and false'. local ppmMode = true and false -- outputs in ppm, default %, if ppm wanted, uncomment 'and false' --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --don't edit below this if you don't know what you are doing --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! local overRide = {} local function gVarValue(value,setting) --Don't ask me to code comment. Ask the OpenTX devs to make userfriendly API's :). This is to detect if a Gvar is used as a value, and return that value. if setting == "min" then if value > 0 then return -10*model.getGlobalVariable(23-value,getFlightMode()) elseif value < -2000 then return 10*model.getGlobalVariable(2024+value,getFlightMode()) end elseif setting == "max" then if value < 0 then return 10*model.getGlobalVariable(24+value,getFlightMode()) elseif value > 2000 then return -10*model.getGlobalVariable(2023-value,getFlightMode()) end else local v = math.abs(value) if v>1000 then local gVar=1024-v return -10*model.getGlobalVariable(gVar,getFlightMode())*value/v end end return value end return { init=function() local offSet for i=1,64 do --for all special function entries do local CF = model.getCustomFunction(i-1) offSet = (CF.name == 'logchx') and (CF.switch - 65) or offSet --The 'ON' switch used on playscript 'logchx' comes just AFTER all logical switches in the switchlist. We use this to get the magic number LS offset. if CF.func == 0 and CF.active==1 and (CF.switch - offSet) > 0 and (CF.switch - offSet) < 65 then overRide[CF.param+1]={switch = "ls" .. (CF.switch - offSet),value = CF.value} --store the overrides per channel, including the switch to evaluate later end end end, run=function() for i=1,8 do --for 8 servoOutputs do local output = model.getOutput(i-1) local mixer = getValue('ch' .. i)/1024 * 100 --getValue local ppm if mix then --nothing, only mixer else if overRide[i] and (getValue(overRide[i].switch) == 1024) then mixer = overRide[i].value else output.offset = gVarValue(output.offset,"offset") output.min = gVarValue(output.min,"min") output.max = gVarValue(output.max,"max") output.offset = math.max(output.min,math.min(output.max,output.offset)) if mixer > 0 then --scale and trim mixer = output.offset/10 + mixer/100 *(output.max/10 - ((output.symetrical == 0) and output.offset/10 or 0)) else mixer = output.offset/10 - mixer/100 *(output.min/10 - ((output.symetrical == 0) and output.offset/10 or 0)) end mixer = (output.revert == 0 and 1 or -1) * math.min(output.max/10,math.max(output.min/10,mixer)) --clip end ppm = 1500 + mixer/100*512 + output.ppmCenter end mixer = math.floor(mixer*10.24+0.5) setTelemetryValue(0X0000,0,100+i,ppmMode and ppm or mixer,0,0,"ch".. i) end end, }