diff --git a/intern/ghost/intern/GHOST_NDOFManager.cc b/intern/ghost/intern/GHOST_NDOFManager.cc index a286ab2b21b..553064576bd 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.cc +++ b/intern/ghost/intern/GHOST_NDOFManager.cc @@ -506,22 +506,15 @@ void GHOST_NDOFManager::sendKeyEvent(GHOST_TKey key, system_.pushEvent(event); } -void GHOST_NDOFManager::updateButton(int button_number, bool press, uint64_t time) +void GHOST_NDOFManager::updateButton(GHOST_NDOF_ButtonT button, bool press, uint64_t time) { - GHOST_NDOF_ButtonT button = static_cast(button_number); - if (button == GHOST_NDOF_BUTTON_INVALID) { - CLOG_INFO( - LOG, 2, "button=%d, press=%d (mapped to none, ignoring!)", button_number, int(press)); + CLOG_INFO(LOG, 2, "button=%d, press=%d (mapped to none, ignoring!)", int(button), int(press)); return; } - CLOG_INFO(LOG, - 2, - "button=%d, press=%d, name=%s", - button_number, - int(press), - ndof_button_names.at(button)); + CLOG_INFO( + LOG, 2, "button=%d, press=%d, name=%s", button, int(press), ndof_button_names.at(button)); #ifndef USE_3DCONNEXION_NONSTANDARD_KEYS if (((button >= GHOST_NDOF_BUTTON_KBP_F1) && (button <= GHOST_NDOF_BUTTON_KBP_F12)) || @@ -545,6 +538,28 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, uint64_t tim } } +void GHOST_NDOFManager::updateButtonRAW(int button_number, bool press, uint64_t time) +{ + GHOST_NDOF_ButtonT button; + + /* For bit-mask devices button mapping isn't unified, therefore check the button map. */ + if (std::find(bitmask_devices_.begin(), bitmask_devices_.end(), device_type_) != + bitmask_devices_.end()) + { + if (button_number >= hid_map_button_num_) { + CLOG_INFO( + LOG, 2, "button=%d, press=%d (out of range, ignoring!)", button_number, int(press)); + return; + } + button = hid_map_[button_number]; + } + else { + button = static_cast(button_number); + } + + GHOST_NDOFManager::updateButton(button, press, time); +} + void GHOST_NDOFManager::updateButtonsBitmask(int button_bits, uint64_t time) { /* Some devices send two data packets: bitmask and number array. @@ -574,7 +589,7 @@ void GHOST_NDOFManager::updateButtonsBitmask(int button_bits, uint64_t time) /* Bitmask devices don't have unified keymaps, so button numbers needs to be looked up in the * map. */ - int button = hid_map_[button_number]; + const GHOST_NDOF_ButtonT button = hid_map_[button_number]; updateButton(button, press, time); } } diff --git a/intern/ghost/intern/GHOST_NDOFManager.hh b/intern/ghost/intern/GHOST_NDOFManager.hh index 7b1e6ef5bd9..7ce232a1bad 100644 --- a/intern/ghost/intern/GHOST_NDOFManager.hh +++ b/intern/ghost/intern/GHOST_NDOFManager.hh @@ -81,7 +81,11 @@ class GHOST_NDOFManager { * The latest raw button data from the device * use HID button encoding (not #NDOF_ButtonT). */ - void updateButton(int button_number, bool press, uint64_t time); + void updateButtonRAW(int button_number, bool press, uint64_t time); + /** + * Add the button event which has already been mapped to #GHOST_NDOF_ButtonT. + */ + void updateButton(GHOST_NDOF_ButtonT button, bool press, uint64_t time); void updateButtonsBitmask(int button_bits, uint64_t time); void updateButtonsArray(NDOF_Button_Array buttons, uint64_t time, NDOF_Button_Type type); /* #NDOFButton events are sent immediately */ diff --git a/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm b/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm index 555645280d3..404c4725ffc 100644 --- a/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm +++ b/intern/ghost/intern/GHOST_NDOFManagerCocoa.mm @@ -205,7 +205,7 @@ static void DeviceEvent(uint32_t /*unused*/, uint32_t msg_type, void *msg_arg) #ifdef DEBUG_NDOF_BUTTONS printf("button number: %d, pressed: %d\n", button_number, pressed); #endif - ndof_manager->updateButton(button_number, pressed, now); + ndof_manager->updateButton(GHOST_NDOF_ButtonT(button_number), pressed, now); ghost_system->notifyExternalEventProcessed(); break; } diff --git a/intern/ghost/intern/GHOST_NDOFManagerUnix.cc b/intern/ghost/intern/GHOST_NDOFManagerUnix.cc index 83e2052bf52..f24df77cb54 100644 --- a/intern/ghost/intern/GHOST_NDOFManagerUnix.cc +++ b/intern/ghost/intern/GHOST_NDOFManagerUnix.cc @@ -116,7 +116,7 @@ bool GHOST_NDOFManagerUnix::processEvents() } case SPNAV_EVENT_BUTTON: uint64_t now = system_.getMilliSeconds(); - updateButton(e.button.bnum, e.button.press, now); + updateButtonRAW(e.button.bnum, e.button.press, now); break; } anyProcessed = true;