From 2d08d8ea2854f16d3692c748ef42c49ccb4148a4 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Mon, 18 Jul 2022 17:01:44 -0400 Subject: [PATCH] Nissan Lua --- firmware/controllers/lua/examples/350z-ac.txt | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 firmware/controllers/lua/examples/350z-ac.txt diff --git a/firmware/controllers/lua/examples/350z-ac.txt b/firmware/controllers/lua/examples/350z-ac.txt new file mode 100644 index 0000000000..44d6de0183 --- /dev/null +++ b/firmware/controllers/lua/examples/350z-ac.txt @@ -0,0 +1,79 @@ +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 + local CLTread = math.floor(getSensor("CLT") + 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 \ No newline at end of file