43#define MAP_ENTRY(button) \
45 GHOST_##button, #button \
124 "SpaceMouseWireless",
125 "SpaceMouseProWireless",
126 "SpaceMouseEnterprise",
215 hid_map_button_mask_(0),
217 button_depressed_(0),
218 pressed_buttons_cache_(),
219 pressed_long_buttons_cache_(),
221 motion_time_prev_(0),
223 motion_event_pending_(
false),
224 motion_dead_zone_(0.0f)
228 memset(translation_, 0,
sizeof(translation_));
229 memset(rotation_, 0,
sizeof(rotation_));
239#define LOG (&LOG_NDOF_DEVICE)
254 hid_map_button_mask_ = 0;
262 switch (product_id) {
268 hid_map_button_num_ = 2;
274 hid_map_button_num_ = 15;
280 hid_map_button_num_ = 31;
286 hid_map_button_num_ = 27;
287 hid_map_button_mask_ = 0x07C0F137;
295 hid_map_button_num_ = 21;
301 hid_map_button_num_ = 12;
306 hid_map_button_num_ = 8;
310 CLOG_INFO(
LOG, 2,
"unknown Logitech product %04hx", product_id);
315 switch (product_id) {
321 hid_map_button_num_ = 2;
332 hid_map_button_num_ = 27;
333 hid_map_button_mask_ = 0x07C0F137;
352 CLOG_INFO(
LOG, 2,
"unknown 3Dconnexion product %04hx", product_id);
357 CLOG_INFO(
LOG, 2,
"unknown device %04hx:%04hx", vendor_id, product_id);
364 if (hid_map_button_mask_ == 0) {
365 hid_map_button_mask_ = int(~(
UINT_MAX << hid_map_button_num_));
368 CLOG_INFO(
LOG, 2,
"%d buttons -> hex:%X", hid_map_button_num_,
uint(hid_map_button_mask_));
383 memcpy(translation_, t,
sizeof(translation_));
385 motion_event_pending_ =
true;
390 memcpy(rotation_, r,
sizeof(rotation_));
392 motion_event_pending_ =
true;
402#define LOG (&LOG_NDOF_BUTTONS)
432#ifdef USE_3DCONNEXION_NONSTANDARD_KEYS
487 "rogue button trying to escape GHOST_NDOF manager");
489 const GHOST_EventNDOFButton *
event =
new GHOST_EventNDOFButton(time, window);
490 GHOST_TEventNDOFButtonData *
data = (GHOST_TEventNDOFButtonData *)event->getData();
492 data->action = press ? GHOST_kPress : GHOST_kRelease;
493 data->button = button;
498void GHOST_NDOFManager::sendKeyEvent(
GHOST_TKey key,
504 const GHOST_EventKey *
event =
new GHOST_EventKey(time, type, window, key,
false);
512 CLOG_INFO(
LOG, 2,
"button=%d, press=%d (mapped to none, ignoring!)",
int(button),
int(press));
519#ifndef USE_3DCONNEXION_NONSTANDARD_KEYS
530 if (window !=
nullptr) {
533 sendKeyEvent(key, press, time, window);
536 sendButtonEvent(button, press, time, window);
546 if (std::find(bitmask_devices_.begin(), bitmask_devices_.end(), device_type_) !=
547 bitmask_devices_.end())
549 if (button_number >= hid_map_button_num_) {
551 LOG, 2,
"button=%d, press=%d (out of range, ignoring!)", button_number,
int(press));
554 button = hid_map_[button_number];
567 if (std::find(bitmask_devices_.begin(), bitmask_devices_.end(), device_type_) ==
568 bitmask_devices_.end())
573 button_bits &= hid_map_button_mask_;
575 int diff = button_depressed_ ^ button_bits;
577 for (
int button_number = 0; button_number < hid_map_button_num_; ++button_number) {
578 int mask = 1 << button_number;
581 bool press = button_bits &
mask;
584 button_depressed_ |=
mask;
587 button_depressed_ &=
~mask;
603 pressed_buttons_cache_;
606 for (
const auto &cached_button : cache) {
608 for (
const auto &button : buttons) {
609 if (button == cached_button) {
621 for (
const auto &button : buttons) {
623 for (
const auto &cached_button : cache) {
624 if (button == cached_button) {
645#define LOG (&LOG_NDOF_MOTION)
650 dz = std::max(dz, 0.0f);
651 motion_dead_zone_ = dz;
654 CLOG_INFO(
LOG, 2,
"dead zone set to %.2f%s", dz, (dz > 0.5f) ?
" (unexpectedly high)" :
"");
659#define HOME(foo) (ndof->foo == 0.0f)
666 if (threshold == 0.0f) {
669#define HOME(foo) (fabsf(ndof->foo) < threshold)
676 if (!motion_event_pending_) {
683 if (
system_.getWindowManager()->getActiveWindow() ==
nullptr) {
691 motion_event_pending_ =
false;
696 if (window ==
nullptr) {
703 GHOST_TEventNDOFMotionData *
data = (GHOST_TEventNDOFMotionData *)event->getData();
708 const float scale = 1.0f / 350.0f;
710 data->tx = scale * translation_[0];
711 data->ty = scale * translation_[1];
712 data->tz = scale * translation_[2];
714 data->rx = scale * rotation_[0];
715 data->ry = scale * rotation_[1];
716 data->rz = scale * rotation_[2];
717 data->dt = 0.001f * (motion_time_ - motion_time_prev_);
718 motion_time_prev_ = motion_time_;
724 switch (motion_state_) {
761 "motion sent, T=(%.2f,%.2f,%.2f), R=(%.2f,%.2f,%.2f) dt=%.3f, status=%s",
774 "motion sent, T=(%d,%d,%d) R=(%d,%d,%d) status=%s",
#define CLOG_INFO(clg_ref, level,...)
#define GHOST_ASSERT(x, info)
static const GHOST_NDOF_ButtonT ndof_HID_map_SpaceExplorer[]
static CLG_LogRef LOG_NDOF_DEVICE
static const int genericButtonCount
static const std::map< GHOST_NDOF_ButtonT, const char * > ndof_button_names
static bool atHomePosition(const GHOST_TEventNDOFMotionData *ndof)
static CLG_LogRef LOG_NDOF_MOTION
static CLG_LogRef LOG_NDOF_BUTTONS
static const GHOST_NDOF_ButtonT ndof_HID_map_Generic[]
static bool nearHomePosition(const GHOST_TEventNDOFMotionData *ndof, float threshold)
static const GHOST_NDOF_ButtonT ndof_HID_map_Shared3Dx[]
static const char * ndof_progress_string[]
static GHOST_TKey ghost_map_keyboard_from_ndof_button(const GHOST_NDOF_ButtonT button)
static const char * ndof_device_names[]
#define MAP_ENTRY(button)
static const GHOST_NDOF_ButtonT ndof_HID_map_SpacePilot[]
@ NDOF_SpaceMouseProWireless
@ NDOF_SpaceMouseWireless
@ NDOF_SpaceMouseEnterprise
#define NDOF_TIME_DELTA_STARTING
std::array< GHOST_NDOF_ButtonT, 6 > NDOF_Button_Array
@ GHOST_NDOF_BUTTON_KBP_F11
@ GHOST_NDOF_BUTTON_FRONT
@ GHOST_NDOF_BUTTON_KBP_F7
@ GHOST_NDOF_BUTTON_DOMINANT
@ GHOST_NDOF_BUTTON_SPACE
@ GHOST_NDOF_BUTTON_DELETE
@ GHOST_NDOF_BUTTON_NP_F2
@ GHOST_NDOF_BUTTON_RIGHT
@ GHOST_NDOF_BUTTON_INVALID
@ GHOST_NDOF_BUTTON_KBP_F9
@ GHOST_NDOF_BUTTON_MINUS
@ GHOST_NDOF_BUTTON_PANZOOM
@ GHOST_NDOF_BUTTON_ROLL_CW
@ GHOST_NDOF_BUTTON_KBP_F1
@ GHOST_NDOF_BUTTON_ROLL_CCW
@ GHOST_NDOF_BUTTON_KBP_F12
@ GHOST_NDOF_BUTTON_KBP_F8
@ GHOST_NDOF_BUTTON_KBP_F5
@ GHOST_NDOF_BUTTON_KBP_F6
@ GHOST_NDOF_BUTTON_NP_F1
@ GHOST_NDOF_BUTTON_KBP_F2
@ GHOST_NDOF_BUTTON_NP_F4
@ GHOST_NDOF_BUTTON_NP_F3
@ GHOST_NDOF_BUTTON_KBP_F3
@ GHOST_NDOF_BUTTON_BOTTOM
@ GHOST_NDOF_BUTTON_ROTATE
@ GHOST_NDOF_BUTTON_KBP_F10
@ GHOST_NDOF_BUTTON_ENTER
@ GHOST_NDOF_BUTTON_KBP_F4
@ GHOST_NDOF_BUTTON_SHIFT
BMesh const char void * data
unsigned long long int uint64_t
void updateButtonsBitmask(int button_bits, uint64_t time)
void updateButton(GHOST_NDOF_ButtonT button, bool press, uint64_t time)
void updateButtonsArray(NDOF_Button_Array buttons, uint64_t time, NDOF_Button_Type type)
void updateTranslation(const int t[3], uint64_t time)
GHOST_NDOFManager(GHOST_System &)
void updateButtonRAW(int button_number, bool press, uint64_t time)
void updateRotation(const int r[3], uint64_t time)
bool setDevice(unsigned short vendor_id, unsigned short product_id)
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)