canRxAdd(0x35d) setTickRate(100) t = Timer.new() t : reset() globalAcOut = 0 function onTick() local RPMread = math.floor(getSensor("RPM") + 0.5) / 3.15 local RPMhi = RPMread / 256 local RPMlo = RPMread cltValue = getSensor("CLT") cltValue = (cltValue == nil and 0 or tps) local CLTread = math.floor(cltValue + 0.5) --print('ac out = ' ..globalAcOut) if globalAcOut == 1 and RPMread >80 then fanPayloadOff = { 0x88, 0x00 } fanPayloadLo = { 0x88, 0x00 } fanPayloadHi = { 0x88, 0x00 } else --print('ac off payload') fanPayloadOff = { 0x00, 0x00 } fanPayloadLo = { 0x40, 0x00 } fanPayloadHi = { 0x80, 0x00 } end cltGauge = 0x00 -- acOut = {0x32, 0x80, 0x00, 0x10, 0x00, 0x00} -- txCan(1, 0x625, 0,acOut) -- clt gauge stuff if CLTread < 115 then -- txCan(1, 0x608, 0, canCLTpayloadNo) cltGauge = math.floor(CLTread * 1.5 + 0.5) elseif CLTread >= 115 then -- txCan(1, 0x608, 0, canCLTpayloadHi) cltGauge = 0xF0 end -- print('clt gauge = '..cltGauge) -- rpm fun stuff if t : getElapsedSeconds() < 2 then CLTandRPM = { 0x00, 0x18, 0x0C, 0x01, 0x0A, 0x87, 0xFF, 0xFF } else CLTandRPM = { 0x00, 0x18, 0x0c, RPMlo, RPMhi, 0x87, 0xFF, cltGauge } end txCan(1, 0x23D, 0, CLTandRPM) -- transmit CLT and RPM if RPMread > 80 then if CLTread <= 80 then txCan(1, 0x1F9, 0, fanPayloadOff) elseif CLTread >= 85 and CLTread < 90 then txCan(1, 0x1F9, 0, fanPayloadLo) elseif CLTread >= 90 then txCan(1, 0x1F9, 0, fanPayloadHi) end else txCan(1, 0x1F9, 0, fanPayloadOff) end -- print('CLT temp' ..CLTread) end function onCanRx(bus, id, dlc, data) --print('got CAN id=' ..id ..' dlc=' ..dlc) --print('ac value is= '..data[1]) if data[1] == 193 then setAcRequestState(true) globalAcOut = 1 --print('ac is on') else setAcRequestState(false) globalAcOut = 0 --print('ac is off') end end