View Single Post
Old 01-12-2007, 05:56 AM   #27
sama
FLAC
sama's CarPC Specs
 
sama's Avatar
 
Join Date: Feb 2006
Location: London, UK
Vehicle: BMW 850CSi
Posts: 1,280
My Photos: ()
ok, that was a false alarm. After looking again, it seems that the "sign" value not only switches between 0 and 255, but it also goes to 254 and to 1 (to indicate second lung).

This means that the actual range of the device is more than +/- 255. I expected to see it go to The max I've seen it get to on the "second lung" (that term is just too catchy to stop using!) is 190. So that's a total range of +/- 445.

@cherrybomb
At the moment, I've got code that checks for 255/254/0/1 etc, and act accordingly. However this is not the way to do it. It seems that this is not an 8 bit number after all, but actually a 10-bit, which is odd!

Using some bitwise operations, I think a much more elegant solution can be obtained. I'm having to go back to my elementary s/w engineering notes (5 years old, but still have them )

Since we have 2 x 8 bit numbers, I'm thinking somethign along these lines:

The value for each axis in each direction ranges from:

00000000 (0)
11111111 (255)

and the "sign"/second lung figure is one of these four:

00000000 (0)
00000001 (1)
11111110 (254)
11111111 (255)

if we take just the last two bits from the sign:

00 (0)
01 (1)
10 (254)
11 (255)

and append that to the first 8 bits, to get a 10 bit number, then we look at the values, this would make things a much much more efficient, perofrmance and code wise. To test the theory, here are some values to see how it would work:

using 00000111 for the value (7), then we should be able to get the following figures.

0000000111 = 7
0100000111 = 263
1000000111 = -7 (if the first bit is read as a sign)
1100000111 = -263 (if the first bit is read as a sign)

and at this stage, we can check the MSB (most significant bit, far left) and that tells us the sign, then we shift everything to the left, and we'll have a value which we can multiply by -1 based on the MSB.

whaddaya think?
__________________
///Mputer - Velocity - TomTom - Vision - Bezel - CarPC
sama is offline   Reply With Quote