cleaned up event logging, added HID -> function table for SpacePilot PRO
authorMike Erwin <significant.bit@gmail.com>
Wed, 15 Jun 2011 20:56:42 +0000 (20:56 +0000)
committerMike Erwin <significant.bit@gmail.com>
Wed, 15 Jun 2011 20:56:42 +0000 (20:56 +0000)
intern/ghost/intern/GHOST_NDOFManager.cpp
intern/ghost/intern/GHOST_NDOFManager.h
intern/ghost/intern/GHOST_SystemWin32.cpp

index 78760cedd54011b311c7e83f6bbdce8822364e5d..20baa6f725e138e8c35eab1e8a91d1066c3da637 100644 (file)
@@ -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 @@ static const char* ndof_button_names[] = {
        "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 @@ static const NDOF_ButtonT SpaceExplorer_HID_map[16] =
        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 @@ void GHOST_NDOFManager::sendButtonEvent(NDOF_ButtonT button, bool press, GHOST_T
        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 @@ void GHOST_NDOFManager::sendKeyEvent(GHOST_TKey key, bool press, GHOST_TUns64 ti
        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 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64
        {
        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 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64
                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 @@ bool GHOST_NDOFManager::sendMotionEvent()
 
        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);
 
index eb04ca654eea19456b5550c59814a9889bb5fa45..ab27fc32f84e9e0a13e06dc880d9de7fb5af46f0 100644 (file)
@@ -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
index 69ced6834355da739f4db2b3c2ab5841787eb3ad..4548d6b34ebef818a22b0e2dce7b5b5fe648fa2a 100644 (file)
@@ -841,40 +841,24 @@ bool GHOST_SystemWin32::processNDOF(/*GHOST_WindowWin32* window,*/ RAWINPUT cons
                        {
                        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;
                        }
                }