forked from bartvdbraak/blender
more cautious device detection, minor cleanup
This commit is contained in:
parent
8c5f028f4a
commit
5fae765187
@ -157,7 +157,7 @@ GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System& sys)
|
|||||||
memset(m_rotation, 0, sizeof(m_rotation));
|
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)
|
switch (vendor_id)
|
||||||
{
|
{
|
||||||
@ -198,18 +198,26 @@ void GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ
|
|||||||
m_buttonCount = 21;
|
m_buttonCount = 21;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: printf("ndof: unknown Logitech product %04hx\n", product_id);
|
default:
|
||||||
|
printf("ndof: unknown Logitech product %04hx\n", product_id);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("ndof: unknown device %04hx:%04hx\n", vendor_id, product_id);
|
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
|
#ifdef DEBUG_NDOF_BUTTONS
|
||||||
printf("ndof: %d buttons -> hex:%X\n", m_buttonCount, m_buttonMask);
|
printf("ndof: %d buttons -> hex:%X\n", m_buttonCount, m_buttonMask);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GHOST_NDOFManager::updateTranslation(short t[3], GHOST_TUns64 time)
|
void GHOST_NDOFManager::updateTranslation(short t[3], GHOST_TUns64 time)
|
||||||
|
@ -95,7 +95,7 @@ public:
|
|||||||
|
|
||||||
// each platform's device detection should call this
|
// each platform's device detection should call this
|
||||||
// use standard USB/HID identifiers
|
// 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
|
// filter out small/accidental/uncalibrated motions by
|
||||||
// setting up a "dead zone" around home position
|
// setting up a "dead zone" around home position
|
||||||
|
@ -29,14 +29,13 @@
|
|||||||
|
|
||||||
GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys)
|
GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys)
|
||||||
: GHOST_NDOFManager(sys)
|
: GHOST_NDOFManager(sys)
|
||||||
|
, m_available(false)
|
||||||
{
|
{
|
||||||
|
setDeadZone(0.1f); // how to calibrate on Linux? throw away slight motion!
|
||||||
|
|
||||||
if (spnav_open() != -1)
|
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
|
#define MAX_LINE_LENGTH 100
|
||||||
|
|
||||||
@ -49,14 +48,17 @@ GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys)
|
|||||||
{
|
{
|
||||||
unsigned short vendor_id = 0, product_id = 0;
|
unsigned short vendor_id = 0, product_id = 0;
|
||||||
if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2)
|
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);
|
pclose(command_output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_available = false;
|
|
||||||
printf("ndof: spacenavd not found\n");
|
printf("ndof: spacenavd not found\n");
|
||||||
// This isn't a hard error, just means the user doesn't have a 3D mouse.
|
// 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;
|
return m_available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//bool GHOST_NDOFManagerX11::identifyDevice()
|
||||||
|
// {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
bool GHOST_NDOFManagerX11::processEvents()
|
bool GHOST_NDOFManagerX11::processEvents()
|
||||||
{
|
{
|
||||||
GHOST_TUns64 now = m_system.getMilliSeconds();
|
GHOST_TUns64 now = m_system.getMilliSeconds();
|
||||||
@ -85,15 +92,7 @@ bool GHOST_NDOFManagerX11::processEvents()
|
|||||||
{
|
{
|
||||||
case SPNAV_EVENT_MOTION:
|
case SPNAV_EVENT_MOTION:
|
||||||
{
|
{
|
||||||
// "natural" device 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};
|
|
||||||
|
|
||||||
// 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
|
|
||||||
short t[3] = {e.motion.x, e.motion.y, -e.motion.z};
|
short t[3] = {e.motion.x, e.motion.y, -e.motion.z};
|
||||||
short r[3] = {-e.motion.rx, -e.motion.ry, e.motion.rz};
|
short r[3] = {-e.motion.rx, -e.motion.ry, e.motion.rz};
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ public:
|
|||||||
bool processEvents();
|
bool processEvents();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// bool identifyDevice();
|
||||||
|
|
||||||
bool m_available;
|
bool m_available;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user