diff --git a/firmware/config/boards/hellen/hellen121nissan/board_configuration.cpp b/firmware/config/boards/hellen/hellen121nissan/board_configuration.cpp index 5c4317bc30..318320b989 100644 --- a/firmware/config/boards/hellen/hellen121nissan/board_configuration.cpp +++ b/firmware/config/boards/hellen/hellen121nissan/board_configuration.cpp @@ -118,7 +118,7 @@ void setBoardDefaultConfiguration() { engineConfiguration->isSdCardEnabled = true; engineConfiguration->enableSoftwareKnock = true; - engineConfiguration->canNbcType = CAN_BUS_NISSAN_VQ; + engineConfiguration->canNbcType = CAN_BUS_NBC_NONE; // none because handled by Lua! engineConfiguration->canTxPin = Gpio::D1; engineConfiguration->canRxPin = Gpio::D0; diff --git a/firmware/config/engines/nissan_vq.cpp b/firmware/config/engines/nissan_vq.cpp index f069783101..2592c2ef12 100644 --- a/firmware/config/engines/nissan_vq.cpp +++ b/firmware/config/engines/nissan_vq.cpp @@ -27,6 +27,90 @@ void setHellen121nissanQR() { } void setHellen121nissanVQ() { + // by definition this should be a copy-paste of https://github.com/rusefi/rusefi/blob/master/firmware/controllers/lua/examples/350z-ac.txt + strncpy(config->luaScript, R"( +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 +)", efi::size(config->luaScript)); + + engineConfiguration->trigger.type = TT_NISSAN_VQ35; engineConfiguration->specs.cylindersCount = 6;