[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37523] branches/merwin-spacenav/intern/ ghost/intern: mapping HID button codes -> functions, for SpaceNavigator and SpaceExplorer
Mike Erwin
significant.bit at gmail.com
Wed Jun 15 21:45:00 CEST 2011
Revision: 37523
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37523
Author: merwin
Date: 2011-06-15 19:45:00 +0000 (Wed, 15 Jun 2011)
Log Message:
-----------
mapping HID button codes -> functions, for SpaceNavigator and SpaceExplorer
Modified Paths:
--------------
branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp 2011-06-15 19:33:46 UTC (rev 37522)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp 2011-06-15 19:45:00 UTC (rev 37523)
@@ -23,12 +23,83 @@
#include "GHOST_NDOFManager.h"
#include "GHOST_EventNDOF.h"
+#include "GHOST_EventKey.h"
#include "GHOST_WindowManager.h"
#include <string.h> // for memory functions
#include <stdio.h> // for debug tracing
+
+
+const char* ndof_button_names[] = {
+ // used internally, never sent
+ "NDOF_BUTTON_NONE",
+ // 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",
+ };
+
+const NDOF_ButtonT SpaceNavigator_HID_to_function[2] =
+ {
+ NDOF_BUTTON_MENU,
+ NDOF_BUTTON_FIT
+ };
+
+const NDOF_ButtonT SpaceExplorer_HID_to_function[16] =
+ {
+ NDOF_BUTTON_1,
+ NDOF_BUTTON_2,
+ NDOF_BUTTON_TOP,
+ NDOF_BUTTON_LEFT,
+ NDOF_BUTTON_RIGHT,
+ NDOF_BUTTON_FRONT,
+ NDOF_BUTTON_NONE, // esc key
+ NDOF_BUTTON_NONE, // alt key
+ NDOF_BUTTON_NONE, // shift key
+ NDOF_BUTTON_NONE, // ctrl key
+ NDOF_BUTTON_FIT,
+ NDOF_BUTTON_MENU,
+ NDOF_BUTTON_PLUS,
+ NDOF_BUTTON_MINUS,
+ NDOF_BUTTON_ROTATE
+ };
+
GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System& sys)
: m_system(sys)
+ , m_deviceType(SpaceExplorer) // set it manually, until device detection code is in place
, m_buttons(0)
, m_motionTime(1000) // one full second (operators should filter out such large time deltas)
, m_prevMotionTime(0)
@@ -54,52 +125,82 @@
m_atRest = false;
}
-void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64 time)
+void GHOST_NDOFManager::sendButtonEvent(NDOF_ButtonT button, bool press, GHOST_TUns64 time, GHOST_IWindow* window)
{
- GHOST_IWindow* window = m_system.getWindowManager()->getActiveWindow();
-
GHOST_EventNDOFButton* event = new GHOST_EventNDOFButton(time, window);
GHOST_TEventNDOFButtonData* data = (GHOST_TEventNDOFButtonData*) event->getData();
data->action = press ? GHOST_kPress : GHOST_kRelease;
- data->button = button_number + 1;
+ data->button = button;
- printf("sending button %d %s\n", data->button, (data->action == GHOST_kPress) ? "pressed" : "released");
+ printf("sending %s %s\n", ndof_button_names[button], press ? "pressed" : "released");
m_system.pushEvent(event);
+ }
- unsigned short mask = 1 << button_number;
+void GHOST_NDOFManager::sendKeyEvent(GHOST_TKey key, bool press, GHOST_TUns64 time, GHOST_IWindow* window)
+ {
+ GHOST_TEventType type = press ? GHOST_kEventKeyDown : GHOST_kEventKeyUp;
+ GHOST_EventKey* event = new GHOST_EventKey(time, type, window, key);
+
+ m_system.pushEvent(event);
+ }
+
+void GHOST_NDOFManager::updateButton(int button_number, bool press, GHOST_TUns64 time)
+ {
+ GHOST_IWindow* window = m_system.getWindowManager()->getActiveWindow();
+
+ switch (m_deviceType)
+ {
+ case SpaceNavigator:
+ sendButtonEvent(SpaceNavigator_HID_to_function[button_number], press, time, window);
+ break;
+ case SpaceExplorer:
+ switch (button_number)
+ {
+ case 6:
+ sendKeyEvent(GHOST_kKeyEsc, press, time, window);
+ break;
+ case 7:
+ sendKeyEvent(GHOST_kKeyLeftAlt, press, time, window);
+ break;
+ case 8:
+ sendKeyEvent(GHOST_kKeyLeftShift, press, time, window);
+ break;
+ case 9:
+ sendKeyEvent(GHOST_kKeyLeftControl, press, time, window);
+ break;
+ default:
+ sendButtonEvent(SpaceExplorer_HID_to_function[button_number], press, time, window);
+ }
+ break;
+ case SpacePilot:
+ printf("button %d %s\n", button, press ? "pressed" : "released");
+ // sendButtonEvent(SpacePilot_HID_to_function(button_number), press, time, window);
+ break;
+ }
+
+ int mask = 1 << button_number;
if (press)
m_buttons |= mask; // set this button's bit
else
m_buttons &= ~mask; // clear this button's bit
}
-void GHOST_NDOFManager::updateButtons(unsigned button_bits, GHOST_TUns64 time)
+void GHOST_NDOFManager::updateButtons(int button_bits, GHOST_TUns64 time)
{
- GHOST_IWindow* window = m_system.getWindowManager()->getActiveWindow();
+ int diff = m_buttons ^ button_bits;
- unsigned diff = m_buttons ^ button_bits;
-
- for (int i = 0; i <= 31; ++i)
+ for (int button_number = 0; button_number <= 31; ++button_number)
{
- unsigned short mask = 1 << i;
+ int mask = 1 << button_number;
if (diff & mask)
{
- GHOST_EventNDOFButton* event = new GHOST_EventNDOFButton(time, window);
- GHOST_TEventNDOFButtonData* data = (GHOST_TEventNDOFButtonData*) event->getData();
-
- data->action = (button_bits & mask) ? GHOST_kPress : GHOST_kRelease;
- data->button = i + 1;
-
- printf("sending button %d %s\n", data->button, (data->action == GHOST_kPress) ? "pressed" : "released");
-
- m_system.pushEvent(event);
+ bool press = button_bits & mask;
+ updateButton(button_number, press, time);
}
}
-
- m_buttons = button_bits;
}
bool GHOST_NDOFManager::sendMotionEvent()
Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h 2011-06-15 19:33:46 UTC (rev 37522)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.h 2011-06-15 19:45:00 UTC (rev 37523)
@@ -27,6 +27,53 @@
#include "GHOST_System.h"
+// --- the following type definitions will find a home somewhere else once finished ---
+
+typedef enum { SpaceNavigator, SpaceExplorer, SpacePilot } NDOF_DeviceT;
+
+// NDOF device button event types
+typedef enum {
+ // used internally, never sent
+ NDOF_BUTTON_NONE,
+ // 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,
+ } NDOF_ButtonT;
+
class GHOST_NDOFManager
{
public:
@@ -43,25 +90,28 @@
void updateRotation(short r[3], GHOST_TUns64 time);
// send events immediately for changed buttons
void updateButton(int button_number, bool press, GHOST_TUns64 time);
- void updateButtons(unsigned button_bits, GHOST_TUns64 time);
+ void updateButtons(int button_bits, GHOST_TUns64 time);
// processes most recent raw data into an NDOFMotion event and sends it
// returns whether an event was sent
bool sendMotionEvent();
+private:
+ void sendButtonEvent(NDOF_ButtonT, bool press, GHOST_TUns64 time, GHOST_IWindow*);
+ void sendKeyEvent(GHOST_TKey, bool press, GHOST_TUns64 time, GHOST_IWindow*);
+
protected:
GHOST_System& m_system;
+ NDOF_DeviceT m_deviceType;
+
short m_translation[3];
short m_rotation[3];
- unsigned m_buttons; // bit field
+ int m_buttons; // bit field
GHOST_TUns64 m_motionTime; // in milliseconds
GHOST_TUns64 m_prevMotionTime; // time of most recent Motion event sent
bool m_atRest;
-
-// void updateMotionTime(GHOST_TUns64 t);
-// void resetMotion();
};
#endif
More information about the Bf-blender-cvs
mailing list