RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Help with bitOp
Author Message
Reply with quote
Post Help with bitOp 
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(bit.band(value, 0x01), 3)
end

[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": ""
}

View user's profile Send private message
Reply with quote
Post  
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
Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum