Skip to content

Commit 2e3bf41

Browse files
committed
Improvements and fixes
1 parent 0cb7ca3 commit 2e3bf41

File tree

9 files changed

+2616
-981
lines changed

9 files changed

+2616
-981
lines changed

OpenVR/headers/openvr.h

Lines changed: 457 additions & 238 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_api.cs

Lines changed: 1087 additions & 221 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_api.json

Lines changed: 424 additions & 183 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_capi.h

Lines changed: 239 additions & 116 deletions
Large diffs are not rendered by default.

OpenVR/headers/openvr_driver.h

Lines changed: 281 additions & 70 deletions
Large diffs are not rendered by default.

OpenVR/samples/driver_sample/driver_sample.cpp

Lines changed: 89 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -211,43 +211,6 @@ class CSampleDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IV
211211
DriverLog( "driver_null: Display Frequency: %f\n", m_flDisplayFrequency );
212212
DriverLog( "driver_null: IPD: %f\n", m_flIPD );*/
213213

214-
CRegKey key;
215-
TCHAR libPath[MAX_PATH];
216-
217-
LONG status = key.Open(HKEY_CURRENT_USER, _T("Software\\TrueOpenVR"));
218-
if (status == ERROR_SUCCESS)
219-
{
220-
ULONG libPathSize = sizeof(libPath);
221-
222-
#ifdef _WIN64
223-
status = key.QueryStringValue(_T("Library64"), libPath, &libPathSize);
224-
#else
225-
status = key.QueryStringValue(_T("Library"), libPath, &libPathSize);
226-
#endif
227-
228-
if (status == ERROR_SUCCESS)
229-
{
230-
231-
hDll = LoadLibrary(libPath);
232-
GetHMDData = (_GetHMDData)GetProcAddress(hDll, "GetHMDData");
233-
GetControllersData = (_GetControllersData)GetProcAddress(hDll, "GetControllersData");
234-
SetControllerData = (_SetControllerData)GetProcAddress(hDll, "SetControllerData");
235-
SetCentering = (_SetCentering)GetProcAddress(hDll, "SetCentering");
236-
237-
if (GetHMDData != NULL && GetHMDData(&MyHMD) == TOVR_SUCCESS)
238-
HMDConnected = true;
239-
240-
if (GetControllersData != NULL && SetControllerData !=NULL && GetControllersData(&MyCtrl, &MyCtrl2) == TOVR_SUCCESS)
241-
ctrlsConnected = true;
242-
243-
if (SetCentering == NULL) {
244-
HMDConnected = false;
245-
ctrlsConnected = false;
246-
}
247-
}
248-
}
249-
250-
key.Close();
251214
}
252215

253216
virtual ~CSampleDeviceDriver()
@@ -540,92 +503,68 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
540503

541504
virtual EVRInitError Activate( vr::TrackedDeviceIndex_t unObjectId )
542505
{
506+
543507
switch (ControllerIndex)
544508
{
545509
case 1:
546510
Ctrl1Index_t = unObjectId;
547-
Ctrl1Index_t = vr::VRProperties()->TrackedDeviceToPropertyContainer(Ctrl1Index_t);
511+
m_ulPropertyContainer = vr::VRProperties()->TrackedDeviceToPropertyContainer(Ctrl1Index_t);
512+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, Prop_SerialNumber_String, "CTRL1Serial");
513+
vr::VRProperties()->SetInt32Property(m_ulPropertyContainer, Prop_ControllerRoleHint_Int32, TrackedControllerRole_LeftHand);
548514
break;
549515
case 2:
550516
Ctrl2Index_t = unObjectId;
551-
Ctrl2Index_t = vr::VRProperties()->TrackedDeviceToPropertyContainer(Ctrl2Index_t);
517+
m_ulPropertyContainer = vr::VRProperties()->TrackedDeviceToPropertyContainer(Ctrl2Index_t);
518+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, Prop_SerialNumber_String, "CTRL2Serial");
519+
vr::VRProperties()->SetInt32Property(m_ulPropertyContainer, Prop_ControllerRoleHint_Int32, TrackedControllerRole_RightHand);
552520
break;
553521
}
554522

555523
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_ControllerType_String, "vive_controller");
556-
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_LegacyInputProfile_String, "vive_controller");
557524

558525
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_ModelNumber_String, "ViveMV");
559526
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_ManufacturerName_String, "HTC");
560527
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_RenderModelName_String, "vr_controller_vive_1_5");
561528

562529
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, Prop_TrackingSystemName_String, "VR Controller");
563-
vr::VRProperties()->SetInt32Property(m_ulPropertyContainer, Prop_DeviceClass_Int32, TrackedDeviceClass_Controller);
564530

565-
switch (ControllerIndex)
566-
{
567-
case 1:
568-
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, Prop_SerialNumber_String, "CTRL1Serial");
569-
break;
570-
case 2:
571-
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, Prop_SerialNumber_String, "CTRL2Serial");
572-
break;
573-
}
574-
575-
uint64_t supportedButtons = 0xFFFFFFFFFFFFFFFFULL;
531+
uint64_t supportedButtons = 0xA4;
576532
vr::VRProperties()->SetUint64Property(m_ulPropertyContainer, vr::Prop_SupportedButtons_Uint64, supportedButtons);
577533

578-
// return a constant that's not 0 (invalid) or 1 (reserved for Oculus)
579-
//vr::VRProperties()->SetUint64Property( m_ulPropertyContainer, Prop_CurrentUniverseId_Uint64, 2 );
580-
581534
// avoid "not fullscreen" warnings from vrmonitor
582-
//vr::VRProperties()->SetBoolProperty( m_ulPropertyContainer, Prop_IsOnDesktop_Bool, false );
583-
584-
// our sample device isn't actually tracked, so set this property to avoid having the icon blink in the status window
585-
//vr::VRProperties()->SetBoolProperty( m_ulPropertyContainer, Prop_NeverTracked_Bool, false );
535+
vr::VRProperties()->SetBoolProperty(m_ulPropertyContainer, Prop_IsOnDesktop_Bool, false);
586536

587-
// even though we won't ever track we want to pretend to be the right hand so binding will work as expected
537+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, Prop_InputProfilePath_String, "{tovr}/input/controller_profile.json");
588538

589-
switch (ControllerIndex)
539+
/*bool bSetupIconUsingExternalResourceFile = false;
540+
if (!bSetupIconUsingExternalResourceFile)
590541
{
591-
case 1:
592-
vr::VRProperties()->SetInt32Property(m_ulPropertyContainer, Prop_ControllerRoleHint_Int32, TrackedControllerRole_LeftHand);
593-
break;
594-
case 2:
595-
vr::VRProperties()->SetInt32Property(m_ulPropertyContainer, Prop_ControllerRoleHint_Int32, TrackedControllerRole_RightHand);
596-
break;
597-
}
598-
542+
// Setup properties directly in code.
543+
// Path values are of the form {drivername}\icons\some_icon_filename.png
544+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceOff_String, "{tovr}/icons/barebones_status_off.png");
545+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReady_String, "{tovr}/icons/barebones_status_ready.png");
546+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceReadyAlert_String, "{tovr}/icons/barebones_status_ready_alert.png");
547+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceNotReady_String, "{tovr}/icons/barebones_status_error.png");
548+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceStandby_String, "{tovr}/icons/barebones_status_standby.png");
549+
vr::VRProperties()->SetStringProperty(m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceAlertLow_String, "{tovr}/icons/barebones_status_ready_low.png");
550+
}*/
599551

600-
// this file tells the UI what to show the user for binding this controller as well as what default bindings should
601-
// be for legacy or other apps
602-
vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, Prop_InputProfilePath_String, "{tovr}/input/mycontroller_profile.json" );
552+
vr::VRDriverInput()->CreateScalarComponent( m_ulPropertyContainer, "/input/trackpad/x", &HAnalog[0], vr::VRScalarType_Absolute, vr::VRScalarUnits_NormalizedTwoSided);
553+
vr::VRDriverInput()->CreateScalarComponent(m_ulPropertyContainer, "/input/trackpad/y", &HAnalog[1], vr::VRScalarType_Absolute, vr::VRScalarUnits_NormalizedTwoSided);
554+
vr::VRDriverInput()->CreateScalarComponent(m_ulPropertyContainer, "/input/trigger/value", &HAnalog[2], vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided);
603555

604556
// Buttons handles
605557
vr::VRDriverInput()->CreateBooleanComponent(m_ulPropertyContainer, "/input/application_menu/click", &HButtons[0]);
606-
vr::VRDriverInput()->CreateBooleanComponent(m_ulPropertyContainer, "/input/grip/click", &HButtons[1]);
607558
vr::VRDriverInput()->CreateBooleanComponent(m_ulPropertyContainer, "/input/system/click", &HButtons[2]);
559+
560+
vr::VRDriverInput()->CreateBooleanComponent(m_ulPropertyContainer, "/input/grip/click", &HButtons[1]);
561+
vr::VRDriverInput()->CreateBooleanComponent(m_ulPropertyContainer, "/input/trigger/click", &HButtons[5]);
562+
608563
vr::VRDriverInput()->CreateBooleanComponent(m_ulPropertyContainer, "/input/trackpad/click", &HButtons[3]);
609564
vr::VRDriverInput()->CreateBooleanComponent(m_ulPropertyContainer, "/input/trackpad/touch", &HButtons[4]);
610565

