Skip to content

Commit b20b257

Browse files
committed
OpenVR SDK 1.0.2:
General: * Split several VR_Init error return values out into unique causes. * Added Prop_ControllerRoleHint_Int32, which a controller driver can optionally use to return the best matching ETrackedControllerRole type for the controller. Use this to specify a controller that is physically shaped for one hand only or when the driver is able to determine which hand is holding the controller through sensors or other means. * Added VREvent_OverlayFocusChanged, which is sent when an overlay was under the laser mouse and isn’t anymore or when there was no overlay under the laser mouse and now there is. IVRApplications: * Added LaunchApplicationFromMimeType. This allows the caller (usually Steam) to start the application that is associated with that mime type if it is not already running. If the application is not running it will be started with the specified arguments appended to existing arguments for the app. If the application is already running it will receive VREvent_ApplicationMimeTypeLoad and can retrieve the arguments by passing event.applicationLaunch.unArgsHandle to IVRApplications:: GetApplicationLaunchArguments. * Added other support functions for mime types. IVRCompositor: * Split out Compositor_FrameTiming's m_flSceneRenderGpuMs into m_flPreSubmitGpuMs and m_flPostSubmitGpuMs. Post-Submit time was not previously being recorded. IVROverlay: * Added VROverlayFlags_SortWithNonSceneOverlays. This allows the scene application's overlays to sort with other non-scene overlays. * Added SetOverlayTexelAspect/GetOverlayTexelAspect. This allows an overlay to control the aspect ratio of its texels. By default all overlay texels are square (i.e. 1.0) * Added SetOverlaySortOrder/GetOverlaySortOrder. This allows an overlay to be force to be sorted above or below other overlays. It is most useful for overlays from the scene application that want to explicitly control their draw order. IVRTrackedCamera: * Added accessors to work with tracked camera gpu resources: ** GetVideoStreamTextureSize ** GetVideoStreamTextureD3D11 ** GetVideoStreamTextureGL ** ReleaseVideoStreamTextureGL IVRResources: * New interface to allow access to resource files in the runtime or user-installed drivers. IVRCameraComponent: * Simplified interface by removing duplicate functions already provided by properties and deprecating the arbitrary distortion methods. IClientDriverHost: * Added WatchdogWakeUp. When a client driver is in Watchdog mode it should call this if a hardware event happens that should cause the system to wake up. The Lighthouse driver, for instance, calls this method when a system button is pressed or a controller is turned on. IClientTrackedDeviceProvider: * Added eDriverMode argument to Init. When this is passed as ClientDriverMode_Watchdog the driver should enter a low-power state where hardware is being monitored. If the driver does not support watchdog mode it should return VRInitError_Init_LowPowerWatchdogNotSupported. [git-p4: depot-paths = "//vr/steamvr/sdk_release/": change = 3525698]
1 parent e1507a2 commit b20b257

33 files changed

+2430
-192
lines changed

bin/linux64/libopenvr_api.so

-4.03 KB
Binary file not shown.

bin/linux64/libopenvr_api.so.dbg

-49.7 KB
Binary file not shown.

bin/osx32/libopenvr_api.dylib

-72 Bytes
Binary file not shown.
Binary file not shown.

bin/win32/openvr_api.dll

1.5 KB
Binary file not shown.

bin/win32/openvr_api.pdb

224 KB
Binary file not shown.

bin/win64/openvr_api.dll

2 KB
Binary file not shown.

bin/win64/openvr_api.pdb

224 KB
Binary file not shown.

headers/openvr.h

+148-23
Large diffs are not rendered by default.

headers/openvr_api.cs

+246-32
Large diffs are not rendered by default.

headers/openvr_api.json

+213-26
Large diffs are not rendered by default.

headers/openvr_capi.h

+69-11
Large diffs are not rendered by default.

headers/openvr_driver.h

+81-17
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ enum ETrackedDeviceProperty
277277
Prop_Axis2Type_Int32 = 3004, // Return value is of type EVRControllerAxisType
278278
Prop_Axis3Type_Int32 = 3005, // Return value is of type EVRControllerAxisType
279279
Prop_Axis4Type_Int32 = 3006, // Return value is of type EVRControllerAxisType
280+
Prop_ControllerRoleHint_Int32 = 3007, // Return value is of type ETrackedControllerRole
280281

