OpenVRDevice::OpenVRDevice(float nearClip, float farClip, const float worldUnitsPerMetre, const int samples) : m_vrSystem(nullptr), m_vrRenderModels(nullptr), m_worldUnitsPerMetre(worldUnitsPerMetre), m_mirrorTexture(nullptr), m_position(osg::Vec3(0.0f, 0.0f, 0.0f)), m_orientation(osg::Quat(0.0f, 0.0f, 0.0f, 1.0f)), m_nearClip(nearClip), m_farClip(farClip), m_samples(samples) { for (int i = 0; i < 2; i++) { m_textureBuffer[i] = nullptr; } trySetProcessAsHighPriority(); // Loading the SteamVR Runtime vr::EVRInitError eError = vr::VRInitError_None; m_vrSystem = vr::VR_Init(&eError, vr::VRApplication_Scene); if (eError != vr::VRInitError_None) { m_vrSystem = nullptr; osg::notify(osg::WARN) << "Error: Unable to initialize the OpenVR library.\n" << "Reason: " << vr::VR_GetVRInitErrorAsEnglishDescription( eError ) << std::endl; return; } if ( !vr::VRCompositor() ) { m_vrSystem = nullptr; vr::VR_Shutdown(); osg::notify(osg::WARN) << "Error: Compositor initialization failed" << std::endl; return; } m_vrRenderModels = (vr::IVRRenderModels *)vr::VR_GetGenericInterface(vr::IVRRenderModels_Version, &eError); if (m_vrRenderModels == nullptr) { m_vrSystem = nullptr; vr::VR_Shutdown(); osg::notify(osg::WARN) << "Error: Unable to get render model interface!\n" << "Reason: " << vr::VR_GetVRInitErrorAsEnglishDescription( eError ) << std::endl; return; } std::string driverName = GetDeviceProperty(vr::Prop_TrackingSystemName_String); std::string deviceSerialNumber = GetDeviceProperty(vr::Prop_SerialNumber_String); osg::notify(osg::NOTICE) << "HMD driver name: "<< driverName << std::endl; osg::notify(osg::NOTICE) << "HMD device serial number: " << deviceSerialNumber << std::endl; }
bool USBDevice::Load(const CString &nDeviceDir, const vector<CString> &interfaces) { m_sDeviceDir = nDeviceDir; m_sInterfaceDeviceDirs = interfaces; CString buf; if (GetDeviceProperty("idVendor", buf)) sscanf(buf, "%x", &m_iIdVendor); else m_iIdVendor = -1; if (GetDeviceProperty("idProduct", buf)) sscanf(buf, "%x", &m_iIdProduct); else m_iIdProduct = -1; if (GetDeviceProperty("bMaxPower", buf)) sscanf(buf, "%imA", &m_iMaxPower); else m_iMaxPower = -1; if (m_iIdVendor == -1 || m_iIdProduct == -1 || m_iMaxPower == -1) { LOG->Warn( "Could not load USBDevice %s", nDeviceDir.c_str() ); return false; } for (unsigned i = 0; i < m_sInterfaceDeviceDirs.size(); i++) { int iClass; if ( GetInterfaceProperty( "bInterfaceClass", i, buf ) ) { sscanf( buf, "%x", &iClass ); } else { //LOG->Warn("Could not read interface %i for %s:%s", i, m_sDeviceDir.c_str(), m_sInterfaceDeviceDirs[i].c_str() ); iClass = -1; } m_iInterfaceClasses.push_back(iClass); } return true; }
// The enumerated device nodes/instances are "empty" PDO's that act as interfaces for the HID Class // Driver. // Since those PDO's normaly don't have a FDO and therefore no driver loaded, we need to move one // device node up in the device tree. // Then check the provider of the device driver, which will be "Microsoft" in case of the default // HID Class Driver // or "TOSHIBA" in case of the Toshiba Bluetooth Stack, because it provides its own Class Driver. static bool CheckForToshibaStack(const DEVINST& hid_interface_device_instance) { HDEVINFO parent_device_info = nullptr; SP_DEVINFO_DATA parent_device_data = {}; parent_device_data.cbSize = sizeof(SP_DEVINFO_DATA); if (GetParentDevice(hid_interface_device_instance, &parent_device_info, &parent_device_data)) { std::wstring class_driver_provider = GetDeviceProperty(parent_device_info, &parent_device_data, &DEVPKEY_Device_DriverProvider); SetupDiDestroyDeviceInfoList(parent_device_info); return (class_driver_provider == L"TOSHIBA"); } DEBUG_LOG(WIIMOTE, "Unable to detect class driver provider!"); return false; }