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

Commit

Permalink
OpenVR plugin in now functional
Browse files Browse the repository at this point in the history
* Fixed crash on rumble (accidentally has CPSMoveTrackerLatest saying it implemented the controller interface when it didn't)
* Fixed uninitialized rumble state
* Tweaked rumble timings
  • Loading branch information
HipsterSloth committed Jun 6, 2016
1 parent e3a32b2 commit c092b9e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 26 deletions.
21 changes: 18 additions & 3 deletions src/openvr_plugin/InitialSetup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ setlocal
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please select the root folder for steam (ex: c:\Program Files (x86)\steam).',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "STEAM_ROOT_PATH=%%I"
if NOT DEFINED STEAM_ROOT_PATH (goto failure)
IF NOT DEFINED STEAM_ROOT_PATH (goto failure)

IF EXIST "%STEAM_ROOT_PATH%\steamapps\common\OpenVR" GOTO use_openvr
IF EXIST "%STEAM_ROOT_PATH%\steamapps\common\SteamVR" GOTO use_steamvr
goto no_steamvr_installed

:no_steamvr_installed
echo "No steamvr folder found at %STEAM_ROOT_PATH%! Please install steamvr."
goto failure

:use_openvr
set STEAMVR_RUNTIME_DIR=%STEAM_ROOT_PATH%\steamapps\common\OpenVR

:use_steamvr
set STEAMVR_RUNTIME_DIR=%STEAM_ROOT_PATH%\steamapps\common\SteamVR

:: Write out the paths to a config batch file
del SetDriverVars.bat
echo @echo off >> SetDriverVars.bat
echo set PLATFORM=win32>> SetDriverVars.bat
echo set INSTALL_DIR=%STEAM_ROOT_PATH%\steamapps\common\OpenVR\drivers\psmove>> SetDriverVars.bat
echo set INSTALL_DIR=%STEAMVR_RUNTIME_DIR%\drivers\psmove>> SetDriverVars.bat
echo set BUILD_DIR=..\..\win32\bin>> SetDriverVars.bat
echo set STEAMVR_RUNTIME_DIR=%STEAM_ROOT_PATH%\steamapps\common\OpenVR>> SetDriverVars.bat
echo set STEAMVR_RUNTIME_DIR=%STEAMVR_RUNTIME_DIR%>> SetDriverVars.bat

:: Copy over the openvr drivers
::call ReinstallDriver.bat
pause
goto exit

:failure
pause
goto exit

:exit
Expand Down
68 changes: 46 additions & 22 deletions src/openvr_plugin/driver_psmoveservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,16 @@ vr::EVRInitError CClientDriver_PSMoveService::SetDisplayId( const char * pchDisp

vr::HiddenAreaMesh_t CClientDriver_PSMoveService::GetHiddenAreaMesh( vr::EVREye eEye )
{
return vr::HiddenAreaMesh_t();
vr::HiddenAreaMesh_t hiddenAreaMesh= vr::HiddenAreaMesh_t();

return hiddenAreaMesh;
}

uint32_t CClientDriver_PSMoveService::GetMCImage( uint32_t * pImgWidth, uint32_t * pImgHeight, uint32_t * pChannels, void * pDataBuffer, uint32_t unBufferLen )
{
return uint32_t();
uint32_t image= uint32_t();

return image;
}

//==================================================================================================
Expand Down Expand Up @@ -613,11 +617,6 @@ void CPSMoveTrackedDeviceLatest::PowerOff()

void *CPSMoveTrackedDeviceLatest::GetComponent(const char *pchComponentNameAndVersion)
{
if (!strcasecmp(pchComponentNameAndVersion, vr::IVRControllerComponent_Version))
{
return (vr::IVRControllerComponent*)this;
}

return NULL;
}

Expand Down Expand Up @@ -804,9 +803,14 @@ const char *CPSMoveTrackedDeviceLatest::GetSerialNumber() const

CPSMoveControllerLatest::CPSMoveControllerLatest( vr::IServerDriverHost * pDriverHost, int controllerId )
: CPSMoveTrackedDeviceLatest(pDriverHost)
, m_nControllerId( controllerId )
, m_nPoseSequenceNumber( 0 )

, m_nControllerId(controllerId)
, m_controller_view(nullptr)
, m_nPoseSequenceNumber(0)
, m_bIsBatteryCharging(false)
, m_fBatteryChargeFraction(1.f)
, m_pendingHapticPulseDuration(0)
, m_sentHapticPulseDuration(0)
, m_lastTimeRumbleSent()
{
char buf[256];
GenerateControllerSerialNumber(buf, sizeof(buf), controllerId);
Expand All @@ -815,11 +819,7 @@ CPSMoveControllerLatest::CPSMoveControllerLatest( vr::IServerDriverHost * pDrive
// Tell psmoveapi that we are listening to this controller id
m_controller_view = ClientPSMoveAPI::allocate_controller_view(controllerId);

memset( &m_ControllerState, 0, sizeof( m_ControllerState ) );

//###HipsterSloth $TODO - Register for updates from the service about these values changing
m_bIsBatteryCharging= false;
m_fBatteryChargeFraction= 1.f;
memset(&m_ControllerState, 0, sizeof(vr::VRControllerState_t));

// Load config from steamvr.vrsettings
//vr::IVRSettings *settings_;
Expand Down Expand Up @@ -854,6 +854,16 @@ void CPSMoveControllerLatest::Deactivate()
ClientPSMoveAPI::stop_controller_data_stream(m_controller_view);
}

void *CPSMoveControllerLatest::GetComponent(const char *pchComponentNameAndVersion)
{
if (!strcasecmp(pchComponentNameAndVersion, vr::IVRControllerComponent_Version))
{
return (vr::IVRControllerComponent*)this;
}

return NULL;
}

bool CPSMoveControllerLatest::GetBoolTrackedDeviceProperty(
vr::ETrackedDeviceProperty prop,
vr::ETrackedPropertyError * pError)
Expand Down Expand Up @@ -1018,9 +1028,7 @@ uint32_t CPSMoveControllerLatest::GetStringTrackedDeviceProperty(

vr::VRControllerState_t CPSMoveControllerLatest::GetControllerState()
{
// This is only called at startup to synchronize with the driver.
// Future updates are driven by our thread calling TrackedDeviceButton*() and TrackedDeviceAxis*()
return vr::VRControllerState_t();
return m_ControllerState;
}

bool CPSMoveControllerLatest::TriggerHapticPulse( uint32_t unAxisId, uint16_t usPulseDurationMicroseconds )
Expand Down Expand Up @@ -1210,8 +1218,8 @@ void CPSMoveControllerLatest::UpdateTrackingState()

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

// Only bother with this if the rumble value actually changed
if (m_pendingHapticPulseDuration != m_sentHapticPulseDuration)
Expand All @@ -1224,9 +1232,18 @@ void CPSMoveControllerLatest::UpdateRumbleState()
{
float rumble_fraction = static_cast<float>(m_pendingHapticPulseDuration) / k_max_pulse_microseconds;

if (rumble_fraction > 1.f)
// Keep the pulse intensity within reasonable bounds
if (m_pendingHapticPulseDuration != 0)
{
rumble_fraction = 1.f;
if (rumble_fraction < 0.35f)
{
// rumble values less 35% isn't noticeable
rumble_fraction = 0.35f;
}
else if (rumble_fraction > 1.f)
{
rumble_fraction = 1.f;
}
}

// Actually send the rumble to the server
Expand All @@ -1235,6 +1252,13 @@ void CPSMoveControllerLatest::UpdateRumbleState()
// Remember the last rumble we went and when we sent it
m_sentHapticPulseDuration = m_pendingHapticPulseDuration;
m_lastTimeRumbleSent = now;

// 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;
}
}
}
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 @@ -140,6 +140,7 @@ class CPSMoveControllerLatest : public CPSMoveTrackedDeviceLatest, public vr::IV
// Overridden Implementation of vr::ITrackedDeviceServerDriver
virtual vr::EVRInitError Activate(uint32_t unObjectId) override;
virtual void Deactivate() override;
virtual void *GetComponent(const char *pchComponentNameAndVersion) override;
virtual bool GetBoolTrackedDeviceProperty( vr::ETrackedDeviceProperty prop, vr::ETrackedPropertyError * pError ) override;
virtual float GetFloatTrackedDeviceProperty( vr::ETrackedDeviceProperty prop, vr::ETrackedPropertyError * pError ) override;
virtual int32_t GetInt32TrackedDeviceProperty( vr::ETrackedDeviceProperty prop, vr::ETrackedPropertyError * pError ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/psmoveclient/ClientNetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class ClientNetworkManagerImpl

if (m_pending_requests.size() > 0 && !m_has_pending_tcp_write)
{
RequestPtr request= m_pending_requests.front();
RequestPtr request= m_pending_requests[0];

m_packed_request.set_msg(request);
m_packed_request.pack(m_write_bufer);
Expand Down

0 comments on commit c092b9e

Please sign in to comment.