281282
// Properties that are unique to TrackedDeviceClass_TrackingReference
282283
Prop_FieldOfViewLeftDegrees_Float = 4000,
@@ -346,6 +347,7 @@ enum EVRState
346347
VRState_Ready_Alert = 4,
347348
VRState_NotReady = 5,
348349
VRState_Standby = 6,
350+
VRState_Ready_Alert_Low = 7,
349351
};
350352

351353
/** The types of events that could be posted (and what the parameters mean for each event type) */
@@ -362,6 +364,7 @@ enum EVREventType
362364
VREvent_EnterStandbyMode = 106,
363365
VREvent_LeaveStandbyMode = 107,
364366
VREvent_TrackedDeviceRoleChanged = 108,
367+
VREvent_WatchdogWakeUpRequested = 109,
365368

366369
VREvent_ButtonPress = 200, // data is controller
367370
VREvent_ButtonUnpress = 201, // data is controller
@@ -375,6 +378,7 @@ enum EVREventType
375378
VREvent_FocusLeave = 304, // data is overlay
376379
VREvent_Scroll = 305, // data is mouse
377380
VREvent_TouchPadMove = 306, // data is mouse
381+
VREvent_OverlayFocusChanged = 307, // data is overlay, global event
378382

379383
VREvent_InputFocusCaptured = 400, // data is process DEPRECATED
380384
VREvent_InputFocusReleased = 401, // data is process DEPRECATED
@@ -412,6 +416,7 @@ enum EVREventType
412416
VREvent_ScreenshotTaken = 521, // Sent by compositor to the application that the screenshot has been taken
413417
VREvent_ScreenshotFailed = 522, // Sent by compositor to the application that the screenshot failed to be taken
414418
VREvent_SubmitScreenshotToDashboard = 523, // Sent by compositor to the dashboard that a completed screenshot was submitted
419+
VREvent_ScreenshotProgressToDashboard = 524, // Sent by compositor to the dashboard that a completed screenshot was submitted
415420

416421
VREvent_Notification_Shown = 600,
417422
VREvent_Notification_Hidden = 601,
@@ -453,6 +458,7 @@ enum EVREventType
453458
VREvent_ApplicationTransitionAborted = 1301,
454459
VREvent_ApplicationTransitionNewAppStarted = 1302,
455460
VREvent_ApplicationListUpdated = 1303,
461+
VREvent_ApplicationMimeTypeLoad = 1304,
456462

457463
VREvent_Compositor_MirrorWindowShown = 1400,
458464
VREvent_Compositor_MirrorWindowHidden = 1401,
@@ -634,6 +640,17 @@ struct VREvent_Screenshot_t
634640
uint32_t type;
635641
};
636642

643+
struct VREvent_ScreenshotProgress_t
644+
{
645+
float progress;
646+
};
647+
648+
struct VREvent_ApplicationLaunch_t
649+
{
650+
uint32_t pid;
651+
uint32_t unArgsHandle;
652+
};
653+
637654
/** If you change this you must manually update openvr_interop.cs.py */
638655
typedef union
639656
{
@@ -652,6 +669,8 @@ typedef union
652669
VREvent_TouchPadMove_t touchPadMove;
653670
VREvent_SeatedZeroPoseReset_t seatedZeroPoseReset;
654671
VREvent_Screenshot_t screenshot;
672+
VREvent_ScreenshotProgress_t screenshotProgress;
673+
VREvent_ApplicationLaunch_t applicationLaunch;
655674
} VREvent_Data_t;
656675

657676
/** An event posted by the server to all running applications */
@@ -795,6 +814,9 @@ enum EVRApplicationType
795814
VRApplication_Utility = 4, // Init should not try to load any drivers. The application needs access to utility
796815
// interfaces (like IVRSettings and IVRApplications) but not hardware.
797816
VRApplication_VRMonitor = 5, // Reserved for vrmonitor
817+
VRApplication_SteamWatchdog = 6,// Reserved for Steam
818+
819+
VRApplication_Max
798820
};
799821

