VB6 and SpacePilot

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

xpeace77
Posts: 5
Joined: Sun Aug 22, 2010 5:13 pm

Post by xpeace77 »

I found the bug I filtered all Values < 20 - Now I got it working ;-) Value gets to 1 as expected :-) Thank you :-)
xpeace77
Posts: 5
Joined: Sun Aug 22, 2010 5:13 pm

Post by xpeace77 »

// Current Implemenation of Reading Hid Report Axis Data

Private Function GetAxisData(Value As Byte, MSB As Byte) As Long

Select Case MSB

Case 0:
GetAxisData = -Value

Case 1:
GetAxisData = -(Value + 255)

Case 255:
GetAxisData = 255 - Value

Case 254:
GetAxisData = 512 - Value

End Select

End Function

Maybe it could be speed up a bit by passing a 2Byte Integer to read both Values Simultaneously and then do some Byte swapping Magic :-)

If someone got a better solution would be nice to post here thx :-)
jwick
Moderator
Moderator
Posts: 3337
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

I don't know what you mean by reportbuffers 5/6....oh and now I see your new code. You should be able to do this with normal VB math.

You get translation and rotation values separately. Each will arrive in a 7 byte packet. The first byte indicates which type of packet you have. 1 indicates a translation packet. 2 indicates a rotation packet. (3 indicates a button packet).

The sample translatation packet then would be:

0 LSBX MSBX LSBY MSBY LSBZ MSBZ

Where LSBX is the Least Significant Byte of the X value and MSBX is the Most Significant Byte of the X value.

The MSB is 0 until you fill up the LSB. Then the extra bits are put into the MSB. E.g.,

__MSB______LSB__
|________|111111111| then add 1:
|_______1|_________|

The latter representing a 16-byte value 0000000100000000

Etc. You can get your compiler to do the combination of the bytes into a signed integer for you. You have to make sure negative numbers are done correctly by the syntax you construct. The negative numbers are twos-complement.

This is usually as simple as:

value = (MSB*256) + LSB

Often explicit casting is required to get the sign bit extended properly. I think that's what your code is in effect doing. You can't just look at one bit in the MSB though. The end user can scale that value up past 350-ish.

I don't know what the syntax is in VB. Judicious diagnostic printing will get you there.
Post Reply