Fix: NDOF HID mapping ignored on Unix

Changes in [0] caused NDOF support on Unix to ignore the `hid_map_`.

- Add updateButtonRAW which takes the RAW button values and maps them
  using `hid_map_` (what `updateButton` did before [0]).
- Keep the existing `updateButton` function using mapped events as
  updateButtonsBitmask & updateButtonsArray GHOST_NDOF_ButtonT ordered
  values.

[0]: c3d92f32dc
This commit is contained in:
Campbell Barton
2025-03-25 06:36:52 +00:00
parent 573f182ff7
commit debef6b78f
4 changed files with 34 additions and 15 deletions

View File

@@ -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<GHOST_NDOF_ButtonT>(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<GHOST_NDOF_ButtonT>(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);
}
}

View File

@@ -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 */

View File

@@ -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;
}

View File

@@ -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;