Space Navigator driver code

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

Moderator: Moderators

Post Reply
superbigio
Posts: 18
Joined: Thu Jan 25, 2007 1:11 pm
Location: Los Angeles

Space Navigator driver code

Post by superbigio »

Hi there,

I am in the process of writing a dedicated Space Navigator driver for an application called Max/MSP by Cycling'74. The purpose of the driver is to make the SN available inside the Max/MSP environment so to expand the possible uses of this awesome device.

I am already estabilishing connection to the device successfully and are able to set up USB add/removal notifications. I would like to ask if it's possible to have a look at the OS X driver code so to understand the data organization required to send commands and receive data from the SN.

What I would like to be able to do is:

- Turn each axis on/off individually
- Adjust axis sensitivity (speed - I believe)
- Switch between normal and dominant mode
- Turn LED On/Off
- ...and of course, reading the axis and button values

Also - as a side question - I'd like to ask if you guys recommend to talk to the device by using Set/GetReports commands and parse the data with a custom function, or if you are actually reading and setting the device values as HID elements. I am leaning towards Set/GetReports, because of crossplatform issues (Windows), but I just wanted to know if you have any other comments in regards.

Thanks for any support.

- Luigi Castelli

P.S
I just bought my 2nd Space Navigator.
Can't wait to have 2 running at the same time!!!
flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan »

I would suggest using the framework that's included with the driver. It will save you time and you can use our preference pane to configure axis on/off, sensitivity etc.

See viewtopic.php?t=232
superbigio
Posts: 18
Joined: Thu Jan 25, 2007 1:11 pm
Location: Los Angeles

LEDs and Sensitivity

Post by superbigio »

Hi there,

thanks for your reply flomotan...

Got up and running pretty quickly.

Now, I have got a few more questions if you don't mind:

1 - Is there a way to control the Space Navigator LED, the axis sensitivity and the axis enable/disable feature ? Basically those feature that you can nicely control from the driver...
I would like to implement that level of control in my driver independent from the Preference Panel.

2 - I don't understand the dfference between buttonState and buttonID. On my machine both the buttonState and buttonID are always the same number. (1 if I press the left button, 2 if I press the right button)

3 - Also, I need to pass a struct pointer as an argument to the MessageHandler function, so that I can save the axes values in my own data structure. How can I do that ?

Thanks in advance for your help.

- Luigi
flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan »

1 - to control the LED, you can use ConnexionControl(kConnexionCtlSetLEDState, 0, &result). As far as controlling sensitivity and axis on/off, one option is for you to provide this UI yourself and control it from your app. You'd of course need to enable all axes and set the sensitivity high for your app in our preference pane. That will give you the range to play with in your app. For instance, you can scale the values down to make it less sensitive or to set an axis value to 0 to turn it "off".

2 - State is 1 or 0 which corresponds to press and release. ID is the button number

3 - Not sure I understand this one but you can just save the axes values in your DS when you're called.
superbigio
Posts: 18
Joined: Thu Jan 25, 2007 1:11 pm
Location: Los Angeles

Post by superbigio »

Thanks for your quick reply.

I am on PowerBookPro (intel) running Mac OS 10.4.7.

1- ConnexionControl(kConnexionCtlSetLEDState, 0, &result) doesn't work as expected here. After fiddling around with it for a while I found out that I have to provide a param value of -15 (decimal) to turn the LED on and a param value of -1 to turn it off (I think any negative number except -15 would work, though).

2 - I am getting a 1 when I press the left button and I am getting a 2 when I am pressing the right button. When there's no button pressed I am getting a 0. This goes for both the button state field AND button ID field. There's no difference between the two on my machine.

3 - I am not sure I understand what you mean when you say "when you're called". I am programming in C and my data structure is not global to the HandleMessage function. So the HandleMessage callback gets called everytime there's an event from the device. But I have no access inside that function. The HandleMessage function is prototyped as:

void HandleMessage(io_connect_t connection, natural_t messageType, void *messageArgument);

I need to pass a pointer referencing my Data Structure to the HandleMessage function if I want to save the axis values in my DS. Or am I overlooking something ?

4 - In the 3Dconnexion driver is the sensitivity implemented in software by just scaling the ranges of the axes values, or is it actually changing a sensor parameter at the hardware level ?

5 - What is the bit resolution of each of the axis values?

Thanks again.

- Luigi
flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan »

