History

Fix for vive controllers sometimes not working

* Fixed bug with input devices that where added, removed then re-added. The default mappings were being ignored on the second add. * Fixed potential crash when hardware inputPlugin device poses were polled from the JavaScript thread by taking the UserInputManager lock during pluginUpdate. * Renamed Controller.Hardware.Vive.LB & RB to LeftGrip and RightGrip, to better match Oculus touch. * Updated resource/controller/vive.json to reflect this new mapping. * Exposed touch pad capacitive touch events to JavaScript as Controller.Hardware.Vive.LSTouch and RSTouch. * Added viveTouchpadTest.js script to test LSTouch and RSTouch events.

Anthony J. Thibault committed 10 years ago

Commit 09a4e0e1 parent 59c6a6d9 files · +172 −34Browse files

Showing the changes to plugins/openvr/src/ViveControllerManager.cpp (1 of 9 files). Show all

Unified · Split

plugins/openvr/src/ViveControllerManager.cpp+40−19
@@ -211,9 +211,13 @@ void ViveControllerManager::renderHand(const controller::Pose& pose, gpu::Batch& · 210 unmodified lines
211211
212212
213213 void ViveControllerManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, bool jointsCaptured) {
214− _inputDevice->update(deltaTime, inputCalibrationData, jointsCaptured);
215214 auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
216215
216+ // because update mutates the internal state we need to lock
217+ userInputMapper->withLock([&, this]() {
218+ _inputDevice->update(deltaTime, inputCalibrationData, jointsCaptured);
219+ });
220+
217221 if (_inputDevice->_trackedControllers == 0 && _registeredWithInputMapper) {
218222 userInputMapper->removeDevice(_inputDevice->_deviceID);
219223 _registeredWithInputMapper = false;
@@ -270,7 +274,8 @@ void ViveControllerManager::InputDevice::handleHandController(float deltaTime, u · 50 unmodified lines
270274 for (uint32_t i = 0; i < vr::k_EButton_Max; ++i) {
271275 auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i);
272276 bool pressed = 0 != (controllerState.ulButtonPressed & mask);
273− handleButtonEvent(deltaTime, i, pressed, isLeftHand);
277+ bool touched = 0 != (controllerState.ulButtonTouched & mask);
278+ handleButtonEvent(deltaTime, i, pressed, touched, isLeftHand);
274279 }
275280
276281 // process each axis
@@ -314,20 +319,26 @@ enum ViveButtonChannel { · 37 unmodified lines
314319
315320
316321 // These functions do translation from the Steam IDs to the standard controller IDs
317−void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool isLeftHand) {
318− if (!pressed) {
319− return;
320− }
322+void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool touched, bool isLeftHand) {
321323
322324 using namespace controller;
323− if (button == vr::k_EButton_ApplicationMenu) {
324− _buttonPressedMap.insert(isLeftHand ? LEFT_APP_MENU : RIGHT_APP_MENU);
325− } else if (button == vr::k_EButton_Grip) {
326− _buttonPressedMap.insert(isLeftHand ? LB : RB);
327− } else if (button == vr::k_EButton_SteamVR_Trigger) {
328− _buttonPressedMap.insert(isLeftHand ? LT : RT);
329− } else if (button == vr::k_EButton_SteamVR_Touchpad) {
330− _buttonPressedMap.insert(isLeftHand ? LS : RS);
325+
326+ if (pressed) {
327+ if (button == vr::k_EButton_ApplicationMenu) {
328+ _buttonPressedMap.insert(isLeftHand ? LEFT_APP_MENU : RIGHT_APP_MENU);
329+ } else if (button == vr::k_EButton_Grip) {
330+ _buttonPressedMap.insert(isLeftHand ? LEFT_GRIP : RIGHT_GRIP);
331+ } else if (button == vr::k_EButton_SteamVR_Trigger) {
332+ _buttonPressedMap.insert(isLeftHand ? LT : RT);
333+ } else if (button == vr::k_EButton_SteamVR_Touchpad) {
334+ _buttonPressedMap.insert(isLeftHand ? LS : RS);
335+ }
336+ }
337+
338+ if (touched) {
339+ if (button == vr::k_EButton_SteamVR_Touchpad) {
340+ _buttonPressedMap.insert(isLeftHand ? LS_TOUCH : RS_TOUCH);
341+ }
331342 }
332343 }
333344
@@ -424,18 +435,28 @@ controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableI · 90 unmodified lines
424435 makePair(LY, "LY"),
425436 makePair(RX, "RX"),
426437 makePair(RY, "RY"),
427− // trigger analogs
428− makePair(LT, "LT"),
429− makePair(RT, "RT"),
430438
431− makePair(LB, "LB"),
432− makePair(RB, "RB"),
439+ // capacitive touch on the touch pad
440+ makePair(LS_TOUCH, "LSTouch"),
441+ makePair(RS_TOUCH, "RSTouch"),
433442
443+ // touch pad press
434444 makePair(LS, "LS"),
435445 makePair(RS, "RS"),
446+
447+ // triggers
448+ makePair(LT, "LT"),
449+ makePair(RT, "RT"),
450+
451+ // low profile side grip button.
452+ makePair(LEFT_GRIP, "LeftGrip"),
453+ makePair(RIGHT_GRIP, "RightGrip"),
454+
455+ // 3d location of controller
436456 makePair(LEFT_HAND, "LeftHand"),
437457 makePair(RIGHT_HAND, "RightHand"),
438458
459+ // app button above trackpad.
439460 Input::NamedPair(Input(_deviceID, LEFT_APP_MENU, ChannelType::BUTTON), "LeftApplicationMenu"),
440461 Input::NamedPair(Input(_deviceID, RIGHT_APP_MENU, ChannelType::BUTTON), "RightApplicationMenu"),
441462 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t