[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37525] branches/merwin-spacenav/intern/ ghost/intern: cleaned up event logging, added HID -> function table for SpacePilot PRO

Mike Erwin significant.bit at gmail.com
Wed Jun 15 22:56:42 CEST 2011


Revision: 37525
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37525
Author:   merwin
Date:     2011-06-15 20:56:42 +0000 (Wed, 15 Jun 2011)
Log Message:
-----------
cleaned up event logging, added HID -> function table for SpacePilot PRO

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_SystemWin32.cpp

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-06-15 19:57:10 UTC (rev 37524)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-06-15 20:56:42 UTC (rev 37525)
@@ -28,8 +28,7 @@
 #include <string.h> // for memory functions
 #include <stdio.h> // for debug tracing
 
-
-
+#ifdef DEBUG_NDOF_BUTTONS
 static const char* ndof_button_names[] = {
 	// used internally, never sent
 	"NDOF_BUTTON_NONE",
@@ -71,14 +70,15 @@
 	"NDOF_BUTTON_9",
 	"NDOF_BUTTON_10",
 	};
+#endif
 
-static const NDOF_ButtonT SpaceNavigator_HID_map[2] =
+static const NDOF_ButtonT SpaceNavigator_HID_map[] =
 	{
 	NDOF_BUTTON_MENU,
 	NDOF_BUTTON_FIT
 	};
 
-static const NDOF_ButtonT SpaceExplorer_HID_map[16] =
+static const NDOF_ButtonT SpaceExplorer_HID_map[] =
 	{
 	NDOF_BUTTON_1,
 	NDOF_BUTTON_2,
@@ -97,9 +97,44 @@
 	NDOF_BUTTON_ROTATE
 	};
 
+static const NDOF_ButtonT SpacePilot_HID_map[] =
+	{
+	NDOF_BUTTON_MENU,
+	NDOF_BUTTON_FIT,
+	NDOF_BUTTON_TOP,
+	NDOF_BUTTON_LEFT,
+	NDOF_BUTTON_RIGHT,
+	NDOF_BUTTON_FRONT,
+	NDOF_BUTTON_BOTTOM,
+	NDOF_BUTTON_BACK,
+	NDOF_BUTTON_ROLL_CW,
+	NDOF_BUTTON_ROLL_CCW,
+	NDOF_BUTTON_ISO1,
+	NDOF_BUTTON_ISO2,
+	NDOF_BUTTON_1,
+	NDOF_BUTTON_2,
+	NDOF_BUTTON_3,
+	NDOF_BUTTON_4,
+	NDOF_BUTTON_5,
+	NDOF_BUTTON_6,
+	NDOF_BUTTON_7,
+	NDOF_BUTTON_8,
+	NDOF_BUTTON_9,
+	NDOF_BUTTON_10,
+	NDOF_BUTTON_NONE, // esc key
+	NDOF_BUTTON_NONE, // alt key
+	NDOF_BUTTON_NONE, // shift key
+	NDOF_BUTTON_NONE, // ctrl key
+	NDOF_BUTTON_ROTATE,
+	NDOF_BUTTON_PANZOOM,
+	NDOF_BUTTON_DOMINANT,
+	NDOF_BUTTON_PLUS,
+	NDOF_BUTTON_MINUS
+	};
+
 GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System& sys)
 	: m_system(sys)
-	, m_deviceType(SpaceExplorer) // set it manually, until device detection code is in place
+	, m_deviceType(SpacePilot) // set it manually, until device detection code is in place
 	, m_buttons(0)
 	, m_motionTime(1000) // one full second (operators should filter out such large time deltas)
 	, m_prevMotionTime(0)
@@ -133,7 +168,9 @@
 	data->action = press ? GHOST_kPress : GHOST_kRelease;
 	data->button = button;
 
-	printf("sending %s %s\n", ndof_button_names[button], press ? "pressed" : "released");
+	#ifdef DEBUG_NDOF_BUTTONS
+	printf("%s %s\n", ndof_button_names[button], press ? "pressed" : "released");
+	#endif
 
 	m_system.pushEvent(event);
 	}
@@ -143,6 +180,10 @@
 	GHOST_TEventType type = press ? GHOST_kEventKeyDown : GHOST_kEventKeyUp;
 	GHOST_EventKey* event = new GHOST_EventKey(time, type, window, key);
 
+	#ifdef DEBUG_NDOF_BUTTONS
+	printf("keyboard %s\n", press ? "down" : "up");
+	#endif
+
 	m_system.pushEvent(event);
 	}
 
