by wave » Tue Jan 16, 2007 10:30 am
Thanks for the info about talking to the device. One nit - on my system, the framework got installed in /Library/Frameworks/, not /System/Library/Frameworks - I assume that's correct?
Also, like the other poster, my add and remove device procs get called, but I don't get anything sent to the handle message one - I twist the Navigator, press buttons, etc - nothing.
Any ideas?
In my case, I'm developing with Objective-C/Cocoa, and have a simple app with a class that looks like this:
#import <Cocoa>
#import <3DconnexionClient>
@interface MyController : NSObject
{
UInt16 _myID;
}
@end
#import "MyController.h"
@implementation MyController
static void
HandleMessage(io_connect_t connection, natural_t messageType, void *messageArgument) {
ConnexionDeviceStatePtr msg = (ConnexionDeviceStatePtr)messageArgument;
switch(messageType) {
case kConnexionMsgDeviceState:
/* Device state messages are broadcast to all clients. It is up to
* the client to figure out if the message is meant for them. This
* is done by comparing the "client" id sent in the message to our
* assigned id when the connection to the driver was established.
*
*/
switch (msg->command)
{
case kConnexionCmdHandleAxis:
// msg->axis[0] .. [5] contain X, Y, Z, Rx, Ry, Rz data
{
SInt16 x = msg->axis[0];
SInt16 y = msg->axis[1];
SInt16 z = msg->axis[2];
SInt16 Rx = msg->axis[3];
SInt16 Ry = msg->axis[4];
SInt16 Rz = msg->axis[5];
NSLog(@"x, y, z == (%hi, %hi, %hi) Rx, Ry, Rz == (%hi, %hi, %hi)", x, y, z, Rx, Ry, Rz);
}
break;
case kConnexionCmdHandleButtons:
// msg->value is the button state
// msg->buttons is the button ID
{
SInt32 buttonState = msg->value;
UInt16 buttonID = msg->buttons;
NSLog(@"button %hu pressed - value is %d", buttonID, buttonState);
}
break;
}
break;
default:
// other messageTypes can happen and should be ignored
break;
}
}
static void
AddedDevice(io_connect_t connection) {
NSLog(@"added device %p", connection);
}
static void
RemovedDevice(io_connect_t connection) {
NSLog(@"removed device %p", connection);
}
- (void)awakeFromNib {
OSErr err = InstallConnexionHandlers(HandleMessage, AddedDevice, RemovedDevice);
if (err == noErr) {
UInt32 signature = kConnexionClientWildcard;
UInt16 mode = kConnexionClientModePlugin;
UInt32 mask = kConnexionMaskAll;
_myID = RegisterConnexionClient(signature, NULL, mode, mask);
NSLog(@"installed handlers for 3Dconnexion Space Navigator and registed client : %hi", _myID);
} else {
NSLog(@"problem installing handlers for 3Dconnexion Space Navigator : %d", err);
}
}
- (void)dealloc {
if (_myID) {
UnregisterConnexionClient(_myID);
CleanupConnexionHandlers();
}
[super dealloc];
}
@end