Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
-- 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})
bestlap = 0
lapstarttime = 0
function onTick()
-- check whether or not we are moving and then enable logging
-- send GPS data to AEM CD7
-- check if we're at start finish to build lap runtime
if getAtStartFinish() then
-- start time is current time in miliseconds
lapstarttime = getUptime()
-- send the lap data to the AEM CD7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment