more cautious device detection, minor cleanup
authorMike Erwin <significant.bit@gmail.com>
Sat, 23 Jul 2011 21:29:19 +0000 (21:29 +0000)
committerMike Erwin <significant.bit@gmail.com>
Sat, 23 Jul 2011 21:29:19 +0000 (21:29 +0000)
intern/ghost/intern/GHOST_NDOFManager.cpp
intern/ghost/intern/GHOST_NDOFManager.h
intern/ghost/intern/GHOST_NDOFManagerX11.cpp
intern/ghost/intern/GHOST_NDOFManagerX11.h

index 06c792128cd8accf4f22b4eecc06d433b73e7c75..69100fefd31945ef6b038a787f51080f4c903506 100644 (file)
@@ -157,7 +157,7 @@ GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System& sys)
        memset(m_rotation, 0, sizeof(m_rotation));
        }
 
-void GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short product_id)
+bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short product_id)
        {
        switch (vendor_id)
                {
@@ -198,18 +198,26 @@ void GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ
                                        m_buttonCount = 21;
                                        break;
 
-                               default: printf("ndof: unknown Logitech product %04hx\n", product_id);
+                               default:
+                                       printf("ndof: unknown Logitech product %04hx\n", product_id);
                                }
                        break;
                default:
                        printf("ndof: unknown device %04hx:%04hx\n", vendor_id, product_id);
                }
 
-       m_buttonMask = ~(-1 << m_buttonCount);
+       if (m_deviceType == NDOF_UnknownDevice)
+               return false;
+       else
+               {
+               m_buttonMask = ~(-1 << m_buttonCount);
 
-       #ifdef DEBUG_NDOF_BUTTONS
-       printf("ndof: %d buttons -> hex:%X\n", m_buttonCount, m_buttonMask);
-       #endif
+               #ifdef DEBUG_NDOF_BUTTONS
+               printf("ndof: %d buttons -> hex:%X\n", m_buttonCount, m_buttonMask);
+               #endif
+
+               return true;
+               }
        }
 
 void GHOST_NDOFManager::updateTranslation(short t[3], GHOST_TUns64 time)
index 9c67daa44125d116938f17b10235a1cb9daa8fa7..d259967daa91638912db5c7444681b1aebcaf195 100644 (file)
@@ -95,7 +95,7 @@ public:
 
        // each platform's device detection should call this
        // use standard USB/HID identifiers
-       void setDevice(unsigned short vendor_id, unsigned short product_id);
+       bool setDevice(unsigned short vendor_id, unsigned short product_id);
 
        // filter out small/accidental/uncalibrated motions by
        // setting up a "dead zone" around home position
index a823c3c8a81e943d27e515d2e6fe96ff2141596f..233a9b367f14a8f1099cf6d0f6af7683be5fe702 100644 (file)
 
 GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys)
        : GHOST_NDOFManager(sys)
+       , m_available(false)
        {
+       setDeadZone(0.1f); // how to calibrate on Linux? throw away slight motion!
+
        if (spnav_open() != -1)
                {
-               m_available = true;
-
-               setDeadZone(0.1f); // how to calibrate on Linux? throw away slight motion!
-
-               // determine exactly which device is plugged in
+               // determine exactly which device (if any) is plugged in
 
                #define MAX_LINE_LENGTH 100
 
@@ -49,14 +48,17 @@ GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys)
                                {
                                unsigned short vendor_id = 0, product_id = 0;
                                if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2)
-                                       setDevice(vendor_id, product_id);
+                                       if (setDevice(vendor_id, product_id))
+                                               {
+                                               m_available = true;
+                                               break; // stop looking once the first 3D mouse is found
+                                               }
                                }
                        pclose(command_output);
                        }
                }
        else
                {
-               m_available = false;
                printf("ndof: spacenavd not found\n");
                // This isn't a hard error, just means the user doesn't have a 3D mouse.
                }
@@ -73,6 +75,11 @@ bool GHOST_NDOFManagerX11::available()
        return m_available;
        }
 
+//bool GHOST_NDOFManagerX11::identifyDevice()
+//     {
+//     
+//     }
+
 bool GHOST_NDOFManagerX11::processEvents()
        {
        GHOST_TUns64 now = m_system.getMilliSeconds();
@@ -85,15 +92,7 @@ bool GHOST_NDOFManagerX11::processEvents()
                        {
                        case SPNAV_EVENT_MOTION:
                                {
-// "natural" device coords
-//                             short t[3] = {e.motion.x, e.motion.y, e.motion.z};
-//                             short r[3] = {e.motion.rx, e.motion.ry, e.motion.rz};
-
-// blender world coords
-//                             short t[3] = {e.motion.x, e.motion.z, e.motion.y};
-//                             short r[3] = {-e.motion.rx, -e.motion.rz, -e.motion.ry};
-
-// blender view coords
+                               // convert to blender view coords
                                short t[3] = {e.motion.x, e.motion.y, -e.motion.z};
                                short r[3] = {-e.motion.rx, -e.motion.ry, e.motion.rz};
 
index def311d51e2ce19ca0f5ca8461783bd995478ca0..5e1c9d91074803f44084892f6351756a263e103c 100644 (file)
@@ -38,6 +38,8 @@ public:
        bool processEvents();
 
 private:
+//     bool identifyDevice();
+
        bool m_available;
        };