local kelvin = 293 -- initialize with 20 Celcius (273 + 20) local pressure = 101325 -- initialize with standard athmospheric sealevel pressure local factor = 0 -- correction factor local inputs = { { "In_Chan", SOURCE }, -- connect to curve output { "Kel1", SOURCE }, -- connect to sensor 1001 to get temp in Kelvin { "Pas2", SOURCE } -- connect to 1002 to get pressure in Pascal } local outputs = { "inpt", "T1", "P2", "F3", "outp" } -- will show in the LUA script window as outputs -- inpt = Input value from fuel curve -- T1 = temperature in Kelvin (from sensor 1001) -- P2 = pressure in hectopascal (from sensor 1002) -- F3 = Correction factor either negative or positive ("0" is no correction) -- outp = output value to solenoid channel local function run(i, k, p) --In_Chan, Kelvin , Pascal if k > 0 then -- if k=0 reuse previous value, telemetry or sensor is lost kelvin = k * 10.24 -- OpenTX appears to scale values to 10 bit binary fields so need this correction end if p > 0 then -- if p = 0 reuse previous value, telemetry or sensor is lost pressure = p * 10.24 -- OpenTX appears to scale values to 10 bit binary fields so need this correction end factor = 1.024 * 273 * pressure / kelvin - 1024 -- calculate correction factor and 10 bit correction -- and apply correction factor to correct the input channel for temp and pressure solchan = (i + (i + 1024) * factor / 1024) -- output solenoid channel return i, kelvin, pressure, factor, solchan -- return the 5 defined local outputs end return { input=inputs, output=outputs, run=run }