800822

@@ -851,6 +873,14 @@ enum EVRInitError
851873
VRInitError_Init_NotSupportedWithCompositor = 122,
852874
VRInitError_Init_NotAvailableToUtilityApps = 123,
853875
VRInitError_Init_Internal = 124,
876+
VRInitError_Init_HmdDriverIdIsNone = 125,
877+
VRInitError_Init_HmdNotFoundPresenceFailed = 126,
878+
VRInitError_Init_VRMonitorNotFound = 127,
879+
VRInitError_Init_VRMonitorStartupFailed = 128,
880+
VRInitError_Init_LowPowerWatchdogNotSupported = 129,
881+
VRInitError_Init_InvalidApplicationType = 130,
882+
VRInitError_Init_NotAvailableToWatchdogApps = 131,
883+
VRInitError_Init_WatchdogDisabledInSettings = 132,
854884

855885
VRInitError_Driver_Failed = 200,
856886
VRInitError_Driver_Unknown = 201,
@@ -861,13 +891,20 @@ enum EVRInitError
861891
VRInitError_Driver_NotCalibrated = 206,
862892
VRInitError_Driver_CalibrationInvalid = 207,
863893
VRInitError_Driver_HmdDisplayNotFound = 208,
864-
894+
VRInitError_Driver_TrackedDeviceInterfaceUnknown = 209,
895+
// VRInitError_Driver_HmdDisplayNotFoundAfterFix = 210, // not needed: here for historic reasons
896+
VRInitError_Driver_HmdDriverIdOutOfBounds = 211,
897+
VRInitError_Driver_HmdDisplayMirrored = 212,
898+
865899
VRInitError_IPC_ServerInitFailed = 300,
866900
VRInitError_IPC_ConnectFailed = 301,
867901
VRInitError_IPC_SharedStateInitFailed = 302,
868902
VRInitError_IPC_CompositorInitFailed = 303,
869903
VRInitError_IPC_MutexInitFailed = 304,
870904
VRInitError_IPC_Failed = 305,
905+
VRInitError_IPC_CompositorConnectFailed = 306,
906+
VRInitError_IPC_CompositorInvalidConnectResponse = 307,
907+
VRInitError_IPC_ConnectFailedAfterMultipleAttempts = 308,
871908

872909
VRInitError_Compositor_Failed = 400,
873910
VRInitError_Compositor_D3D11HardwareRequired = 401,
@@ -971,7 +1008,7 @@ static const uint32_t k_unScreenshotHandleInvalid = 0;
9711008
#define VR_INTERFACE extern "C" __declspec( dllimport )
9721009
#endif
9731010

974-
#elif defined(GNUC) || defined(COMPILER_GCC) || defined(__APPLE__)
1011+
#elif defined(__GNUC__) || defined(COMPILER_GCC) || defined(__APPLE__)
9751012

9761013
#ifdef VR_API_EXPORT
9771014
#define VR_INTERFACE extern "C" __attribute__((visibility("default")))
@@ -995,6 +1032,25 @@ static const uint32_t k_unScreenshotHandleInvalid = 0;
9951032
#endif // _INCLUDE_VRTYPES_H
9961033

9971034

