44#define MAP_ENTRY(button) {GHOST_##button, #button}
122 "SpaceMouseWireless",
123 "SpaceMouseProWireless",
124 "SpaceMouseEnterprise",
213 hid_map_button_mask_(0),
215 button_depressed_(0),
216 pressed_buttons_cache_(),
217 pressed_long_buttons_cache_(),
219 motion_time_prev_(0),
221 motion_event_pending_(
false),
222 motion_dead_zone_(0.0f)
226 memset(translation_, 0,
sizeof(translation_));
227 memset(rotation_, 0,
sizeof(rotation_));
249 hid_map_button_mask_ = 0;
257 switch (product_id) {
263 hid_map_button_num_ = 2;
269 hid_map_button_num_ = 15;
275 hid_map_button_num_ = 31;
281 hid_map_button_num_ = 27;
282 hid_map_button_mask_ = 0x07C0F137;
290 hid_map_button_num_ = 21;
296 hid_map_button_num_ = 12;
301 hid_map_button_num_ = 8;
305 CLOG_INFO(&
LOG,
"Unknown Logitech product %04hx", product_id);
310 switch (product_id) {
316 hid_map_button_num_ = 2;
327 hid_map_button_num_ = 27;
328 hid_map_button_mask_ = 0x07C0F137;
347 CLOG_INFO(&
LOG,
"Unknown 3Dconnexion product %04hx", product_id);
352 CLOG_INFO(&
LOG,
"Unknown device %04hx:%04hx", vendor_id, product_id);
359 if (hid_map_button_mask_ == 0) {
360 hid_map_button_mask_ = int(~(
UINT_MAX << hid_map_button_num_));
363 CLOG_DEBUG(&
LOG,
"Device %d buttons -> hex:%X", hid_map_button_num_,
uint(hid_map_button_mask_));
376 memcpy(translation_, t,
sizeof(translation_));
378 motion_event_pending_ =
true;
383 memcpy(rotation_, r,
sizeof(rotation_));
385 motion_event_pending_ =
true;
422#ifdef USE_3DCONNEXION_NONSTANDARD_KEYS
477 "rogue button trying to escape GHOST_NDOF manager");
479 const GHOST_EventNDOFButton *
event =
new GHOST_EventNDOFButton(time, window);
480 GHOST_TEventNDOFButtonData *
data = (GHOST_TEventNDOFButtonData *)event->getData();
482 data->action = press ? GHOST_kPress : GHOST_kRelease;
483 data->button = button;
488void GHOST_NDOFManager::sendKeyEvent(
GHOST_TKey key,
494 const GHOST_EventKey *
event =
new GHOST_EventKey(time, type, window, key,
false);
503 &
LOG,
"Update button=%d, press=%d (mapped to none, ignoring!)",
int(button),
int(press));
508 "Update button=%d, press=%d, name=%s",
513#ifndef USE_3DCONNEXION_NONSTANDARD_KEYS
524 if (window !=
nullptr) {
527 sendKeyEvent(key, press, time, window);
530 sendButtonEvent(button, press, time, window);
540 if (std::find(bitmask_devices_.begin(), bitmask_devices_.end(), device_type_) !=
541 bitmask_devices_.end())
543 if (button_number >= hid_map_button_num_) {
545 &
LOG,
"Update button=%d, press=%d (out of range, ignoring!)", button_number,
int(press));
548 button = hid_map_[button_number];
561 if (std::find(bitmask_devices_.begin(), bitmask_devices_.end(), device_type_) ==
562 bitmask_devices_.end())
567 button_bits &= hid_map_button_mask_;
569 int diff = button_depressed_ ^ button_bits;
571 for (
int button_number = 0; button_number < hid_map_button_num_; ++button_number) {
572 int mask = 1 << button_number;
575 bool press = button_bits &
mask;
578 button_depressed_ |=
mask;
581 button_depressed_ &=
~mask;
597 pressed_buttons_cache_;
600 for (
const auto &cached_button : cache) {
602 for (
const auto &button : buttons) {
603 if (button == cached_button) {
615 for (
const auto &button : buttons) {
617 for (
const auto &cached_button : cache) {
618 if (button == cached_button) {
640 dz = std::max(dz, 0.0f);
641 motion_dead_zone_ = dz;
644 CLOG_INFO(&
LOG,
"Dead zone set to %.2f%s", dz, (dz > 0.5f) ?
" (unexpectedly high)" :
"");
649#define HOME(foo) (ndof->foo == 0.0f)
656 if (threshold == 0.0f) {
659#define HOME(foo) (fabsf(ndof->foo) < threshold)
666 if (!motion_event_pending_) {
673 if (
system_.getWindowManager()->getActiveWindow() ==
nullptr) {
681 motion_event_pending_ =
false;
686 if (window ==
nullptr) {
693 GHOST_TEventNDOFMotionData *
data = (GHOST_TEventNDOFMotionData *)event->getData();
698 const float scale = 1.0f / 350.0f;
700 data->tx = scale * translation_[0];
701 data->ty = scale * translation_[1];
702 data->tz = scale * translation_[2];
704 data->rx = scale * rotation_[0];
705 data->ry = scale * rotation_[1];
706 data->rz = scale * rotation_[2];
707 data->dt = 0.001f * (motion_time_ - motion_time_prev_);
708 motion_time_prev_ = motion_time_;
714 switch (motion_state_) {
750 "Motion sent, T=(%.2f,%.2f,%.2f), R=(%.2f,%.2f,%.2f) dt=%.3f, status=%s",
762 "Motion sent, T=(%d,%d,%d) R=(%d,%d,%d) status=%s",
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_INFO(clg_ref,...)
#define GHOST_ASSERT(x, info)
static const GHOST_NDOF_ButtonT ndof_HID_map_SpaceExplorer[]
static const int genericButtonCount
static const std::map< GHOST_NDOF_ButtonT, const char * > ndof_button_names
static bool atHomePosition(const GHOST_TEventNDOFMotionData *ndof)
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)