* 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.
Showing the changes to plugins/openvr/src/ViveControllerManager.cpp (1 of 9 files). Show all
Unified · Split
| @@ -211,9 +211,13 @@ void ViveControllerManager::renderHand(const controller::Pose& pose, gpu::Batch& · 210 unmodified lines | |||
| 211 | 211 | ||
| 212 | 212 | ||
| 213 | void ViveControllerManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, bool jointsCaptured) { | 213 | void ViveControllerManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData, bool jointsCaptured) { |
| 214 | _inputDevice->update(deltaTime, inputCalibrationData, jointsCaptured); | ||
| 215 | auto userInputMapper = DependencyManager::get<controller::UserInputMapper>(); | 214 | auto userInputMapper = DependencyManager::get<controller::UserInputMapper>(); |
| 216 | 215 | ||
| 216 | // because update mutates the internal state we need to lock | ||
| 217 | userInputMapper->withLock([&, this]() { | ||
| 218 | _inputDevice->update(deltaTime, inputCalibrationData, jointsCaptured); | ||
| 219 | }); | ||
| 220 | |||
| 217 | if (_inputDevice->_trackedControllers == 0 && _registeredWithInputMapper) { | 221 | if (_inputDevice->_trackedControllers == 0 && _registeredWithInputMapper) { |
| 218 | userInputMapper->removeDevice(_inputDevice->_deviceID); | 222 | userInputMapper->removeDevice(_inputDevice->_deviceID); |
| 219 | _registeredWithInputMapper = false; | 223 | _registeredWithInputMapper = false; |
| @@ -270,7 +274,8 @@ void ViveControllerManager::InputDevice::handleHandController(float deltaTime, u · 50 unmodified lines | |||
| 270 | for (uint32_t i = 0; i < vr::k_EButton_Max; ++i) { | 274 | for (uint32_t i = 0; i < vr::k_EButton_Max; ++i) { |
| 271 | auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i); | 275 | auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i); |
| 272 | bool pressed = 0 != (controllerState.ulButtonPressed & mask); | 276 | 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); | ||
| 274 | } | 279 | } |
| 275 | 280 | ||
| 276 | // process each axis | 281 | // process each axis |
| @@ -314,20 +319,26 @@ enum ViveButtonChannel { · 37 unmodified lines | |||
| 314 | 319 | ||
| 315 | 320 | ||
| 316 | // These functions do translation from the Steam IDs to the standard controller IDs | 321 | // 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) { | 322 | void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool touched, bool isLeftHand) { |
| 318 | if (!pressed) { | ||
| 319 | return; | ||
| 320 | } | ||
| 321 | 323 | ||
| 322 | using namespace controller; | 324 | using namespace controller; |
| 323 | if (button == vr::k_EButton_ApplicationMenu) { | 325 | |
| 324 | _buttonPressedMap.insert(isLeftHand ? LEFT_APP_MENU : RIGHT_APP_MENU); | 326 | if (pressed) { |
| 325 | } else if (button == vr::k_EButton_Grip) { | 327 | if (button == vr::k_EButton_ApplicationMenu) { |
| 326 | _buttonPressedMap.insert(isLeftHand ? LB : RB); | 328 | _buttonPressedMap.insert(isLeftHand ? LEFT_APP_MENU : RIGHT_APP_MENU); |
| 327 | } else if (button == vr::k_EButton_SteamVR_Trigger) { | 329 | } else if (button == vr::k_EButton_Grip) { |
| 328 | _buttonPressedMap.insert(isLeftHand ? LT : RT); | 330 | _buttonPressedMap.insert(isLeftHand ? LEFT_GRIP : RIGHT_GRIP); |
| 329 | } else if (button == vr::k_EButton_SteamVR_Touchpad) { | 331 | } else if (button == vr::k_EButton_SteamVR_Trigger) { |
| 330 | _buttonPressedMap.insert(isLeftHand ? LS : RS); | 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 | } | ||
| 331 | } | 342 | } |
| 332 | } | 343 | } |
| 333 | 344 | ||
| @@ -424,18 +435,28 @@ controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableI · 90 unmodified lines | |||
| 424 | makePair(LY, "LY"), | 435 | makePair(LY, "LY"), |
| 425 | makePair(RX, "RX"), | 436 | makePair(RX, "RX"), |
| 426 | makePair(RY, "RY"), | 437 | makePair(RY, "RY"), |
| 427 | // trigger analogs | ||
| 428 | makePair(LT, "LT"), | ||
| 429 | makePair(RT, "RT"), | ||
| 430 | 438 | ||
| 431 | makePair(LB, "LB"), | 439 | // capacitive touch on the touch pad |
| 432 | makePair(RB, "RB"), | 440 | makePair(LS_TOUCH, "LSTouch"), |
| 441 | makePair(RS_TOUCH, "RSTouch"), | ||
| 433 | 442 | ||
| 443 | // touch pad press | ||
| 434 | makePair(LS, "LS"), | 444 | makePair(LS, "LS"), |
| 435 | makePair(RS, "RS"), | 445 | 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 | ||
| 436 | makePair(LEFT_HAND, "LeftHand"), | 456 | makePair(LEFT_HAND, "LeftHand"), |
| 437 | makePair(RIGHT_HAND, "RightHand"), | 457 | makePair(RIGHT_HAND, "RightHand"), |
| 438 | 458 | ||
| 459 | // app button above trackpad. | ||
| 439 | Input::NamedPair(Input(_deviceID, LEFT_APP_MENU, ChannelType::BUTTON), "LeftApplicationMenu"), | 460 | Input::NamedPair(Input(_deviceID, LEFT_APP_MENU, ChannelType::BUTTON), "LeftApplicationMenu"), |
| 440 | Input::NamedPair(Input(_deviceID, RIGHT_APP_MENU, ChannelType::BUTTON), "RightApplicationMenu"), | 461 | Input::NamedPair(Input(_deviceID, RIGHT_APP_MENU, ChannelType::BUTTON), "RightApplicationMenu"), |
| 441 | }; | 462 | }; |