611-
// Analog handles
612-
vr::VRDriverInput()->CreateScalarComponent(
613-
m_ulPropertyContainer, "/input/trackpad/x", &HAnalog[0],
614-
vr::VRScalarType_Absolute, vr::VRScalarUnits_NormalizedTwoSided
615-
);
616-
vr::VRDriverInput()->CreateScalarComponent(
617-
m_ulPropertyContainer, "/input/trackpad/y", &HAnalog[1],
618-
vr::VRScalarType_Absolute, vr::VRScalarUnits_NormalizedTwoSided
619-
);
620-
vr::VRDriverInput()->CreateScalarComponent(
621-
m_ulPropertyContainer, "/input/trigger/value", &HAnalog[2],
622-
vr::EVRScalarType::VRScalarType_Absolute, vr::EVRScalarUnits::VRScalarUnits_NormalizedOneSided
623-
);
624-
625-
vr::VRProperties()->SetInt32Property(m_ulPropertyContainer, vr::Prop_Axis0Type_Int32, vr::k_eControllerAxis_TrackPad);
626-
627566
// create our haptic component
628-
vr::VRDriverInput()->CreateHapticComponent( m_ulPropertyContainer, "/output/haptic", &m_compHaptic);
567+
vr::VRDriverInput()->CreateHapticComponent(m_ulPropertyContainer, "/output/haptic", &m_compHaptic);
629568

630569
return VRInitError_None;
631570
}
@@ -707,7 +646,22 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
707646

708647
void RunFrame()
709648
{
710-
#if defined( _WINDOWS )
649+
switch (ControllerIndex)
650+
{
651+
case 1:
652+
if (Ctrl1Index_t != vr::k_unTrackedDeviceIndexInvalid)
653+
{
654+
vr::VRServerDriverHost()->TrackedDevicePoseUpdated(Ctrl1Index_t, GetPose(), sizeof(DriverPose_t));
655+
}
656+
break;
657+
case 2:
658+
if (Ctrl2Index_t != vr::k_unTrackedDeviceIndexInvalid)
659+
{
660+
vr::VRServerDriverHost()->TrackedDevicePoseUpdated(Ctrl2Index_t, GetPose(), sizeof(DriverPose_t));
661+
}
662+
break;
663+
}
664+
711665
// Your driver would read whatever hardware state is associated with its input components and pass that
712666
// in to UpdateBooleanComponent. This could happen in RunFrame or on a thread of your own that's reading USB
713667
// state. There's no need to update input state unless it changes, but it doesn't do any harm to do so.
@@ -758,25 +712,6 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
758712
SetCentering(2);
759713
}
760714

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-
777-
}
778-
779-
#endif
780715
}
781716

782717
void ProcessEvent( const vr::VREvent_t & vrEvent )
@@ -818,7 +753,7 @@ class CSampleControllerDriver : public vr::ITrackedDeviceServerDriver
818753
//vr::VRInputComponentHandle_t m_compC;
819754
vr::VRInputComponentHandle_t m_compHaptic;
820755

821-
vr::VRInputComponentHandle_t HButtons[5], HAnalog[3];
756+
vr::VRInputComponentHandle_t HButtons[6], HAnalog[3];
822757
//std::string m_sSerialNumber;
823758
//std::string m_sModelNumber;
824759
};
@@ -851,11 +786,49 @@ EVRInitError CServerDriver_Sample::Init( vr::IVRDriverContext *pDriverContext )
851786
VR_INIT_SERVER_DRIVER_CONTEXT( pDriverContext );
852787
//InitDriverLog( vr::VRDriverLog() );
853788

