[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37604] branches/merwin-spacenav/intern/ ghost/intern: finished Mac NDOF device detection, moved core device ID to base NDOFManager, clarified info/error messages

Mike Erwin significant.bit at gmail.com
Fri Jun 17 21:48:27 CEST 2011


Revision: 37604
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37604
Author:   merwin
Date:     2011-06-17 19:48:26 +0000 (Fri, 17 Jun 2011)
Log Message:
-----------
finished Mac NDOF device detection, moved core device ID to base NDOFManager, clarified info/error messages

Modified Paths:
--------------
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.h
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.h

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-06-17 18:41:43 UTC (rev 37603)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-06-17 19:48:26 UTC (rev 37604)
@@ -146,6 +146,24 @@
 	memset(m_rotation, 0, sizeof(m_rotation));
 	}
 
+void GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short product_id)
+	{
+	switch (vendor_id)
+		{
+		case 0x046d: // Logitech (3Dconnexion)
+			switch (product_id)
+				{
+				case 0xc626: m_deviceType = NDOF_SpaceNavigator; break;
+				case 0xc627: m_deviceType = NDOF_SpaceExplorer; break;
+				case 0xc629: m_deviceType = NDOF_SpacePilotPro; break;
+				default: printf("ndof: unknown Logitech product %04hx\n", product_id);
+				}
+			break;
+		default:
+			printf("ndof: unknown vendor %04hx\n", vendor_id);
+		}
+	}
+
 void GHOST_NDOFManager::updateTranslation(short t[3], GHOST_TUns64 time)
 	{
 	memcpy(m_translation, t, sizeof(m_translation));
@@ -192,7 +210,7 @@
 	GHOST_IWindow* window = m_system.getWindowManager()->getActiveWindow();
 
 	#ifdef DEBUG_NDOF_BUTTONS
-	printf("button %d -> ", button_number);
+	printf("ndof: button %d -> ", button_number);
 	#endif
 
 	switch (m_deviceType)
@@ -221,7 +239,7 @@
 				}
 			break;
 		case NDOF_UnknownDevice:
-			printf("button %d on unknown device (not sent)\n", button_number);
+			printf("ndof: button %d on unknown device (ignoring)\n", button_number);
 		}
 
 	int mask = 1 << button_number;
@@ -276,7 +294,7 @@
 	m_prevMotionTime = m_motionTime;
 
 	#ifdef DEBUG_NDOF_MOTION
-	printf("sending T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f\n",
+	printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f\n",
 		data->tx, data->ty, data->tz, data->rx, data->ry, data->rz, data->dt);
 	#endif
 

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h	2011-06-17 18:41:43 UTC (rev 37603)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h	2011-06-17 19:48:26 UTC (rev 37604)
@@ -88,22 +88,31 @@
 	// does not imply that a device is plugged in or being used
 	virtual bool available() = 0;
 
-	// the latest raw data from the device
+	// each platform's device detection should call this
+	// use standard USB/HID identifiers
+	void setDevice(unsigned short vendor_id, unsigned short product_id);
+
+	// the latest raw axis data from the device
 	void updateTranslation(short t[3], GHOST_TUns64 time);
 	void updateRotation(short r[3], GHOST_TUns64 time);
-	// send events immediately for changed buttons
+
+	// the latest raw button data from the device
+	// use HID button encoding (not NDOF_ButtonT)
 	void updateButton(int button_number, bool press, GHOST_TUns64 time);
 	void updateButtons(int button_bits, GHOST_TUns64 time);
+	// NDOFButton events are sent immediately
 
-	// processes most recent raw data into an NDOFMotion event and sends it
+	// processes and sends most recent raw data as an NDOFMotion event
 	// returns whether an event was sent
 	bool sendMotionEvent();
 
+protected:
+
 private:
 	void sendButtonEvent(NDOF_ButtonT, bool press, GHOST_TUns64 time, GHOST_IWindow*);
 	void sendKeyEvent(GHOST_TKey, bool press, GHOST_TUns64 time, GHOST_IWindow*);
 
-protected:
+
 	GHOST_System& m_system;
 
 	NDOF_DeviceT m_deviceType;

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.h	2011-06-17 18:41:43 UTC (rev 37603)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.h	2011-06-17 19:48:26 UTC (rev 37604)
@@ -26,7 +26,7 @@
 
 #include "GHOST_NDOFManager.h"
 
-// Event capture is handled within the NDOFManager on Macintosh,
+// Event capture is handled within the NDOF manager on Macintosh,
 // so there's no need for SystemCocoa to look for them.
 
 class GHOST_NDOFManagerCocoa : public GHOST_NDOFManager

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm	2011-06-17 18:41:43 UTC (rev 37603)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm	2011-06-17 19:48:26 UTC (rev 37604)
@@ -29,11 +29,15 @@
 	#include <stdio.h>
 	}
 
