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

Commit

Permalink
Updating OpenVR scripts
Browse files Browse the repository at this point in the history
* Renamed openvr scripts to start with "SteamVR_"
* Copy build scripts and resources folder to the bin/win32 folder
* Renamed "driver_psmoveservice" to "driver_psmove"
  • Loading branch information
HipsterSloth committed Jun 8, 2016
1 parent dfd6cbb commit 03f74bc
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 57 deletions.
14 changes: 10 additions & 4 deletions src/openvr_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ file(GLOB OPENVR_PLUGIN_LIBRARY_SRC
)

# Shared library
add_library(driver_psmoveservice SHARED ${OPENVR_PLUGIN_LIBRARY_SRC})
target_include_directories(driver_psmoveservice PUBLIC ${OPENVR_PLUGIN_INCL_DIRS})
target_link_libraries(driver_psmoveservice ${OPENVR_PLUGIN_REQ_LIBS})
add_library(driver_psmove SHARED ${OPENVR_PLUGIN_LIBRARY_SRC})
target_include_directories(driver_psmove PUBLIC ${OPENVR_PLUGIN_INCL_DIRS})
target_link_libraries(driver_psmove ${OPENVR_PLUGIN_REQ_LIBS})

# Install
IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
install(TARGETS driver_psmoveservice
install(TARGETS driver_psmove
RUNTIME DESTINATION ${ROOT_DIR}/win32/bin
LIBRARY DESTINATION ${ROOT_DIR}/win32/lib
ARCHIVE DESTINATION ${ROOT_DIR}/win32/lib)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/
DESTINATION ${ROOT_DIR}/win32/bin
FILES_MATCHING PATTERN "*.bat")
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/resources
DESTINATION ${ROOT_DIR}/win32/bin
FILES_MATCHING PATTERN "*.png" PATTERN "*.json" PATTERN "*.obj" PATTERN "*.mtl")
ELSE() #Linux/Darwin
ENDIF()
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ goto write_set_drivers_script
echo "Found SteamVR Runtime Dir: %STEAMVR_RUNTIME_DIR%"

:: 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=%STEAMVR_RUNTIME_DIR%\drivers\psmove>> SetDriverVars.bat
echo set BUILD_DIR=..\..\win32\bin>> SetDriverVars.bat
echo set STEAMVR_RUNTIME_DIR=%STEAMVR_RUNTIME_DIR%>> SetDriverVars.bat
del SteamVR_SetDriverVars.bat
echo @echo off >> SteamVR_SetDriverVars.bat
echo set PLATFORM=win32>> SteamVR_SetDriverVars.bat
echo set INSTALL_DIR=%STEAMVR_RUNTIME_DIR%\drivers\psmove>> SteamVR_SetDriverVars.bat
echo set STEAMVR_RUNTIME_DIR=%STEAMVR_RUNTIME_DIR%>> SteamVR_SetDriverVars.bat

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@echo off
call SetDriverVars.bat
call SteamVR_SetDriverVars.bat

echo "(Re)Installing PSMoveService OpenVR driver..."
echo "(Re)Installing PSMoveService SteamVR driver..."
IF NOT EXIST "%INSTALL_DIR%\bin\%PLATFORM%" mkdir "%INSTALL_DIR%\bin\%PLATFORM%"
copy %BUILD_DIR%\driver_psmoveservice.dll "%INSTALL_DIR%\bin\%PLATFORM%\driver_psmove.dll"
copy %BUILD_DIR%\PSMoveClient.dll "%INSTALL_DIR%\bin\%PLATFORM%"
copy driver_psmove.dll "%INSTALL_DIR%\bin\%PLATFORM%\driver_psmove.dll"
copy PSMoveClient.dll "%INSTALL_DIR%\bin\%PLATFORM%"
"%STEAMVR_RUNTIME_DIR%\bin\win32\vrpathreg" adddriver "%INSTALL_DIR%"
xcopy /s /i /y "resources" "%STEAMVR_RUNTIME_DIR%\drivers\psmove\resources"

Expand Down
11 changes: 11 additions & 0 deletions src/openvr_plugin/SteamVR_UninstallDriver.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
call SteamVR_SetDriverVars.bat

echo "Unstalling PSMoveService SteamVR driver..."
IF NOT EXIST "%INSTALL_DIR%" goto done
del /F /S /Q "%INSTALL_DIR%*.*"
rmdir /S /Q "%INSTALL_DIR%"

:done
echo "Done"
pause
76 changes: 35 additions & 41 deletions src/openvr_plugin/driver_psmoveservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,6 @@ CPSMoveControllerLatest::CPSMoveControllerLatest( vr::IServerDriverHost * pDrive
, m_bIsBatteryCharging(false)
, m_fBatteryChargeFraction(1.f)
, m_pendingHapticPulseDuration(0)
, m_sentHapticPulseDuration(0)
, m_lastTimeRumbleSent()
, m_lastTimeRumbleSentValid(false)
{
Expand Down Expand Up @@ -1219,59 +1218,54 @@ void CPSMoveControllerLatest::UpdateTrackingState()

void CPSMoveControllerLatest::UpdateRumbleState()
{
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_rumble_update_rate = 200.f; // Don't bother trying to update the rumble faster than 5fps (200ms)
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)
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
bool bTimoutElapsed= true;

if (m_lastTimeRumbleSentValid)
{
std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
bool bTimoutElapsed= true;
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)
// Unless a zero runble intensity was explicitly set,
// don't rumble less than 35% (no enough to feel)
if (m_pendingHapticPulseDuration != 0)
{
float rumble_fraction = static_cast<float>(m_pendingHapticPulseDuration) / k_max_pulse_microseconds;

// Unless a zero runble intensity was explicitly set,
// don't rumble less than 35% (no enough to feel)
if (m_pendingHapticPulseDuration != 0)
if (rumble_fraction < 0.35f)
{
if (rumble_fraction < 0.35f)
{
// rumble values less 35% isn't noticeable
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
ClientPSMoveAPI::eat_response(ClientPSMoveAPI::set_controller_rumble(m_controller_view, rumble_fraction));
// Actually send the rumble to the server
ClientPSMoveAPI::set_controller_rumble(m_controller_view, rumble_fraction);

// Remember the last rumble we went and when we sent it
m_sentHapticPulseDuration = m_pendingHapticPulseDuration;
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;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/openvr_plugin/driver_psmoveservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class CPSMoveControllerLatest : public CPSMoveTrackedDeviceLatest, public vr::IV

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

0 comments on commit 03f74bc

Please sign in to comment.