ValveSoftware / openvr

OpenVR SDK
http://steamvr.com
BSD 3-Clause "New" or "Revised" License
6.11k stars 1.28k forks source link

How to develop openVR driver? #221

Open zmingyang opened 8 years ago

zmingyang commented 8 years ago

I want connect our usb HID position device into SteamVR to replace HTC controller. I have read wiki https://github.com/ValveSoftware/openvr/wiki/Driver-Documentation. But this artical too simple, I even didn't know how the steamVR server found this driver, and how to debug it. where can I found these information?

matrixcr commented 8 years ago

there's also a simple sample driver in the sdk, maybe you can get start from there.

otri commented 8 years ago

The Driver-Documentation wiki could also cover some suggestions such as: updating the User Macros in the "Paths" property sheet. Open the Property Sheet Manager, and configure them. There are two samples, github ValveSoftware/driver_hydra (useful info for the OP) and a driver_sample which implements a null HMD driver in the openvr/samples folder.

I also would like to know how to debug the driver DLL. Which exe can we run to trigger loading the various SteamVR runtimes, is this vrserver.exe? What command line arguments can we use to trigger loading our driver?

This info would be very helpful for connecting the dots through to getting development going.

Thanks, this is excellent work on the driver interfaces. The APIs are awesome.

zloveless commented 8 years ago

How are we meant to debug these things? vrserver.exe calls the driver exports but it has a short timeout, so if you try to debug it, it will be killed because it is suspended too long. Is there a setting somewhere?

otri commented 8 years ago

Turns out you need to multi-launch some processes. 1) vrmonitor.exe (start without debugging) 2) your project (start) - configure project to launch vrserver.exe

See the details here on how to configure "multiple startup projects": https://msdn.microsoft.com/en-us/library/jj919165.aspx

Once you've got vrmonitor launching, it'll attach to vrserver.exe which triggers loading your DLL driver. Pay attention to vrserver.txt log file for details about how it's attempting to load your driver.

Streamlining the post-build step is also important. Have a look at Valve's driver_hydra: https://github.com/ValveSoftware/driver_hydra

Look at the driver_hydra Property Pages Configuration Properties -> Build Events -> Post-Build Event

You'll see a handy script there: mkdir "$(InstallDir)\bin\$(Platform)" copy $(OutDir)$(TargetName)$(TargetExt) "$(InstallDir)\bin\$(Platform)" copy "$(SixenseSDKDir)\bin\$(Platform)\$(Configuration)_dll\*" "$(InstallDir)\bin\$(Platform)" "$(SteamVRRuntimeDir)\bin\win32\vrpathreg" adddriver "$(InstallDir)" xcopy /s /i /y "$(SolutionDir)\resources" "$(InstallDir)\resources"

driver_hydra uses a custom property page "Paths" too, also a handy resource for configuring a bunch of the environment variables like $(InstallDir), $(SixenseSDKDir), etc... Look in the Property Manager: driver_hydra -> Debug | Win32 -> Paths. Open up its properties and have a look at User Macros.

uilyam commented 6 years ago

@zmingyang Did you ever find any more useful documentation? Unfortunately the official wiki documentation on this is still rather sparse.

TheDeveloperGuy commented 6 years ago

@uilyam There is none, nor is there ever likely to be. It appears Valve devs (like all others) are not big fans of writing documentation. It seems the attitude is "it's not that hard, figure it out yourself", where sometimes you'll get clues dropped if you manage to catch a dev coming by here and manage to phrase your question in such a way that it can be answered with a useful but cryptic one-liner.

Maybe there will be some more samples, but right now, you've got the release notes of the 1.0.12 SDK and the openvr_driver.h header file to get you through developing a controller driver (the Hydra driver is now completely out of date and won't build with the latest SDK).

For any driver, you'll really want to start with the 'sample' driver that comes with the SDK to at least get a (not very useful) driver building etc. There is also a 'virtual' driver sample in its own (Valve) repository for developing that kind of driver. Yeah it's frustrating, but "it's not that hard" :wink: