From 5fae765187b98b6a35c9f674e61bd1a26d09b0c0 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Sat, 23 Jul 2011 21:29:19 +0000 Subject: [PATCH] more cautious device detection, minor cleanup --- intern/ghost/intern/GHOST_NDOFManager.cpp | 20 +++++++++---- intern/ghost/intern/GHOST_NDOFManager.h | 2 +- intern/ghost/intern/GHOST_NDOFManagerX11.cpp | 31 ++++++++++---------- intern/ghost/intern/GHOST_NDOFManagerX11.h | 2 ++ 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp index 06c792128cd..69100fefd31 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.cpp +++ b/intern/ghost/intern/GHOST_NDOFManager.cpp @@ -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) diff --git a/intern/ghost/intern/GHOST_NDOFManager.h b/intern/ghost/intern/GHOST_NDOFManager.h index 9c67daa4412..d259967daa9 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.h +++ b/intern/ghost/intern/GHOST_NDOFManager.h @@ -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 diff --git a/intern/ghost/intern/GHOST_NDOFManagerX11.cpp b/intern/ghost/intern/GHOST_NDOFManagerX11.cpp index a823c3c8a81..233a9b367f1 100644 --- a/intern/ghost/intern/GHOST_NDOFManagerX11.cpp +++ b/intern/ghost/intern/GHOST_NDOFManagerX11.cpp @@ -29,14 +29,13 @@ 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}; diff --git a/intern/ghost/intern/GHOST_NDOFManagerX11.h b/intern/ghost/intern/GHOST_NDOFManagerX11.h index def311d51e2..5e1c9d91074 100644 --- a/intern/ghost/intern/GHOST_NDOFManagerX11.h +++ b/intern/ghost/intern/GHOST_NDOFManagerX11.h @@ -38,6 +38,8 @@ public: bool processEvents(); private: +// bool identifyDevice(); + bool m_available; };