+// static functions need to talk to these objects:
+static GHOST_SystemCocoa* ghost_system = NULL;
+static GHOST_NDOFManager* ndof_manager = NULL;
+
 static void NDOF_DeviceAdded(io_connect_t connection)
 	{
-	printf("ndof device added\n"); // change these: printf --> informational reports
+	printf("ndof: device added\n"); // change these: printf --> informational reports
 
-	// determine exactly which device is plugged in
+#if 0 // device preferences will be useful soon, but not for hardware model detection
 	ConnexionDevicePrefs p;
 	ConnexionGetCurrentDevicePrefs(kDevID_AnyDevice, &p);
 	printf("device type %d: %s\n", p.deviceID,
@@ -41,72 +45,72 @@
 		p.deviceID == kDevID_SpaceNavigatorNB ? "SpaceNavigator for Notebooks" :
 		p.deviceID == kDevID_SpaceExplorer ? "SpaceExplorer" :
 		"unknown");
+#endif
 
-	// try a more "standard" way
+	// determine exactly which device is plugged in
 	int result = 0;
 	ConnexionControl(kConnexionCtlGetDeviceID, 0, &result);
 	unsigned short vendorID = result >> 16;
 	unsigned short productID = result & 0xffff;
-	printf("vendor %04hx:%04hx product\n", vendorID, productID);
+
+	ndof_manager->setDevice(vendorID, productID);
 	}
 
 static void NDOF_DeviceRemoved(io_connect_t connection)
 	{
-	printf("ndof device removed\n");
+	printf("ndof: device removed\n");
 	}
 
 static void NDOF_DeviceEvent(io_connect_t connection, natural_t messageType, void* messageArgument)
 	{
-	GHOST_SystemCocoa* system = (GHOST_SystemCocoa*) GHOST_ISystem::getSystem();
-	GHOST_NDOFManager* manager = system->getNDOFManager();
 	switch (messageType)
 		{
 		case kConnexionMsgDeviceState:
 			{
 			ConnexionDeviceState* s = (ConnexionDeviceState*)messageArgument;
 
-			GHOST_TUns64 now = system->getMilliSeconds();
+			GHOST_TUns64 now = ghost_system->getMilliSeconds();
 
 			switch (s->command)
 				{
 				case kConnexionCmdHandleAxis:
-					manager->updateTranslation(s->axis, now);
-					manager->updateRotation(s->axis + 3, now);
-					system->notifyExternalEventProcessed();
+					ndof_manager->updateTranslation(s->axis, now);
+					ndof_manager->updateRotation(s->axis + 3, now);
+					ghost_system->notifyExternalEventProcessed();
 					break;
 
 				case kConnexionCmdHandleButtons:
 
 					// s->buttons field has only 16 bits, not enough for SpacePilotPro
 					// look at raw USB report for more button bits
-					printf("button bits = [");
+					printf("ndof: button bits = [");
 					for (int i = 0; i < 8; ++i)
 						printf("%02x", s->report[i]);
 					printf("]\n");
 
-					manager->updateButtons(s->buttons, now);
-					system->notifyExternalEventProcessed();
+					ndof_manager->updateButtons(s->buttons, now);
+					ghost_system->notifyExternalEventProcessed();
 					break;
 
 				case kConnexionCmdAppSpecific:
-					printf("app-specific command: param=%hd value=%d\n", s->param, s->value);
+					printf("ndof: app-specific command, param = %hd, value = %d\n", s->param, s->value);
 					break;
 
 				default:
-					printf("<!> mystery command %d\n", s->command);
+					printf("ndof: mystery device command %d\n", s->command);
 				}
 			break;
 			}
 		case kConnexionMsgPrefsChanged:
-			printf("prefs changed\n"); // this includes app switches
+			printf("ndof: prefs changed\n"); // this includes app switches
 			break;
 		case kConnexionMsgDoAction:
-			printf("do action\n"); // no idea what this means
+			printf("ndof: do action\n"); // no idea what this means
 			// 'calibrate device' in System Prefs sends this
 			// 3Dx header file says to ignore these
 			break;
 		default:
-			printf("<!> mystery event\n");
+			printf("ndof: mystery event %d\n", messageType);
 		}
 	}
 
@@ -115,10 +119,14 @@
 	{
 	if (available())
 		{
+		// give static functions something to talk to:
+		ghost_system = dynamic_cast<GHOST_SystemCocoa*>(&sys);
+		ndof_manager = this;
+
 		OSErr error = InstallConnexionHandlers(NDOF_DeviceEvent, NDOF_DeviceAdded, NDOF_DeviceRemoved);
 		if (error)
 			{
-			printf("<!> error = %d\n", error);
+			printf("ndof: error %d while installing handlers\n", error);
 			return;
 			}
 
@@ -126,12 +134,12 @@
 		m_clientID = RegisterConnexionClient('blnd', (UInt8*) "\pblender",
 			kConnexionClientModeTakeOver, kConnexionMaskAll);
 
-		printf("client id = %d\n", m_clientID);
+		printf("ndof: client id = %d\n", m_clientID);
 		}
 	else
 		{
-		printf("<!> SpaceNav driver not found\n");
-		// This isn't a hard error, just means the user doesn't have a SpaceNavigator.
+		printf("ndof: 3Dx driver not found\n");
+		// This isn't a hard error, just means the user doesn't have a 3D mouse.
 		}
 	}
 
@@ -139,6 +147,8 @@
 	{
 	UnregisterConnexionClient(m_clientID);
 	CleanupConnexionHandlers();
+	ghost_system = NULL;
+	ndof_manager = NULL;
 	}
 
 bool GHOST_NDOFManagerCocoa::available()

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp	2011-06-17 18:41:43 UTC (rev 37603)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp	2011-06-17 19:48:26 UTC (rev 37604)
@@ -47,26 +47,16 @@
 				{
 				unsigned short vendor_id = 0, product_id = 0;
 				if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2)
-					{
-					// the following code will live in the base class
-					// once all platforms have device detection
-					switch (product_id)
-						{
-						case 0xc626: m_deviceType = NDOF_SpaceNavigator; break;
-						case 0xc627: m_deviceType = NDOF_SpaceExplorer; break;
-						case 0xc629: m_deviceType = NDOF_SpacePilotPro; break;
-						default: printf("unknown product ID: %04x\n", product_id);
-						}
-					}
+					setDevice(vendor_id, product_id);
 				}
 			pclose(command_output);
 			}
 		}
 	else
 		{
-		printf("<!> SpaceNav driver not found\n");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list