1035+
// vrannotation.h
1036+
#ifdef API_GEN
1037+
# define VR_CLANG_ATTR(ATTR) __attribute__((annotate( ATTR )))
1038+
#else
1039+
# define VR_CLANG_ATTR(ATTR)
1040+
#endif
1041+
1042+
#define VR_METHOD_DESC(DESC) VR_CLANG_ATTR( "desc:" #DESC ";" )
1043+
#define VR_IGNOREATTR() VR_CLANG_ATTR( "ignore" )
1044+
#define VR_OUT_STRUCT() VR_CLANG_ATTR( "out_struct: ;" )
1045+
#define VR_OUT_STRING() VR_CLANG_ATTR( "out_string: ;" )
1046+
#define VR_OUT_ARRAY_CALL(COUNTER,FUNCTION,PARAMS) VR_CLANG_ATTR( "out_array_call:" #COUNTER "," #FUNCTION "," #PARAMS ";" )
1047+
#define VR_OUT_ARRAY_COUNT(COUNTER) VR_CLANG_ATTR( "out_array_count:" #COUNTER ";" )
1048+
#define VR_ARRAY_COUNT(COUNTER) VR_CLANG_ATTR( "array_count:" #COUNTER ";" )
1049+
#define VR_ARRAY_COUNT_D(COUNTER, DESC) VR_CLANG_ATTR( "array_count:" #COUNTER ";desc:" #DESC )
1050+
#define VR_BUFFER_COUNT(COUNTER) VR_CLANG_ATTR( "buffer_count:" #COUNTER ";" )
1051+
#define VR_OUT_BUFFER_COUNT(COUNTER) VR_CLANG_ATTR( "out_buffer_count:" #COUNTER ";" )
1052+
#define VR_OUT_STRING_COUNT(COUNTER) VR_CLANG_ATTR( "out_string_count:" #COUNTER ";" )
1053+
9981054
// vrtrackedcameratypes.h
9991055
#ifndef _VRTRACKEDCAMERATYPES_H
10001056
#define _VRTRACKEDCAMERATYPES_H
@@ -1121,7 +1177,7 @@ namespace vr
11211177
virtual void SetInt32( const char *pchSection, const char *pchSettingsKey, int32_t nValue, EVRSettingsError *peError = nullptr ) = 0;
11221178
virtual float GetFloat( const char *pchSection, const char *pchSettingsKey, float flDefaultValue, EVRSettingsError *peError = nullptr ) = 0;
11231179
virtual void SetFloat( const char *pchSection, const char *pchSettingsKey, float flValue, EVRSettingsError *peError = nullptr ) = 0;
1124-
virtual void GetString( const char *pchSection, const char *pchSettingsKey, char *pchValue, uint32_t unValueLen, const char *pchDefaultValue, EVRSettingsError *peError = nullptr ) = 0;
1180+
virtual void GetString( const char *pchSection, const char *pchSettingsKey, VR_OUT_STRING() char *pchValue, uint32_t unValueLen, const char *pchDefaultValue, EVRSettingsError *peError = nullptr ) = 0;
11251181
virtual void SetString( const char *pchSection, const char *pchSettingsKey, const char *pchValue, EVRSettingsError *peError = nullptr ) = 0;
11261182

11271183
virtual void RemoveSection( const char *pchSection, EVRSettingsError *peError = nullptr ) = 0;
@@ -1170,6 +1226,10 @@ namespace vr
11701226
static const char * const k_pch_SteamVR_ForceFadeOnBadTracking_Bool = "forceFadeOnBadTracking";
11711227
static const char * const k_pch_SteamVR_DefaultMirrorView_Int32 = "defaultMirrorView";
11721228
static const char * const k_pch_SteamVR_ShowMirrorView_Bool = "showMirrorView";
1229+
static const char * const k_pch_SteamVR_StartMonitorFromAppLaunch = "startMonitorFromAppLaunch";
1230+
static const char * const k_pch_SteamVR_AutoLaunchSteamVROnButtonPress = "autoLaunchSteamVROnButtonPress";
1231+
static const char * const k_pch_SteamVR_UseGenericGraphcisDevice_Bool = "useGenericGraphicsDevice";
1232+
11731233

11741234
//-----------------------------------------------------------------------------
11751235
// lighthouse keys
@@ -1205,7 +1265,8 @@ namespace vr
12051265
// user interface keys
12061266
static const char * const k_pch_UserInterface_Section = "userinterface";
12071267
static const char * const k_pch_UserInterface_StatusAlwaysOnTop_Bool = "StatusAlwaysOnTop";
1208-
static const char * const k_pch_UserInterface_EnableScreenshots_Bool = "EnableScreenshots";
1268+
static const char * const k_pch_UserInterface_Screenshots_Bool = "screenshots";
1269+
static const char * const k_pch_UserInterface_ScreenshotType_Int = "screenshotType";
12091270

