Skip to content

Instantly share code, notes, and snippets.

@brentpicasso
Last active June 17, 2017 22:02
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 brentpicasso/97b9fc8116325059bf55d2c8ec232774 to your computer and use it in GitHub Desktop.
Save brentpicasso/97b9fc8116325059bf55d2c8ec232774 to your computer and use it in GitHub Desktop.
Demo script reading RPM from RaceCapture input, and updating the current shift light value
shiftx_can = 1
shiftx_id = 0xE3700
function shiftx_tx(offset, data)
txCAN(shiftx_can, shiftx_id + offset, 1, data)
sleep(10)
end
function splitWord(value)
return bit.band(value, 0xFF), bit.rshift(bit.band(value, 0xFF00),8)
end
function setLinearThreshold(id, seg, threshold, red, green, blue, flash)
local lowt
local hight
lowt, hight = splitWord(threshold)
shiftx_tx(41,{id, seg, lowt, hight, red, green, blue, flash})
sleep(10)
end
function configLinearGraph( renderStyle, linearStyle, lowRange, highRange)
local lowRangeLow
local lowRangeHigh
local highRangeLow
local highRangeHigh
lowRangeLow, lowRangeHigh = splitWord(lowRange)
highRangeLow, highRangeHigh = splitWord(highRange)
shiftx_tx(40,{renderStyle, linearStyle, lowRangeLow, lowRangeHigh, highRangeLow, highRangeHigh})
sleep(10)
end
function updateLinearGraph(value)
low, high = splitWord(value)
shiftx_tx(42, {low, high})
end
function onTick()
local rpm = readOBD2(12)
updateLinearGraph(rpm)
end
setTickRate(30)
initCAN(0, 500000)
configLinearGraph( 0, 0, 0, 7000)
setLinearThreshold(0, 0, 0, 0, 255, 0, 0)
setLinearThreshold(1, 0, 5000, 255,127, 0, 0)
setLinearThreshold(2, 0, 6000, 255, 0, 0, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment