This commit is contained in:
rusefillc 2023-05-31 21:04:46 -04:00
parent d9872f62fb
commit cf0e6b065a
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
-- this controls onCanRx rate as well!
setTickRate(300)
timeout = 3000
rpmSensor = Sensor.new("rpm")
rpmSensor : setTimeout(timeout)
--ppsSensor = Sensor.new("AcceleratorPedal")
--ppsSensor : setTimeout(timeout)
speedSensor = Sensor.new("VehicleSpeed")
speedSensor : setTimeout(timeout)
hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
function toHexString(num)
if num == 0 then
return '0'
end
local result = ""
while num > 0 do
local n = num % 16
result = hexstr[n + 1] ..result
num = math.floor(num / 16)
end
return result
end
function arrayToString(arr)
local str = ""
local index = 1
while arr[index] ~= nil do
str = str.." "..toHexString(arr[index])
index = index + 1
end
return str
end
function onRpmData(bus, id, dlc, data)
-- print('onRpmData ' ..arrayToString(data))
end
function onSpeedData(bus, id, dlc, data)
-- print('onSpeedData ' ..arrayToString(data))
end
canRxAdd(1, 0x23D, onRpmData)