12101271
//-----------------------------------------------------------------------------
12111272
// notification keys
@@ -1543,7 +1604,6 @@ namespace vr
15431604
// ivrcameracomponent.h
15441605
namespace vr
15451606
{
1546-
15471607
//-----------------------------------------------------------------------------
15481608
//-----------------------------------------------------------------------------
15491609
class ICameraVideoSinkCallback
@@ -1561,28 +1621,21 @@ namespace vr
15611621
// ------------------------------------
15621622
// Camera Methods
15631623
// ------------------------------------
1564-
virtual bool HasCamera() = 0;
1565-
virtual bool GetCameraFirmwareDescription( char *pBuffer, uint32_t nBufferLen ) = 0;
15661624
virtual bool GetCameraFrameDimensions( vr::ECameraVideoStreamFormat nVideoStreamFormat, uint32_t *pWidth, uint32_t *pHeight ) = 0;
15671625
virtual bool GetCameraFrameBufferingRequirements( int *pDefaultFrameQueueSize, uint32_t *pFrameBufferDataSize ) = 0;
15681626
virtual bool SetCameraFrameBuffering( int nFrameBufferCount, void **ppFrameBuffers, uint32_t nFrameBufferDataSize ) = 0;
15691627
virtual bool SetCameraVideoStreamFormat( vr::ECameraVideoStreamFormat nVideoStreamFormat ) = 0;
15701628
virtual vr::ECameraVideoStreamFormat GetCameraVideoStreamFormat() = 0;
15711629
virtual bool StartVideoStream() = 0;
15721630
virtual void StopVideoStream() = 0;
1573-
virtual bool IsVideoStreamActive() = 0;
1574-
virtual float GetVideoStreamElapsedTime() = 0;
1631+
virtual bool IsVideoStreamActive( bool *pbPaused, float *pflElapsedTime ) = 0;
15751632
virtual const vr::CameraVideoStreamFrame_t *GetVideoStreamFrame() = 0;
15761633
virtual void ReleaseVideoStreamFrame( const vr::CameraVideoStreamFrame_t *pFrameImage ) = 0;
15771634
virtual bool SetAutoExposure( bool bEnable ) = 0;
15781635
virtual bool PauseVideoStream() = 0;
15791636
virtual bool ResumeVideoStream() = 0;
1580-
virtual bool IsVideoStreamPaused() = 0;
15811637
virtual bool GetCameraDistortion( float flInputU, float flInputV, float *pflOutputU, float *pflOutputV ) = 0;
1582-
virtual bool GetCameraProjection( float flWidthPixels, float flHeightPixels, float flZNear, float flZFar, vr::HmdMatrix44_t *pProjection ) = 0;
1583-
virtual bool GetRecommendedCameraUndistortion( uint32_t *pUndistortionWidthPixels, uint32_t *pUndistortionHeightPixels ) = 0;
1584-
virtual bool SetCameraUndistortion( uint32_t nUndistortionWidthPixels, uint32_t nUndistortionHeightPixels ) = 0;
1585-
virtual bool GetCameraFirmwareVersion( uint64_t *pFirmwareVersion ) = 0;
1638+
virtual bool GetCameraProjection( vr::EVRTrackedCameraFrameType eFrameType, float flZNear, float flZFar, vr::HmdMatrix44_t *pProjection ) = 0;
15861639
virtual bool SetFrameRate( int nISPFrameRate, int nSensorFrameRate ) = 0;
15871640
virtual bool SetCameraVideoSinkCallback( vr::ICameraVideoSinkCallback *pCameraVideoSinkCallback ) = 0;
15881641
virtual bool GetCameraCompatibilityMode( vr::ECameraCompatibilityMode *pCameraCompatibilityMode ) = 0;
@@ -1591,7 +1644,7 @@ namespace vr
15911644
virtual bool GetCameraIntrinsics( vr::EVRTrackedCameraFrameType eFrameType, HmdVector2_t *pFocalLength, HmdVector2_t *pCenter ) = 0;
15921645
};
15931646

1594-
static const char *IVRCameraComponent_Version = "IVRCameraComponent_001";
1647+
static const char *IVRCameraComponent_Version = "IVRCameraComponent_002";
15951648
}
15961649
// itrackeddevicedriverprovider.h
15971650
namespace vr
@@ -1754,9 +1807,20 @@ class IClientDriverHost
17541807

17551808
/** always returns a pointer to a valid interface pointer of IVRSettings */
17561809
virtual IVRSettings *GetSettings( const char *pchInterfaceVersion ) = 0;
1810+
1811+
/** Client drivers in watchdog mode should call this when they have received a signal from hardware that should
1812+
* cause SteamVR to start */
1813+
virtual void WatchdogWakeUp() = 0;
17571814
};
17581815

17591816

1817+
/** Defines the mode that the client driver should start in. */
1818+
enum EClientDriverMode
1819+
{
1820+
ClientDriverMode_Normal = 0,
1821+
ClientDriverMode_Watchdog = 1, // client should return VRInitError_Init_LowPowerWatchdogNotSupported if it can't support this mode
1822+
};
1823+
17601824

17611825
/** This interface must be implemented in each driver. It will be loaded in vrclient.dll */
17621826
class IClientTrackedDeviceProvider
@@ -1772,7 +1836,7 @@ class IClientTrackedDeviceProvider
17721836
* config files.
17731837
* pchDriverInstallDir - The absolute path of the root directory for the driver.
17741838
*/
1775-
virtual EVRInitError Init( IDriverLog *pDriverLog, vr::IClientDriverHost *pDriverHost, const char *pchUserDriverConfigDir, const char *pchDriverInstallDir ) = 0;
1839+
virtual EVRInitError Init( EClientDriverMode eDriverMode, IDriverLog *pDriverLog, vr::IClientDriverHost *pDriverHost, const char *pchUserDriverConfigDir, const char *pchDriverInstallDir ) = 0;
17761840

17771841
/** cleans up the driver right before it is unloaded */
17781842
virtual void Cleanup() = 0;
@@ -1800,7 +1864,7 @@ class IClientTrackedDeviceProvider
18001864
virtual uint32_t GetMCImage( uint32_t *pImgWidth, uint32_t *pImgHeight, uint32_t *pChannels, void *pDataBuffer, uint32_t unBufferLen ) = 0;
18011865
};
18021866

1803-
static const char *IClientTrackedDeviceProvider_Version = "IClientTrackedDeviceProvider_003";
1867+
static const char *IClientTrackedDeviceProvider_Version = "IClientTrackedDeviceProvider_004";
18041868

18051869
}
18061870

lib/linux64/libopenvr_api.so

-50.7 KB
Binary file not shown.

lib/win32/openvr_api.lib

0 Bytes
Binary file not shown.

lib/win64/openvr_api.lib

0 Bytes
Binary file not shown.

samples/bin/linux64/libopenvr_api.so

371 KB
Binary file not shown.

samples/bin/osx32/libopenvr_api.dylib

293 KB
Binary file not shown.

samples/bin/win32/openvr_api.dll

1.5 KB
Binary file not shown.

samples/bin/win64/openvr_api.dll

2 KB
Binary file not shown.

samples/driver_sample/driver_sample.cpp

+71-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
#include "driverlog.h"
55

66
#include <vector>
7+
#include <thread>
8+
#include <chrono>
9+
10+
#if defined( _WINDOWS )
11+
#include <Windows.h>
12+
#endif
713

814
using namespace vr;
915

@@ -70,33 +76,61 @@ class CClientDriver_Sample : public IClientTrackedDeviceProvider
7076
: m_bEnableNullDriver( false )
7177
, m_bInit( false )
7278
{
79+
m_eDriverMode = ClientDriverMode_Normal;
80+
m_pWatchdogThread = nullptr;
7381
}
7482

75-
virtual EVRInitError Init( vr::IDriverLog *pDriverLog, vr::IClientDriverHost *pDriverHost, const char *pchUserDriverConfigDir, const char *pchDriverInstallDir ) ;
83+
virtual EVRInitError Init( vr::EClientDriverMode eDriverMode, vr::IDriverLog *pDriverLog, vr::IClientDriverHost *pDriverHost, const char *pchUserDriverConfigDir, const char *pchDriverInstallDir ) ;
7684
virtual void Cleanup() ;
7785
virtual bool BIsHmdPresent( const char *pchUserDriverConfigDir ) ;
7886
virtual EVRInitError SetDisplayId( const char *pchDisplayId ) { return VRInitError_None; } // Null doesn't care
7987
virtual HiddenAreaMesh_t GetHiddenAreaMesh( EVREye eEye ) ;
8088
virtual uint32_t GetMCImage( uint32_t *pImgWidth, uint32_t *pImgHeight, uint32_t *pChannels, void *pDataBuffer, uint32_t unBufferLen ) { return 0; }
8189