854-
//if (HMDConnected)
855-
//{
789+
CRegKey key;
790+
TCHAR libPath[MAX_PATH];
791+
792+
LONG status = key.Open(HKEY_CURRENT_USER, _T("Software\\TrueOpenVR"));
793+
if (status == ERROR_SUCCESS)
794+
{
795+
ULONG libPathSize = sizeof(libPath);
796+
797+
#ifdef _WIN64
798+
status = key.QueryStringValue(_T("Library64"), libPath, &libPathSize);
799+
#else
800+
status = key.QueryStringValue(_T("Library"), libPath, &libPathSize);
801+
#endif
802+
803+
if (status == ERROR_SUCCESS)
804+
{
805+
806+
hDll = LoadLibrary(libPath);
807+
GetHMDData = (_GetHMDData)GetProcAddress(hDll, "GetHMDData");
808+
GetControllersData = (_GetControllersData)GetProcAddress(hDll, "GetControllersData");
809+
SetControllerData = (_SetControllerData)GetProcAddress(hDll, "SetControllerData");
810+
SetCentering = (_SetCentering)GetProcAddress(hDll, "SetCentering");
811+
812+
if (GetHMDData != NULL && GetHMDData(&MyHMD) == TOVR_SUCCESS)
813+
HMDConnected = true;
814+
815+
if (GetControllersData != NULL && SetControllerData != NULL && GetControllersData(&MyCtrl, &MyCtrl2) == TOVR_SUCCESS)
816+
ctrlsConnected = true;
817+
818+
if (SetCentering == NULL) {
819+
HMDConnected = false;
820+
ctrlsConnected = false;
821+
}
822+
}
823+
}
824+
825+
key.Close();
826+
827+
if (HMDConnected)
828+
{
856829
m_pNullHmdLatest = new CSampleDeviceDriver();
857830
vr::VRServerDriverHost()->TrackedDeviceAdded(m_pNullHmdLatest->GetSerialNumber().c_str(), vr::TrackedDeviceClass_HMD, m_pNullHmdLatest);
858-
//}
831+
}
859832

860833
if (ctrlsConnected) {
861834
m_pController = new CSampleControllerDriver();
@@ -874,10 +847,10 @@ EVRInitError CServerDriver_Sample::Init( vr::IVRDriverContext *pDriverContext )
874847
void CServerDriver_Sample::Cleanup()
875848
{
876849
//CleanupDriverLog();
877-
//if (HMDConnected) {
850+
if (HMDConnected) {
878851
delete m_pNullHmdLatest;
879852
m_pNullHmdLatest = NULL;
880-
//}
853+
}
881854

882855
if (ctrlsConnected) {
883856
delete m_pController;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"tovr" : {
3+
"secondsFromVsyncToPhotons" : 0.004999999888241291,
4+
"serialNumber" : "1000",
5+
"renderWidth" : <RENDERWIDTH>,
6+
"renderHeight" : <RENDERHEIGHT>,
7+
"windowWidth" : <WINDOWWIDTH>,
8+
"windowHeight" : <WINDOWHEIGHT>,
9+
"windowX" : <WINDOWX>,
10+
"windowY" : <WINDOWY>,
11+
"displayFrequency" : 60,
12+
"ipd" : <IPD>,
13+
"DistortionK1" : <DISTORTIONK1>,
14+
"DistortionK2" : <DISTORTIONK2>,
15+
"ZoomWidth" : 0.8,
16+
"ZoomHeight" : 0.8,
17+
"DistanceBetweenEyes" : 0,
18+
"ScreenOffsetX" : 0,
19+
"DebugMode" : <DEBUGMODE>
20+
}
21+
}

TrueOpenVR SteamVR/OpenVR/steamvr.vrsettings

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,5 @@
88
"directMode" : false,
99
"enableHomeApp" : false,
1010
"startMonitorFromAppLaunch" : false
11-
},
12-
"tovr" : {
13-
"secondsFromVsyncToPhotons" : 0.004999999888241291,
14-
"serialNumber" : "1000",
15-
"renderWidth" : <RENDERWIDTH>,
16-
"renderHeight" : <RENDERHEIGHT>,
17-
"windowWidth" : <WINDOWWIDTH>,
18-
"windowHeight" : <WINDOWHEIGHT>,
19-
"windowX" : <WINDOWX>,
20-
"windowY" : <WINDOWY>,
21-
"displayFrequency" : 60,
22-
"ipd" : <IPD>,
23-
"DistortionK1" : <DISTORTIONK1>,
24-
"DistortionK2" : <DISTORTIONK2>,
25-
"ZoomWidth" : 0.8,
26-
"ZoomHeight" : 0.8,
27-
"DistanceBetweenEyes" : 0,
28-
"ScreenOffsetX" : 0,
29-
"DebugMode" : <DEBUGMODE>
3011
}
3112
}

0 commit comments

Comments
 (0)