@@ -51,7 +51,7 @@ inline void HmdMatrix_SetIdentity( HmdMatrix34_t *pMatrix )
5151
5252
5353// keys for use with the settings API
54- static const char * const k_pch_Sample_Section = " driver_null " ;
54+ static const char * const k_pch_Sample_Section = " tovr " ;
5555static const char * const k_pch_Sample_SerialNumber_String = " serialNumber" ;
5656static const char * const k_pch_Sample_ModelNumber_String = " modelNumber" ;
5757static const char * const k_pch_Sample_WindowX_Int32 = " windowX" ;
@@ -173,7 +173,7 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
173173public:
174174 CSampleDeviceDriver ( )
175175 {
176- m_unObjectId = vr::k_unTrackedDeviceIndexInvalid;
176+ HMDIndex_t = vr::k_unTrackedDeviceIndexInvalid;
177177 m_ulPropertyContainer = vr::k_ulInvalidPropertyContainer;
178178
179179 // DriverLog( "Using settings values\n" );
@@ -227,18 +227,23 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
227227
228228 if (status == ERROR_SUCCESS)
229229 {
230- HMDConnected = true ;
230+
231231 hDll = LoadLibrary (libPath);
232232 GetHMDData = (_GetHMDData)GetProcAddress (hDll, " GetHMDData" );
233233 GetControllersData = (_GetControllersData)GetProcAddress (hDll, " GetControllersData" );
234234 SetControllerData = (_SetControllerData)GetProcAddress (hDll, " SetControllerData" );
235235 SetCentering = (_SetCentering)GetProcAddress (hDll, " SetCentering" );
236236
237- if (GetHMDData == NULL ) HMDConnected = false ;
238- if (SetCentering == NULL ) HMDConnected = false ;
237+ if (GetHMDData != NULL && GetHMDData (&MyHMD) == TOVR_SUCCESS)
238+ HMDConnected = true ;
239239
240240 if (GetControllersData != NULL && SetControllerData !=NULL && GetControllersData (&MyCtrl, &MyCtrl2) == TOVR_SUCCESS)
241241 ctrlsConnected = true ;
242+
243+ if (SetCentering == NULL ) {
244+ HMDConnected = false ;
245+ ctrlsConnected = false ;
246+ }
242247 }
243248 }
244249
@@ -252,9 +257,8 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
252257
253258 virtual EVRInitError Activate ( vr::TrackedDeviceIndex_t unObjectId )
254259 {
255- m_unObjectId = unObjectId;
256- m_ulPropertyContainer = vr::VRProperties ()->TrackedDeviceToPropertyContainer ( m_unObjectId );
257-
260+ HMDIndex_t = unObjectId;
261+ m_ulPropertyContainer = vr::VRProperties ()->TrackedDeviceToPropertyContainer ( HMDIndex_t );
258262
259263 vr::VRProperties ()->SetStringProperty ( m_ulPropertyContainer, Prop_ModelNumber_String, m_sModelNumber.c_str () );
260264 vr::VRProperties ()->SetStringProperty ( m_ulPropertyContainer, Prop_RenderModelName_String, m_sModelNumber.c_str () );
@@ -295,7 +299,7 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
295299 // Thus "Prop_NamedIconPathDeviceAlertLow_String" in each model's block represent a specialization specific for that "model".
296300 // Keys in "Model-v Defaults" are an example of mapping to the same states, and here all map to "Prop_NamedIconPathDeviceOff_String".
297301 //
298- bool bSetupIconUsingExternalResourceFile = true ;
302+ /* bool bSetupIconUsingExternalResourceFile = true;
299303 if ( !bSetupIconUsingExternalResourceFile )
300304 {
301305 // Setup properties directly in code.
@@ -308,14 +312,14 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
308312 vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceNotReady_String, "{null}/icons/headset_sample_status_error.png" );
309313 vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceStandby_String, "{null}/icons/headset_sample_status_standby.png" );
310314 vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceAlertLow_String, "{null}/icons/headset_sample_status_ready_low.png" );
311- }
315+ }*/
312316
313317 return VRInitError_None;
314318 }
315319
316320 virtual void Deactivate ()
317321 {
318- m_unObjectId = vr::k_unTrackedDeviceIndexInvalid;
322+ HMDIndex_t = vr::k_unTrackedDeviceIndexInvalid;
319323 }
320324
321325 virtual void EnterStandby ()
@@ -477,16 +481,16 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
477481 // In a real driver, this should happen from some pose tracking thread.
478482 // The RunFrame interval is unspecified and can be very irregular if some other
479483 // driver blocks it for some periodic task.
480- if ( m_unObjectId != vr::k_unTrackedDeviceIndexInvalid )
484+ if ( HMDIndex_t != vr::k_unTrackedDeviceIndexInvalid )
481485 {
482- vr::VRServerDriverHost ()->TrackedDevicePoseUpdated ( m_unObjectId , GetPose (), sizeof ( DriverPose_t ) );
486+ vr::VRServerDriverHost ()->TrackedDevicePoseUpdated ( HMDIndex_t , GetPose (), sizeof ( DriverPose_t ) );
483487 }
484488 }
485489
486490 std::string GetSerialNumber () const { return m_sSerialNumber; }
487491
488492private:
489- vr::TrackedDeviceIndex_t m_unObjectId ;
493+ vr::TrackedDeviceIndex_t HMDIndex_t ;
490494 vr::PropertyContainerHandle_t m_ulPropertyContainer;
491495
492496 std::string m_sSerialNumber;
@@ -520,7 +524,8 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
520524public:
521525 CSampleControllerDriver ()
522526 {
523- m_unObjectId = vr::k_unTrackedDeviceIndexInvalid;
527+ Ctrl1Index_t = vr::k_unTrackedDeviceIndexInvalid;
528+ Ctrl2Index_t = vr::k_unTrackedDeviceIndexInvalid;
524529 m_ulPropertyContainer = vr::k_ulInvalidPropertyContainer;
525530 }
526531
@@ -535,8 +540,17 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
535540
536541 virtual EVRInitError Activate ( vr::TrackedDeviceIndex_t unObjectId )
537542 {
538- m_unObjectId = unObjectId;
539- m_ulPropertyContainer = vr::VRProperties ()->TrackedDeviceToPropertyContainer ( m_unObjectId );
543+ switch (ControllerIndex)
544+ {
545+ case 1 :
546+ Ctrl1Index_t = unObjectId;
547+ Ctrl1Index_t = vr::VRProperties ()->TrackedDeviceToPropertyContainer (Ctrl1Index_t);
548+ break ;
549+ case 2 :
550+ Ctrl2Index_t = unObjectId;
551+ Ctrl2Index_t = vr::VRProperties ()->TrackedDeviceToPropertyContainer (Ctrl2Index_t);
552+ break ;
553+ }
540554
541555 vr::VRProperties ()->SetStringProperty (m_ulPropertyContainer, vr::Prop_ControllerType_String, " vive_controller" );
542556 vr::VRProperties ()->SetStringProperty (m_ulPropertyContainer, vr::Prop_LegacyInputProfile_String, " vive_controller" );
@@ -585,7 +599,7 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
585599
586600 // this file tells the UI what to show the user for binding this controller as well as what default bindings should
587601 // be for legacy or other apps
588- vr::VRProperties ()->SetStringProperty ( m_ulPropertyContainer, Prop_InputProfilePath_String, " {null }/input/mycontroller_profile.json" );
602+ vr::VRProperties ()->SetStringProperty ( m_ulPropertyContainer, Prop_InputProfilePath_String, " {tovr }/input/mycontroller_profile.json" );
589603
590604 // Buttons handles
591605 vr::VRDriverInput ()->CreateBooleanComponent (m_ulPropertyContainer, " /input/application_menu/click" , &HButtons[0 ]);
@@ -618,7 +632,15 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
618632
619633 virtual void Deactivate ()
620634 {
621- m_unObjectId = vr::k_unTrackedDeviceIndexInvalid;
635+ switch (ControllerIndex)
636+ {
637+ case 1 :
638+ Ctrl1Index_t = vr::k_unTrackedDeviceIndexInvalid;
639+ break ;
640+ case 2 :
641+ Ctrl2Index_t = vr::k_unTrackedDeviceIndexInvalid;
642+ break ;
643+ }
622644 }
623645
624646
@@ -736,9 +758,22 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
736758 SetCentering (2 );
737759 }
738760
739- if (m_unObjectId != vr::k_unTrackedDeviceIndexInvalid)
740- {
741- vr::VRServerDriverHost ()->TrackedDevicePoseUpdated (m_unObjectId, GetPose (), sizeof (DriverPose_t));
761+ if (ControllerIndex == 1 ) {
762+
763+ if (Ctrl1Index_t != vr::k_unTrackedDeviceIndexInvalid)
764+ {
765+ vr::VRServerDriverHost ()->TrackedDevicePoseUpdated (Ctrl1Index_t, GetPose (), sizeof (DriverPose_t));
766+ }
767+
768+ }
769+
770+ if (ControllerIndex == 2 ) {
771+
772+ if (Ctrl2Index_t != vr::k_unTrackedDeviceIndexInvalid)
773+ {
774+ vr::VRServerDriverHost ()->TrackedDevicePoseUpdated (Ctrl2Index_t, GetPose (), sizeof (DriverPose_t));
775+ }
776+
742777 }
743778
744779#endif
@@ -774,7 +809,8 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
774809 }
775810
776811private:
777- vr::TrackedDeviceIndex_t m_unObjectId;
812+ vr::TrackedDeviceIndex_t Ctrl1Index_t;
813+ vr::TrackedDeviceIndex_t Ctrl2Index_t;
778814 vr::PropertyContainerHandle_t m_ulPropertyContainer;
779815
780816 // vr::VRInputComponentHandle_t m_compA;
@@ -815,8 +851,11 @@ EVRInitError CServerDriver_Sample::Init( vr::IVRDriverContext *pDriverContext )
815851 VR_INIT_SERVER_DRIVER_CONTEXT ( pDriverContext );
816852 // InitDriverLog( vr::VRDriverLog() );
817853
818- m_pNullHmdLatest = new CSampleDeviceDriver ();
819- vr::VRServerDriverHost ()->TrackedDeviceAdded ( m_pNullHmdLatest->GetSerialNumber ().c_str (), vr::TrackedDeviceClass_HMD, m_pNullHmdLatest );
854+ // if (HMDConnected)
855+ // {
856+ m_pNullHmdLatest = new CSampleDeviceDriver ();
857+ vr::VRServerDriverHost ()->TrackedDeviceAdded (m_pNullHmdLatest->GetSerialNumber ().c_str (), vr::TrackedDeviceClass_HMD, m_pNullHmdLatest);
858+ // }
820859
821860 if (ctrlsConnected) {
822861 m_pController = new CSampleControllerDriver ();
@@ -834,17 +873,22 @@ EVRInitError CServerDriver_Sample::Init( vr::IVRDriverContext *pDriverContext )
834873
835874void CServerDriver_Sample::Cleanup ()
836875{
837- if (hDll != NULL ) FreeLibrary (hDll);
838- hDll = nullptr ;
839876 // CleanupDriverLog();
840- delete m_pNullHmdLatest;
841- m_pNullHmdLatest = NULL ;
877+ // if (HMDConnected) {
878+ delete m_pNullHmdLatest;
879+ m_pNullHmdLatest = NULL ;
880+ // }
881+
842882 if (ctrlsConnected) {
843883 delete m_pController;
844884 m_pController = NULL ;
845885 delete m_pController2;
846886 m_pController2 = NULL ;
847887 }
888+ if (hDll != NULL ) {
889+ FreeLibrary (hDll);
890+ hDll = nullptr ;
891+ }
848892}
849893
850894
0 commit comments