Revision: 38641
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38641
Author:   merwin
Date:     2011-07-23 21:29:19 +0000 (Sat, 23 Jul 2011)
Log Message:
-----------
more cautious device detection, minor cleanup

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_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-07-23 20:49:26 UTC (rev 38640)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp  
2011-07-23 21:29:19 UTC (rev 38641)
@@ -157,7 +157,7 @@
        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 @@
                                        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)

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h    
2011-07-23 20:49:26 UTC (rev 38640)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h    
2011-07-23 21:29:19 UTC (rev 38641)
@@ -95,7 +95,7 @@
 
        // 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

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp       
2011-07-23 20:49:26 UTC (rev 38640)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.cpp       
2011-07-23 21:29:19 UTC (rev 38641)
@@ -29,15 +29,14 @@
 
 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;
+               // determine exactly which device (if any) is plugged in
 
-               setDeadZone(0.1f); // how to calibrate on Linux? throw away 
slight motion!
-
-               // determine exactly which device is plugged in
-
                #define MAX_LINE_LENGTH 100
 
                // look for USB devices with Logitech's vendor ID
@@ -49,14 +48,17 @@
                                {
                                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 @@
        return m_available;
        }
 
+//bool GHOST_NDOFManagerX11::identifyDevice()
+//     {
+//     
+//     }
+
 bool GHOST_NDOFManagerX11::processEvents()
        {
        GHOST_TUns64 now = m_system.getMilliSeconds();
@@ -85,15 +92,7 @@
                        {
                        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};
 

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.h 
2011-07-23 20:49:26 UTC (rev 38640)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManagerX11.h 
2011-07-23 21:29:19 UTC (rev 38641)
@@ -38,6 +38,8 @@
        bool processEvents();
 
 private:
+//     bool identifyDevice();
+
        bool m_available;
        };
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to