--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 --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! local BUGSOLVE = { [2]=2, [6]=1, } --local mix = true -- if outputs wanted, uncomment. --local gVar = true -- gVar 1-8 for FM0 is set to the calculated value to check with mixer source MAX weight gVar --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --don't edit below this if you don't know what you are doing --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! local overRide = {} 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 CF.func = -1*(BUGSOLVE[i] or 0) if CF.func < 0 and CF.active==1 and (CF.switch - offSet) > 1 and (CF.switch - offSet) < 64 then overRide[-CF.func]={switch = "ls" .. (CF.switch - offSet),value = CF.value} 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 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+0.5) if gVar then model.setGlobalVariable(math.min(7,i-1),0,mixer) end setTelemetryValue(0X0000,0,100+i,ppm or mixer,0,0,"ch".. i) end end, }