Hopefully not breaking anything

This commit is contained in:
rusefillc 2022-11-15 15:15:17 -05:00
parent 2bc3b7cea5
commit eb700af722
1 changed files with 29 additions and 24 deletions

View File

@ -1,5 +1,9 @@
canRxAdd(0x35d)
OUT_1F9 = 0x1F9
OUT_233 = 0x233
OUT_23D = 0x23D
setTickRate(100)
t = Timer.new()
t : reset()
@ -7,15 +11,15 @@ t : reset()
globalAcOut = 0
function onTick()
local RPMread = math.floor(getSensor("RPM") + 0.5) / 3.15
local rpmValue = math.floor(getSensor("RPM") + 0.5)
local RPMread = rpmValue / 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)
cltValue = (cltValue == nil and 0 or cltValue)
--print('ac out = ' ..globalAcOut)
if globalAcOut == 1 and RPMread >80 then
if globalAcOut == 1 and rpmValue > 250 then
fanPayloadOff = { 0x88, 0x00 }
fanPayloadLo = { 0x88, 0x00 }
fanPayloadHi = { 0x88, 0x00 }
@ -27,41 +31,42 @@ function onTick()
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)
if cltValue < 115 then
cltGauge = math.floor(cltValue * 1.5 + 0.5)
else
cltGauge = 0xF0
end
-- print('clt gauge = '..cltGauge)
-- rpm fun stuff
if t : getElapsedSeconds() < 2 then
CLTandRPM = { 0x00, 0x18, 0x0C, 0x01, 0x0A, 0x87, 0xFF, 0xFF }
CLTandRPM_D = { 0x00, 0x18, 0x0C, 0x01, 0x0A, 0x87, 0xFF, 0xFF }
else
CLTandRPM = { 0x00, 0x18, 0x0c, RPMlo, RPMhi, 0x87, 0xFF, cltGauge }
CLTandRPM_D = { 0x00, 0x18, 0x0c, RPMlo, RPMhi, 0x87, 0xFF, cltGauge }
end
txCan(1, 0x23D, 0, CLTandRPM) -- transmit CLT and RPM
state_233 = rpmValue > 250 and 0x10 or 0x18
CLTandRPM_3 = { cltGauge, 0x8C, 0x20, state_233, RPMlo, 0x00, 0x00, RPMhi }
txCan(1, OUT_233, 0, CLTandRPM_3) -- transmit CLT and RPM for who knows whom
txCan(1, OUT_23D, 0, CLTandRPM_D) -- transmit CLT and RPM for gauge cluster
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)
if rpmValue > 250 then
if cltValue <= 80 then
txCan(1, OUT_1F9, 0, fanPayloadOff)
elseif cltValue < 85 then
-- send nothing
elseif cltValue < 90 then
txCan(1, OUT_1F9, 0, fanPayloadLo)
else
txCan(1, OUT_1F9, 0, fanPayloadHi)
end
else
txCan(1, 0x1F9, 0, fanPayloadOff)
txCan(1, OUT_1F9, 0, fanPayloadOff)
end
-- print('CLT temp' ..CLTread)
-- print('CLT temp' ..cltValue)
end