@@ -150,6 +191,10 @@
 	{
 	GHOST_IWindow* window = m_system.getWindowManager()->getActiveWindow();
 
+	#ifdef DEBUG_NDOF_BUTTONS
+	printf("button %d -> ", button_number);
+	#endif
+
 	switch (m_deviceType)
 		{
 		case SpaceNavigator:
@@ -158,25 +203,22 @@
 		case SpaceExplorer:
 			switch (button_number)
 				{
-				case 6:
-					sendKeyEvent(GHOST_kKeyEsc, press, time, window);
-					break;
-				case 7:
-					sendKeyEvent(GHOST_kKeyLeftAlt, press, time, window);
-					break;
-				case 8:
-					sendKeyEvent(GHOST_kKeyLeftShift, press, time, window);
-					break;
-				case 9:
-					sendKeyEvent(GHOST_kKeyLeftControl, press, time, window);
-					break;
-				default:
-					sendButtonEvent(SpaceExplorer_HID_map[button_number], press, time, window);
+				case 6: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break;
+				case 7: sendKeyEvent(GHOST_kKeyLeftAlt, press, time, window); break;
+				case 8: sendKeyEvent(GHOST_kKeyLeftShift, press, time, window); break;
+				case 9: sendKeyEvent(GHOST_kKeyLeftControl, press, time, window); break;
+				default: sendButtonEvent(SpaceExplorer_HID_map[button_number], press, time, window);
 				}
 			break;
 		case SpacePilot:
-			printf("button %d %s\n", button_number, press ? "pressed" : "released");
-			// sendButtonEvent(SpacePilot_HID_map[button_number], press, time, window);
+			switch (button_number)
+				{
+				case 22: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break;
+				case 23: sendKeyEvent(GHOST_kKeyLeftAlt, press, time, window); break;
+				case 24: sendKeyEvent(GHOST_kKeyLeftShift, press, time, window); break;
+				case 25: sendKeyEvent(GHOST_kKeyLeftControl, press, time, window); break;
+				default: sendButtonEvent(SpacePilot_HID_map[button_number], press, time, window);
+				}
 			break;
 		}
 
@@ -231,8 +273,10 @@
 
 	m_prevMotionTime = m_motionTime;
 
+	#ifdef DEBUG_NDOF_MOTION
 	printf("sending 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
 
 	m_system.pushEvent(event);
 

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h	2011-06-15 19:57:10 UTC (rev 37524)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h	2011-06-15 20:56:42 UTC (rev 37525)
@@ -29,6 +29,9 @@
 
 // --- the following type definitions will find a home somewhere else once finished ---
 
+// #define DEBUG_NDOF_MOTION
+#define DEBUG_NDOF_BUTTONS
+
 typedef enum { SpaceNavigator, SpaceExplorer, SpacePilot } NDOF_DeviceT;
 
 // NDOF device button event types

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemWin32.cpp	2011-06-15 19:57:10 UTC (rev 37524)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemWin32.cpp	2011-06-15 20:56:42 UTC (rev 37525)
@@ -841,40 +841,24 @@
 			{
 			short t[3];
 			memcpy(t, data + 1, sizeof(t));
-			// too much noise -- disable for now
-			printf("T: %+5d %+5d %+5d\n", t[0], t[1], t[2]);
 			m_ndofManager->updateTranslation(t, getMilliSeconds());
 			// wariness of alignment issues prevents me from saying it this way:
 			// m_ndofManager->updateTranslation((short*)(data + 1), getMilliSeconds());
-			// though it probably (94.7%) works fine
+			// though it probably (94.7%) would work fine
 			break;
 			}
 		case 2: // rotation
 			{
 			short r[3];
 			memcpy(r, data + 1, sizeof(r));
-			printf("R: %+5d %+5d %+5d\n", r[0], r[1], r[2]);
 			m_ndofManager->updateRotation(r, getMilliSeconds());
 			break;
 			}
 		case 3: // buttons
 			{
-			unsigned buttons;
-			memcpy(&buttons, data + 1, sizeof(buttons));
-
-//			printf("buttons:");
-//			if (buttons)
-//				{
-//				// work our way through the bit mask
-//				for (int i = 0; i < 16; ++i)
-//					if (buttons & (1 << i))
-//						printf(" %d", i + 1);
-//				printf("\n");
-//				}
-//			else
-//				printf(" none\n");
-
-			m_ndofManager->updateButtons(buttons, getMilliSeconds());
+			int button_bits;
+			memcpy(&button_bits, data + 1, sizeof(button_bits));
+			m_ndofManager->updateButtons(button_bits, getMilliSeconds());
 			break;
 			}
 		}




More information about the Bf-blender-cvs mailing list