90+
void WatchdogWakeUp();
8291
private:
8392
vr::IClientDriverHost *m_pClientDriverHost;
8493

8594
bool m_bEnableNullDriver;
8695
bool m_bInit;
96+
vr::EClientDriverMode m_eDriverMode;
97+
std::thread *m_pWatchdogThread;
8798
};
8899

89100
CClientDriver_Sample g_clientDriverNull;
90101

91102

92-
EVRInitError CClientDriver_Sample::Init( vr::IDriverLog *pDriverLog, vr::IClientDriverHost *pDriverHost, const char *pchUserDriverConfigDir, const char *pchDriverInstallDir )
103+
bool g_bExiting = false;
104+
105+
void WatchdogThreadFunction( )
106+
{
107+
while ( !g_bExiting )
108+
{
109+
#if defined( _WINDOWS )
110+
// on windows send the event when the Y key is pressed.
111+
if ( (0x01 & GetAsyncKeyState( 'Y' )) != 0 )
112+
{
113+
// Y key was pressed.
114+
g_clientDriverNull.WatchdogWakeUp();
115+
}
116+
std::this_thread::sleep_for( std::chrono::microseconds( 500 ) );
117+
#else
118+
// for the other platforms, just send one every five seconds
119+
std::this_thread::sleep_for( std::chrono::seconds( 5 ) );
120+
g_clientDriverNull.WatchdogWakeUp();
121+
#endif
122+
}
123+
}
124+
125+
EVRInitError CClientDriver_Sample::Init( vr::EClientDriverMode eDriverMode, vr::IDriverLog *pDriverLog, vr::IClientDriverHost *pDriverHost, const char *pchUserDriverConfigDir, const char *pchDriverInstallDir )
93126
{
94127
m_pClientDriverHost = pDriverHost;
95128
InitDriverLog( pDriverLog );
96129

130+
m_eDriverMode = eDriverMode;
131+
97132
if ( !m_bInit )
98133
{
99-
100134
if ( m_pClientDriverHost )
101135
{
102136
IVRSettings *pSettings = m_pClientDriverHost->GetSettings( vr::IVRSettings_Version );
@@ -109,12 +143,46 @@ EVRInitError CClientDriver_Sample::Init( vr::IDriverLog *pDriverLog, vr::IClient
109143
m_bInit = true;
110144
}
111145

146+
if ( eDriverMode == ClientDriverMode_Watchdog )
147+
{
148+
if ( !m_bEnableNullDriver )
149+
{
150+
return VRInitError_Init_LowPowerWatchdogNotSupported;
151+
}
152+
153+
// Watchdog mode on Windows starts a thread that listens for the 'Y' key on the keyboard to
154+
// be pressed. A real driver should wait for a system button event or something else from the
155+
// the hardware that signals that the VR system should start up.
156+
g_bExiting = false;
157+
m_pWatchdogThread = new std::thread( WatchdogThreadFunction );
158+
if ( !m_pWatchdogThread )
159+
{
160+
DriverLog( "Unable to create watchdog thread\n");
161+
return VRInitError_Driver_Failed;
162+
}
163+
}
164+
112165
return VRInitError_None;
113166
}
114167

115168

169+
void CClientDriver_Sample::WatchdogWakeUp()
170+
{
171+
if ( m_pClientDriverHost )
172+
m_pClientDriverHost->WatchdogWakeUp();
173+
}
174+
175+
116176
void CClientDriver_Sample::Cleanup()
117177
{
178+
g_bExiting = true;
179+
if ( m_pWatchdogThread )
180+
{
181+
m_pWatchdogThread->join();
182+
delete m_pWatchdogThread;
183+
m_pWatchdogThread = nullptr;
184+
}
185+
118186
CleanupDriverLog();
119187
}
120188

0 commit comments

Comments
 (0)