Skip to content

Instantly share code, notes, and snippets.

@thoraxe
Created June 2, 2019 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoraxe/dc2f28d789e47ab323846082cc40786b to your computer and use it in GitHub Desktop.
Save thoraxe/dc2f28d789e47ab323846082cc40786b to your computer and use it in GitHub Desktop.
function sendLapData()
-- build lap data
local lapcount = getLapCount()
local lastlap = getLapTime()
local predlap = getPredTime()
-- calculate if last lap is better than best lap
if lastlap < bestlap then
bestlap = lastlap
end
-- delta between predlap and bestlap in seconds
local lapdelta = bestlap - predlap
-- current elapsed lap time in miliseconds
local elapsedtime = getUptime() - lapstarttime
-- scale values by 1000 to make integers, scale down in AEM CD-7
local lastscale1,lastscale2 = split16(lastlap * 1000)
local predscale1,predscale2 = split16(predlap * 1000)
local bestscale1,bestscale2 = split16(bestlap * 1000)
local deltascale1,deltascale2 = split16(lapdelta * 1000)
local elapsed1,elapsed2 = split16(elapsedtime)
-- send data
sendcan(2, 1430, {lastscale1, lastscale2, predscale1, predscale2, bestscale1, bestscale2, deltascale1, deltascale2})
sendcan(2, 1431, {lapcount, elapsed1, elapsed2})
end
bestlap = 0
lapstarttime = 0
function onTick()
-- check whether or not we are moving and then enable logging
setLogging()
-- send GPS data to AEM CD7
sendGPS()
sendImu()
-- check if we're at start finish to build lap runtime
if getAtStartFinish() then
-- start time is current time in miliseconds
lapstarttime = getUptime()
end
-- send the lap data to the AEM CD7
sendLapData()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment