diff options
-rw-r--r-- | intern/ghost/intern/GHOST_NDOFManager.cpp | 14 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_NDOFManager.h | 2 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_NDOFManagerX11.cpp | 28 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_ops.c | 8 | ||||
-rw-r--r-- | source/blender/windowmanager/wm_event_types.h | 58 |
5 files changed, 84 insertions, 26 deletions
diff --git a/intern/ghost/intern/GHOST_NDOFManager.cpp b/intern/ghost/intern/GHOST_NDOFManager.cpp index 20baa6f725e..5c2ca658fdb 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.cpp +++ b/intern/ghost/intern/GHOST_NDOFManager.cpp @@ -97,7 +97,7 @@ static const NDOF_ButtonT SpaceExplorer_HID_map[] = NDOF_BUTTON_ROTATE }; -static const NDOF_ButtonT SpacePilot_HID_map[] = +static const NDOF_ButtonT SpacePilotPro_HID_map[] = { NDOF_BUTTON_MENU, NDOF_BUTTON_FIT, @@ -134,7 +134,7 @@ static const NDOF_ButtonT SpacePilot_HID_map[] = GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System& sys) : m_system(sys) - , m_deviceType(SpacePilot) // set it manually, until device detection code is in place + , m_deviceType(NDOF_UnknownDevice) // each platform needs its own device detection code , m_buttons(0) , m_motionTime(1000) // one full second (operators should filter out such large time deltas) , m_prevMotionTime(0) @@ -197,10 +197,10 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64 switch (m_deviceType) { - case SpaceNavigator: + case NDOF_SpaceNavigator: sendButtonEvent(SpaceNavigator_HID_map[button_number], press, time, window); break; - case SpaceExplorer: + case NDOF_SpaceExplorer: switch (button_number) { case 6: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break; @@ -210,16 +210,18 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64 default: sendButtonEvent(SpaceExplorer_HID_map[button_number], press, time, window); } break; - case SpacePilot: + case NDOF_SpacePilotPro: switch (button_number) { case 22: sendKeyEvent(GHOST_kKeyEsc, press, time, window); break; case 23: sendKeyEvent(GHOST_kKeyLeftAlt, press, time, window); break; case 24: sendKeyEvent(GHOST_kKeyLeftShift, press, time, window); break; case 25: sendKeyEvent(GHOST_kKeyLeftControl, press, time, window); break; - default: sendButtonEvent(SpacePilot_HID_map[button_number], press, time, window); + default: sendButtonEvent(SpacePilotPro_HID_map[button_number], press, time, window); } break; + case NDOF_UnknownDevice: + printf("button %d on unknown device (not sent)\n", button_number); } int mask = 1 << button_number; diff --git a/intern/ghost/intern/GHOST_NDOFManager.h b/intern/ghost/intern/GHOST_NDOFManager.h index ab27fc32f84..564b0f6f239 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.h +++ b/intern/ghost/intern/GHOST_NDOFManager.h @@ -32,7 +32,7 @@ // #define DEBUG_NDOF_MOTION #define DEBUG_NDOF_BUTTONS -typedef enum { SpaceNavigator, SpaceExplorer, SpacePilot } NDOF_DeviceT; +typedef enum { NDOF_UnknownDevice, NDOF_SpaceNavigator, NDOF_SpaceExplorer, NDOF_SpacePilotPro } NDOF_DeviceT; // NDOF device button event types typedef enum { diff --git a/intern/ghost/intern/GHOST_NDOFManagerX11.cpp b/intern/ghost/intern/GHOST_NDOFManagerX11.cpp index 99ee29d8a17..49372e8502d 100644 --- a/intern/ghost/intern/GHOST_NDOFManagerX11.cpp +++ b/intern/ghost/intern/GHOST_NDOFManagerX11.cpp @@ -33,6 +33,34 @@ GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys) if (spnav_open() != -1) { m_available = true; + + // determine exactly which device is plugged in + + #define MAX_LINE_LENGTH 100 + + // look for USB devices with Logitech's vendor ID + FILE* command_output = popen("lsusb -d 046d:","r"); + if (command_output) + { + char line[MAX_LINE_LENGTH] = {0}; + while (fgets(line, MAX_LINE_LENGTH, command_output)) + { + unsigned short vendor_id = 0, product_id = 0; + if (sscanf(line, "Bus %*d Device %*d: ID %hx:%hx", &vendor_id, &product_id) == 2) + { + // the following code will live in the base class + // once all platforms have device detection + switch (product_id) + { + case 0xc626: m_deviceType = NDOF_SpaceNavigator; break; + case 0xc627: m_deviceType = NDOF_SpaceExplorer; break; + case 0xc629: m_deviceType = NDOF_SpacePilotPro; break; + default: printf("unknown product ID: %04x\n", product_id); + } + } + } + pclose(command_output); + } } else { diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 3e99c6992d1..2dd560a6408 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -163,8 +163,14 @@ void view3d_keymap(wmKeyConfig *keyconf) RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1); /* 3D mouse */ - WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON1, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "VIEW3D_OT_ndof", NDOF_MOTION, 0, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BACK, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BACK); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_LEFT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_LEFT); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP); + RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BOTTOM, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BOTTOM); /* numpad view hotkeys*/ RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA); diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index 748f5018e1a..ed500ccd5c5 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -79,25 +79,47 @@ #define INBETWEEN_MOUSEMOVE 17 /* NDOF (from SpaceNavigator & friends) */ -#define NDOF_MOTION 0x12 +#define NDOF_MOTION 0x12 // keep in sync with GHOST_NDOFManager.h enum { - NDOF_BUTTON_NONE = NDOF_MOTION, /* never sent, used internally */ - NDOF_BUTTON1, - NDOF_BUTTON2/*, the following buttons will be supported soon... - NDOF_BUTTON3, and possibly get meaningful names - NDOF_BUTTON4, - NDOF_BUTTON5, - NDOF_BUTTON6, - NDOF_BUTTON7, - NDOF_BUTTON8, - NDOF_BUTTON9, - NDOF_BUTTON10, - NDOF_BUTTON11, - NDOF_BUTTON12, - NDOF_BUTTON13, - NDOF_BUTTON14, - NDOF_BUTTON15, - NDOF_BUTTON16*/ + // used internally, never sent + NDOF_BUTTON_NONE = NDOF_MOTION, + // these two are available from any 3Dconnexion device + NDOF_BUTTON_MENU, + NDOF_BUTTON_FIT, + // standard views + NDOF_BUTTON_TOP, + NDOF_BUTTON_BOTTOM, + NDOF_BUTTON_LEFT, + NDOF_BUTTON_RIGHT, + NDOF_BUTTON_FRONT, + NDOF_BUTTON_BACK, + // more views + NDOF_BUTTON_ISO1, + NDOF_BUTTON_ISO2, + // 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 + NDOF_BUTTON_ROTATE, + NDOF_BUTTON_PANZOOM, + NDOF_BUTTON_DOMINANT, + NDOF_BUTTON_PLUS, + NDOF_BUTTON_MINUS, + // general-purpose buttons + NDOF_BUTTON_1, + NDOF_BUTTON_2, + NDOF_BUTTON_3, + NDOF_BUTTON_4, + NDOF_BUTTON_5, + NDOF_BUTTON_6, + NDOF_BUTTON_7, + NDOF_BUTTON_8, + NDOF_BUTTON_9, + NDOF_BUTTON_10, }; |