diff options
Diffstat (limited to 'intern/ghost/intern/GHOST_NDOFManager.cpp')
-rw-r--r-- | intern/ghost/intern/GHOST_NDOFManager.cpp | 126 |
1 files changed, 64 insertions, 62 deletions
diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp index 079ad67f737..0317c175273 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.cpp +++ b/intern/ghost/intern/GHOST_NDOFManager.cpp @@ -22,51 +22,51 @@ #include <limits.h> #include <math.h> -#include <stdio.h> // for error/info reporting -#include <string.h> // for memory functions +#include <stdio.h> /* For error/info reporting. */ +#include <string.h> /* For memory functions. */ #ifdef DEBUG_NDOF_MOTION -// printable version of each GHOST_TProgress value +/* Printable version of each GHOST_TProgress value. */ static const char *progress_string[] = { "not started", "starting", "in progress", "finishing", "finished"}; #endif #ifdef DEBUG_NDOF_BUTTONS static const char *ndof_button_names[] = { - // used internally, never sent + /* used internally, never sent */ "NDOF_BUTTON_NONE", - // these two are available from any 3Dconnexion device + /* these two are available from any 3Dconnexion device */ "NDOF_BUTTON_MENU", "NDOF_BUTTON_FIT", - // standard views + /* standard views */ "NDOF_BUTTON_TOP", "NDOF_BUTTON_BOTTOM", "NDOF_BUTTON_LEFT", "NDOF_BUTTON_RIGHT", "NDOF_BUTTON_FRONT", "NDOF_BUTTON_BACK", - // more views + /* more views */ "NDOF_BUTTON_ISO1", "NDOF_BUTTON_ISO2", - // 90 degree rotations + /* 90 degree rotations */ "NDOF_BUTTON_ROLL_CW", "NDOF_BUTTON_ROLL_CCW", "NDOF_BUTTON_SPIN_CW", "NDOF_BUTTON_SPIN_CCW", "NDOF_BUTTON_TILT_CW", "NDOF_BUTTON_TILT_CCW", - // device control + /* device control */ "NDOF_BUTTON_ROTATE", "NDOF_BUTTON_PANZOOM", "NDOF_BUTTON_DOMINANT", "NDOF_BUTTON_PLUS", "NDOF_BUTTON_MINUS", - // keyboard emulation + /* keyboard emulation */ "NDOF_BUTTON_ESC", "NDOF_BUTTON_ALT", "NDOF_BUTTON_SHIFT", "NDOF_BUTTON_CTRL", - // general-purpose buttons + /* general-purpose buttons */ "NDOF_BUTTON_1", "NDOF_BUTTON_2", "NDOF_BUTTON_3", @@ -77,17 +77,17 @@ static const char *ndof_button_names[] = { "NDOF_BUTTON_8", "NDOF_BUTTON_9", "NDOF_BUTTON_10", - // more general-purpose buttons + /* more general-purpose buttons */ "NDOF_BUTTON_A", "NDOF_BUTTON_B", "NDOF_BUTTON_C", - // the end + /* the end */ "NDOF_BUTTON_LAST"}; #endif -// shared by the latest 3Dconnexion hardware -// SpacePilotPro uses all of these -// smaller devices use only some, based on button mask +/* Shared by the latest 3Dconnexion hardware + * SpacePilotPro uses all of these + * smaller devices use only some, based on button mask. */ static const NDOF_ButtonT Modern3Dx_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, @@ -116,15 +116,15 @@ static const NDOF_ButtonT SpaceExplorer_HID_map[] = { NDOF_BUTTON_ROTATE, }; -// this is the older SpacePilot (sans Pro) -// thanks to polosson for info about this device +/* This is the older SpacePilot (sans Pro) + * thanks to polosson for info about this device. */ static const NDOF_ButtonT SpacePilot_HID_map[] = { NDOF_BUTTON_1, NDOF_BUTTON_2, NDOF_BUTTON_3, NDOF_BUTTON_4, NDOF_BUTTON_5, NDOF_BUTTON_6, NDOF_BUTTON_TOP, NDOF_BUTTON_LEFT, NDOF_BUTTON_RIGHT, NDOF_BUTTON_FRONT, NDOF_BUTTON_ESC, NDOF_BUTTON_ALT, NDOF_BUTTON_SHIFT, NDOF_BUTTON_CTRL, NDOF_BUTTON_FIT, NDOF_BUTTON_MENU, NDOF_BUTTON_PLUS, NDOF_BUTTON_MINUS, NDOF_BUTTON_DOMINANT, NDOF_BUTTON_ROTATE, - NDOF_BUTTON_NONE // the CONFIG button -- what does it do? + NDOF_BUTTON_NONE /* the CONFIG button -- what does it do? */ }; static const NDOF_ButtonT Generic_HID_map[] = { @@ -146,7 +146,7 @@ static const int genericButtonCount = sizeof(Generic_HID_map) / sizeof(NDOF_Butt GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System &sys) : m_system(sys), - m_deviceType(NDOF_UnknownDevice), // each platform has its own device detection code + m_deviceType(NDOF_UnknownDevice), /* Each platform has its own device detection code. */ m_buttonCount(genericButtonCount), m_buttonMask(0), m_hidMap(Generic_HID_map), @@ -157,37 +157,37 @@ GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System &sys) m_motionEventPending(false), m_deadZone(0.0f) { - // to avoid the rare situation where one triple is updated and - // the other is not, initialize them both here: + /* To avoid the rare situation where one triple is updated and + * the other is not, initialize them both here: */ memset(m_translation, 0, sizeof(m_translation)); memset(m_rotation, 0, sizeof(m_rotation)); } bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short product_id) { - // call this function until it returns true - // it's a good idea to stop calling it after that, as it will "forget" - // whichever device it already found + /* Call this function until it returns true + * it's a good idea to stop calling it after that, as it will "forget" + * whichever device it already found */ - // default to safe generic behavior for "unknown" devices - // unidentified devices will emit motion events like normal - // rogue buttons do nothing by default, but can be customized by the user + /* Default to safe generic behavior for "unknown" devices + * unidentified devices will emit motion events like normal + * rogue buttons do nothing by default, but can be customized by the user. */ m_deviceType = NDOF_UnknownDevice; m_hidMap = Generic_HID_map; m_buttonCount = genericButtonCount; m_buttonMask = 0; - // "mystery device" owners can help build a HID_map for their hardware - // A few users have already contributed information about several older devices - // that I don't have access to. Thanks! + /* "mystery device" owners can help build a HID_map for their hardware + * A few users have already contributed information about several older devices + * that I don't have access to. Thanks! */ switch (vendor_id) { - case 0x046D: // Logitech (3Dconnexion was a subsidiary) + case 0x046D: /* Logitech (3Dconnexion was a subsidiary). */ switch (product_id) { - // -- current devices -- - case 0xC626: // full-size SpaceNavigator - case 0xC628: // the "for Notebooks" one + /* -- current devices -- */ + case 0xC626: /* full-size SpaceNavigator */ + case 0xC628: /* the "for Notebooks" one */ puts("ndof: using SpaceNavigator"); m_deviceType = NDOF_SpaceNavigator; m_buttonCount = 2; @@ -209,12 +209,12 @@ bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ puts("ndof: using SpaceMouse Pro"); m_deviceType = NDOF_SpaceMousePro; m_buttonCount = 27; - // ^^ actually has 15 buttons, but their HID codes range from 0 to 26 + /* ^^ actually has 15 buttons, but their HID codes range from 0 to 26 */ m_buttonMask = 0x07C0F137; m_hidMap = Modern3Dx_HID_map; break; - // -- older devices -- + /* -- older devices -- */ case 0xC625: puts("ndof: using SpacePilot"); m_deviceType = NDOF_SpacePilot; @@ -236,21 +236,21 @@ bool GHOST_NDOFManager::setDevice(unsigned short vendor_id, unsigned short produ printf("ndof: unknown Logitech product %04hx\n", product_id); } break; - case 0x256F: // 3Dconnexion + case 0x256F: /* 3Dconnexion */ switch (product_id) { - case 0xC62E: // plugged in - case 0xC62F: // wireless + case 0xC62E: /* Plugged in. */ + case 0xC62F: /* Wireless. */ puts("ndof: using SpaceMouse Wireless"); m_deviceType = NDOF_SpaceMouseWireless; m_buttonCount = 2; m_hidMap = Modern3Dx_HID_map; break; - case 0xC631: // plugged in - case 0xC632: // wireless + case 0xC631: /* Plugged in. */ + case 0xC632: /* Wireless. */ puts("ndof: using SpaceMouse Pro Wireless"); m_deviceType = NDOF_SpaceMouseProWireless; m_buttonCount = 27; - // ^^ actually has 15 buttons, but their HID codes range from 0 to 26 + /* ^^ actually has 15 buttons, but their HID codes range from 0 to 26. */ m_buttonMask = 0x07C0F137; m_hidMap = Modern3Dx_HID_map; break; @@ -364,16 +364,16 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, uint64_t tim int mask = 1 << button_number; if (press) { - m_buttons |= mask; // set this button's bit + m_buttons |= mask; /* Set this button's bit. */ } else { - m_buttons &= ~mask; // clear this button's bit + m_buttons &= ~mask; /* Clear this button's bit. */ } } void GHOST_NDOFManager::updateButtons(int button_bits, uint64_t time) { - button_bits &= m_buttonMask; // discard any "garbage" bits + button_bits &= m_buttonMask; /* Discard any "garbage" bits. */ int diff = m_buttons ^ button_bits; @@ -390,11 +390,11 @@ void GHOST_NDOFManager::updateButtons(int button_bits, uint64_t time) void GHOST_NDOFManager::setDeadZone(float dz) { if (dz < 0.0f) { - // negative values don't make sense, so clamp at zero + /* Negative values don't make sense, so clamp at zero. */ dz = 0.0f; } else if (dz > 0.5f) { - // warn the rogue user/developer, but allow it + /* Warn the rogue user/developer, but allow it. */ GHOST_PRINTF("ndof: dead zone of %.2f is rather high...\n", dz); } m_deadZone = dz; @@ -426,22 +426,22 @@ bool GHOST_NDOFManager::sendMotionEvent() if (!m_motionEventPending) return false; - m_motionEventPending = false; // any pending motion is handled right now + m_motionEventPending = false; /* Any pending motion is handled right now. */ GHOST_IWindow *window = m_system.getWindowManager()->getActiveWindow(); if (window == NULL) { - m_motionState = GHOST_kNotStarted; // avoid large 'dt' times when changing windows - return false; // delivery will fail, so don't bother sending + m_motionState = GHOST_kNotStarted; /* Avoid large `dt` times when changing windows. */ + return false; /* Delivery will fail, so don't bother sending. */ } GHOST_EventNDOFMotion *event = new GHOST_EventNDOFMotion(m_motionTime, window); GHOST_TEventNDOFMotionData *data = (GHOST_TEventNDOFMotionData *)event->getData(); - // scale axis values here to normalize them to around +/- 1 - // they are scaled again for overall sensitivity in the WM based on user prefs + /* Scale axis values here to normalize them to around +/- 1 + * they are scaled again for overall sensitivity in the WM based on user preferences. */ - const float scale = 1.0f / 350.0f; // 3Dconnexion devices send +/- 350 usually + const float scale = 1.0f / 350.0f; /* 3Dconnexion devices send +/- 350 usually */ data->tx = scale * m_translation[0]; data->ty = scale * m_translation[1]; @@ -451,24 +451,24 @@ bool GHOST_NDOFManager::sendMotionEvent() data->ry = scale * m_rotation[1]; data->rz = scale * m_rotation[2]; - data->dt = 0.001f * (m_motionTime - m_prevMotionTime); // in seconds + data->dt = 0.001f * (m_motionTime - m_prevMotionTime); /* In seconds. */ m_prevMotionTime = m_motionTime; bool weHaveMotion = !nearHomePosition(data, m_deadZone); - // determine what kind of motion event to send (Starting, InProgress, Finishing) - // and where that leaves this NDOF manager (NotStarted, InProgress, Finished) + /* Determine what kind of motion event to send `(Starting, InProgress, Finishing)` + * and where that leaves this NDOF manager `(NotStarted, InProgress, Finished)`. */ switch (m_motionState) { case GHOST_kNotStarted: case GHOST_kFinished: if (weHaveMotion) { data->progress = GHOST_kStarting; m_motionState = GHOST_kInProgress; - // prev motion time will be ancient, so just make up a reasonable time delta + /* Previous motion time will be ancient, so just make up a reasonable time delta. */ data->dt = 0.0125f; } else { - // send no event and keep current state + /* Send no event and keep current state. */ #ifdef DEBUG_NDOF_MOTION printf("ndof motion ignored -- %s\n", progress_string[data->progress]); #endif @@ -479,20 +479,22 @@ bool GHOST_NDOFManager::sendMotionEvent() case GHOST_kInProgress: if (weHaveMotion) { data->progress = GHOST_kInProgress; - // remain 'InProgress' + /* Remain 'InProgress'. */ } else { data->progress = GHOST_kFinishing; m_motionState = GHOST_kFinished; } break; - default:; // will always be one of the above + default: + /* Will always be one of the above. */ + break; } #ifdef DEBUG_NDOF_MOTION printf("ndof motion sent -- %s\n", progress_string[data->progress]); - // show details about this motion event + /* Show details about this motion event. */ printf(" T=(%d,%d,%d) R=(%d,%d,%d) raw\n", m_translation[0], m_translation[1], |