1 - Thanks for pointing this out. We'll queue this is up for fixing

2 - The ID gets populated only on button down events. button up returns zero in both fields as you've mentioned. Are discrete up events with button IDs something you need? This will help us prioritize

3 - There's no option to pass-in an arbitrary pointer into the API for inclusion as a parameter in the messagehandler. You'd have to create another way to take the data in the messagehandler and pass it to your DS handling code. Perhaps a setter function?

4 - It's all in sw

5 - I'd recommend planning for a value range of -500 to 500. That typically provides a nice range that feels good to most users
superbigio
Posts: 18
Joined: Thu Jan 25, 2007 1:11 pm
Location: Los Angeles

Post by superbigio »

OK, got it.

2 - I do not need discrete up events with button IDs. Thank you. What I meant is that - as it is now - the button ID reports ALWAYS the same value held in the button state field. There's no difference between the two. You might just as well use one value field, which - in the end - might be the best option. You can decode 2 buttons up and down states with one 2 bit value. LSB will be 1 or 0 for left button and MSB will be 1 or 0 for right button. Then you can decode both buttons with a mask and shift. That' what I am doing right now and I am using ONLY the button state field. Just my 2 cents...

3 - Is that something could be implemented in the future? I would consider it almost an essential feature.

4 - OK, great.

5 - I get about -2500 to +2500 for each axis, which adds up to about 5000 states. The closer power of 2 would be 8192 which would make each axis at least a 13 bit value. What I meant is: how many bits of resolution do the raw values coming out of 6-axis optical sensor carry?

- Luigi
flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan »

The sensor puts out 10 bits. That's scaled in the driver resulting in the value range you see. However, I'd suggest programming to -500 to 500.
superbigio
Posts: 18
Joined: Thu Jan 25, 2007 1:11 pm
Location: Los Angeles

Post by superbigio »

OK, thank you.

In my fiddling with the Space Navigator I found out a few other interesting facts.

1 - Please don't hesitate to tell me if I am completely off here, but it seems that client IDs are not reported correctly by the HandleMessage() function. In my own Initialize() function I call RegisterConnexionClient() twice because I have two Space Navigator devices connected. So I am expecting to be able to distinguish between what Space Navigator is sending data by looking at its client ID. However the HandleMessage() function always reports only the last ID assigned, no matter what device is sending out data. Could you please check that. I would like to make sure I am not doing something wrong in my code... Thank you.

2 - In my own CleanUp() function I call UnregisterConnexionClient(clientID_1), UnregisterConnexionClient(clientID_2) and CleanupConnexionHandlers(). Both my Space Navigators can still receive messages after they have been unregistered and all the 3dconnexion handlers have been cleaned up. Not a big deal to me really, but I am just letting you know...

3 - The function RegisterConnexionClient() has a parameter called 'name' which I always pass NULL to. Could you please explain what that parameter is for?

4 - Dominant Mode is implemented in software. Am I correct in assuming so?

Thanks again for your support.

- Luigi
flomotan
Moderator
Moderator
Posts: 287
Joined: Mon Jan 08, 2007 3:37 pm

Post by flomotan »

1 - Right now the interface treats multiple devices as one. It does not qualify which device is sending the data. You only need to call RegisterConnexionClient once. We'll look at tagging the incoming data with a device ID.

2 - Thanks for pointing this out. It should stop sending

3 - It will be used to pass a CFBundleIdentifier string to identify your app. Right now it's not yet functional

4 - Correct
superbigio
Posts: 18
Joined: Thu Jan 25, 2007 1:11 pm
Location: Los Angeles

Post by superbigio »

OK, great!

Thank you so much for answering all my questions.

Do you have an approximate release date for a version of the driver with multiple device support ?

Thanks again.

- Luigi
ettore
Moderator
Moderator
Posts: 127
Joined: Wed Mar 14, 2007 5:55 pm
Location: SF Bay Area, CA

Post by ettore »

Hi Luigi,

as of 1.0.2 our OS X driver supports multiple devices. It's also documented in our sdk documentation:
http://www.3dconnexion.com/support/4f.php

(BTW: the Windows driver does not support multiple devices.)

Also, I just wanted to say thank you for adding support for the SN in that amazing app that is Max/MSP (I played with it myself in the past :D ). Please let us know when you are done with your efforts, we will gladly add it to our list of supported apps.
ettore pasquini
software engineer
3Dconnexion, inc.
Post Reply