Help with bitOp

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
Posts: 27
Joined: Thu Apr 09, 2015 8:18 pm

Help with bitOp

Post by Mustangkev »

I have an individual bit mapped in the can mapping section but I need to reference it in the LUA script. Can anyone convert this in to a Lua script for me? I am trying to use the cruise control button to start and stop logging. The cruise control dash light is on can ID 1349 and the 4th bit of the first byte. I tried to do this by using the E46 clutch example but I can't get it to work. Here is the channel, Can and filter text that I have in my E46 LUA script that doesn't work.

cruiseId = addChannel("Cruise", 10, 0, 0, 1)

function cruiseFilter(value)
return bit.rshift(, 0x01), 3)

[1349] = function(data) map_chan(cruiseId, data, 0, 1, 1,0,cruiseFilter) end,

This is the working cruise channel from the can mapping.

"add": 0.0,
"bigEndian": false,
"bm": true,
"bus": 0,
"div": 1.0,
"filtId": 0,
"id": 1349,
"idMask": 0,
"len": 1,
"max": 1,
"min": 0,
"mult": 1.0,
"nm": "Cruise",
"offset": 3,
"prec": 0,
"sr": 10,
"type": 0,
"ut": ""

Site Admin
Posts: 5986
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Basically the easiest way to do it is filter the value using the AND mask (band() ) and then just checking if it's zero (bit not set) or non zero (bit is set).

Try it with just the band() and watch the data using a println() output to the console - that should help you get further!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply