if overlapping calls, haptics take on strength and duration of call that will finish last

This commit is contained in:
SamGondelman 2016-06-06 15:35:12 -07:00
parent cea0d74c35
commit b59d597780
3 changed files with 12 additions and 8 deletions

View file

@ -253,16 +253,18 @@ bool OculusControllerManager::TouchDevice::triggerHapticPulse(float strength, fl
Locker locker(_lock); Locker locker(_lock);
bool toReturn = true; bool toReturn = true;
if (hand == controller::BOTH || hand == controller::LEFT) { if (hand == controller::BOTH || hand == controller::LEFT) {
if (ovr_SetControllerVibration(_parent._session, ovrControllerType_LTouch, 1.0f, strength) != ovrSuccess) { _leftHapticStrength = (duration > _leftHapticDuration) ? strength : _leftHapticStrength;
if (ovr_SetControllerVibration(_parent._session, ovrControllerType_LTouch, 1.0f, _leftHapticStrength) != ovrSuccess) {
toReturn = false; toReturn = false;
} }
_leftHapticDuration = duration; _leftHapticDuration = std::max(duration, _leftHapticDuration);
} }
if (hand == controller::BOTH || hand == controller::RIGHT) { if (hand == controller::BOTH || hand == controller::RIGHT) {
if (ovr_SetControllerVibration(_parent._session, ovrControllerType_RTouch, 1.0f, strength) != ovrSuccess) { _rightHapticStrength = (duration > _rightHapticDuration) ? strength : _rightHapticStrength;
if (ovr_SetControllerVibration(_parent._session, ovrControllerType_RTouch, 1.0f, _rightHapticStrength) != ovrSuccess) {
toReturn = false; toReturn = false;
} }
_rightHapticDuration = duration; _rightHapticDuration = std::max(duration, _rightHapticDuration);
} }
return toReturn; return toReturn;
} }

View file

@ -80,7 +80,9 @@ private:
void withLock(F&& f) { Locker locker(_lock); f(); } void withLock(F&& f) { Locker locker(_lock); f(); }
float _leftHapticDuration { 0.0f }; float _leftHapticDuration { 0.0f };
float _leftHapticStrength { 0.0f };
float _rightHapticDuration { 0.0f }; float _rightHapticDuration { 0.0f };
float _rightHapticStrength { 0.0f };
mutable std::recursive_mutex _lock; mutable std::recursive_mutex _lock;
friend class OculusControllerManager; friend class OculusControllerManager;

View file

@ -455,12 +455,12 @@ void ViveControllerManager::InputDevice::handlePoseEvent(float deltaTime, const
bool ViveControllerManager::InputDevice::triggerHapticPulse(float strength, float duration, controller::Hand hand) { bool ViveControllerManager::InputDevice::triggerHapticPulse(float strength, float duration, controller::Hand hand) {
Locker locker(_lock); Locker locker(_lock);
if (hand == controller::BOTH || hand == controller::LEFT) { if (hand == controller::BOTH || hand == controller::LEFT) {
_leftHapticStrength = strength; _leftHapticStrength = (duration > _leftHapticDuration) ? strength : _leftHapticStrength;
_leftHapticDuration = duration; _leftHapticDuration = std::max(duration, _leftHapticDuration);
} }
if (hand == controller::BOTH || hand == controller::RIGHT) { if (hand == controller::BOTH || hand == controller::RIGHT) {
_rightHapticStrength = strength; _rightHapticStrength = (duration > _rightHapticDuration) ? strength : _rightHapticStrength;
_rightHapticDuration = duration; _rightHapticDuration = std::max(duration, _rightHapticDuration);
} }
return true; return true;
} }