Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Fix for issue #189 (Disable switch for rumble)
Browse files Browse the repository at this point in the history
* Added support for a new "rumble_suppressed" flag in the steamvr.vrsettings file
  • Loading branch information
HipsterSloth committed Aug 31, 2016
1 parent c632c43 commit a7f12fb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 52 deletions.
116 changes: 64 additions & 52 deletions src/openvr_plugin/driver_psmoveservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ CPSMoveControllerLatest::CPSMoveControllerLatest( vr::IServerDriverHost * pDrive
, m_nPoseSequenceNumber(0)
, m_bIsBatteryCharging(false)
, m_fBatteryChargeFraction(1.f)
, m_bRumbleSuppressed(false)
, m_pendingHapticPulseDuration(0)
, m_lastTimeRumbleSent()
, m_lastTimeRumbleSentValid(false)
Expand Down Expand Up @@ -1019,6 +1020,9 @@ CPSMoveControllerLatest::CPSMoveControllerLatest( vr::IServerDriverHost * pDrive
LoadButtonMapping(pSettings, ePSButtonID::k_EPSButtonID_R1, vr::k_EButton_SteamVR_Trigger, k_EVRTouchpadDirection_None);
LoadButtonMapping(pSettings, ePSButtonID::k_EPSButtonID_R2, vr::k_EButton_SteamVR_Trigger, k_EVRTouchpadDirection_None);
LoadButtonMapping(pSettings, ePSButtonID::k_EPSButtonID_R3, vr::k_EButton_Grip, k_EVRTouchpadDirection_None);

// Load the rumble settings
m_bRumbleSuppressed= pSettings->GetBool("psmove", "rumble_suppressed", m_bRumbleSuppressed);
}

CPSMoveControllerLatest::~CPSMoveControllerLatest()
Expand Down Expand Up @@ -1756,67 +1760,75 @@ void CPSMoveControllerLatest::UpdateTrackingState()

void CPSMoveControllerLatest::UpdateRumbleState()
{
const float k_max_rumble_update_rate = 33.f; // Don't bother trying to update the rumble faster than 30fps (33ms)
const float k_max_pulse_microseconds = 1000.f; // Docs suggest max pulse duration of 5ms, but we'll call 1ms max
if (!m_bRumbleSuppressed)
{
const float k_max_rumble_update_rate = 33.f; // Don't bother trying to update the rumble faster than 30fps (33ms)
const float k_max_pulse_microseconds = 1000.f; // Docs suggest max pulse duration of 5ms, but we'll call 1ms max

std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
bool bTimoutElapsed= true;
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
bool bTimoutElapsed = true;

if (m_lastTimeRumbleSentValid)
{
std::chrono::duration<double, std::milli> timeSinceLastSend = now - m_lastTimeRumbleSent;
if (m_lastTimeRumbleSentValid)
{
std::chrono::duration<double, std::milli> timeSinceLastSend = now - m_lastTimeRumbleSent;

bTimoutElapsed= timeSinceLastSend.count() >= k_max_rumble_update_rate;
}
bTimoutElapsed = timeSinceLastSend.count() >= k_max_rumble_update_rate;
}

// See if a rumble request hasn't come too recently
if (bTimoutElapsed)
{
float rumble_fraction = static_cast<float>(m_pendingHapticPulseDuration) / k_max_pulse_microseconds;
// See if a rumble request hasn't come too recently
if (bTimoutElapsed)
{
float rumble_fraction = static_cast<float>(m_pendingHapticPulseDuration) / k_max_pulse_microseconds;

// Unless a zero rumble intensity was explicitly set,
// don't rumble less than 35% (no enough to feel)
if (m_pendingHapticPulseDuration != 0)
{
if (rumble_fraction < 0.35f)
{
// rumble values less 35% isn't noticeable
rumble_fraction = 0.35f;
}
}
// Unless a zero rumble intensity was explicitly set,
// don't rumble less than 35% (no enough to feel)
if (m_pendingHapticPulseDuration != 0)
{
if (rumble_fraction < 0.35f)
{
// rumble values less 35% isn't noticeable
rumble_fraction = 0.35f;
}
}

// Keep the pulse intensity within reasonable bounds
if (rumble_fraction > 1.f)
{
rumble_fraction = 1.f;
}
// Keep the pulse intensity within reasonable bounds
if (rumble_fraction > 1.f)
{
rumble_fraction = 1.f;
}

// Actually send the rumble to the server
switch (m_controller_view->GetControllerViewType())
{
case ClientControllerView::PSMove:
m_controller_view->GetPSMoveViewMutable().SetRumble(rumble_fraction);
break;
case ClientControllerView::PSNavi:
break;
case ClientControllerView::PSDualShock4:
m_controller_view->GetPSDualShock4ViewMutable().SetBigRumble(rumble_fraction);
break;
default:
assert(0 && "Unreachable");
}
// Actually send the rumble to the server
switch (m_controller_view->GetControllerViewType())
{
case ClientControllerView::PSMove:
m_controller_view->GetPSMoveViewMutable().SetRumble(rumble_fraction);
break;
case ClientControllerView::PSNavi:
break;
case ClientControllerView::PSDualShock4:
m_controller_view->GetPSDualShock4ViewMutable().SetBigRumble(rumble_fraction);
break;
default:
assert(0 && "Unreachable");
}

// Remember the last rumble we went and when we sent it
m_lastTimeRumbleSent = now;
m_lastTimeRumbleSentValid= true;
// Remember the last rumble we went and when we sent it
m_lastTimeRumbleSent = now;
m_lastTimeRumbleSentValid = true;

// Reset the pending haptic pulse duration.
// If another call to TriggerHapticPulse() is made later, it will stomp this value.
// If no call to TriggerHapticPulse() is made later, then the next call to UpdateRumbleState()
// in k_max_rumble_update_rate milliseconds will set the rumble_fraction to 0.f
// This effectively makes the shortest rumble pulse k_max_rumble_update_rate milliseconds.
m_pendingHapticPulseDuration = 0;
}
// Reset the pending haptic pulse duration.
// If another call to TriggerHapticPulse() is made later, it will stomp this value.
// If no call to TriggerHapticPulse() is made later, then the next call to UpdateRumbleState()
// in k_max_rumble_update_rate milliseconds will set the rumble_fraction to 0.f
// This effectively makes the shortest rumble pulse k_max_rumble_update_rate milliseconds.
m_pendingHapticPulseDuration = 0;
}
}
else
{
// Reset the pending haptic pulse duration since rumble is suppressed.
m_pendingHapticPulseDuration = 0;
}
}

bool CPSMoveControllerLatest::HasControllerId( int ControllerID )
Expand Down
1 change: 1 addition & 0 deletions src/openvr_plugin/driver_psmoveservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class CPSMoveControllerLatest : public CPSMoveTrackedDeviceLatest, public vr::IV
float m_fBatteryChargeFraction;

// Rumble state
bool m_bRumbleSuppressed;
uint16_t m_pendingHapticPulseDuration;
std::chrono::time_point<std::chrono::high_resolution_clock> m_lastTimeRumbleSent;
bool m_lastTimeRumbleSentValid;
Expand Down

0 comments on commit a7f12fb

Please sign in to comment.