Skip to content

Commit

Permalink
Merge pull request #27 from OSVR/openvr106
Browse files Browse the repository at this point in the history
Update plugin code to work with OpenVR SDK 1.0.6
  • Loading branch information
mars979 authored May 10, 2017
2 parents 9a0dea8 + 9adbeb1 commit 0b7963f
Show file tree
Hide file tree
Showing 35 changed files with 1,752 additions and 726 deletions.
28 changes: 22 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ find_package(JsonCpp REQUIRED)
find_package(Boost REQUIRED COMPONENTS system iostreams filesystem)
find_package(Eigen3 REQUIRED)

#
# Third-party libraries
#
add_subdirectory(vendor)

option(BUILD_EXTRA_TOOLS "Whether the extra, optional tools should also be built." OFF)

# Interface target for the openvr_driver.h header we'll use to interact with the target driver.
Expand All @@ -29,8 +34,8 @@ target_include_directories(OpenVRDriver INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/v
add_library(boost_filesystem_v3 INTERFACE)
target_link_libraries(boost_filesystem_v3
INTERFACE
${Boost_FILESYSTEM_LIBRARIES}
${Boost_SYSTEM_LIBRARIES})
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY})
target_compile_definitions(boost_filesystem_v3 INTERFACE BOOST_FILESYSTEM_VERSION=3)
target_include_directories(boost_filesystem_v3 INTERFACE ${Boost_INCLUDE_DIRS})

Expand Down Expand Up @@ -102,8 +107,15 @@ add_library(ViveLoaderLib STATIC
ServerPropertyHelper.h
PropertyHelper.h
PropertyTraits.h
VRSettings.cpp
VRSettings.h)
Properties.h
Properties.cpp
Settings.cpp
Settings.h
DriverLog.h
DriverLog.cpp
DriverContext.h
DriverContext.cpp
ValveStrCpy.h)
target_link_libraries(ViveLoaderLib
PUBLIC
OpenVRDriver osvr::osvrUtil linkable_into_dll
Expand All @@ -115,14 +127,18 @@ target_include_directories(ViveLoaderLib PUBLIC ${CMAKE_CURRENT_BINARY_DIRECTORY
osvr_convert_json(com_osvr_Vive_json
com_osvr_Vive.json
"${CMAKE_CURRENT_BINARY_DIR}/com_osvr_Vive_json.h")
osvr_convert_json(com_osvr_ViveSync_json
com_osvr_ViveSync.json
"${CMAKE_CURRENT_BINARY_DIR}/com_osvr_ViveSync_json.h")
osvr_add_plugin(com_osvr_Vive
CPP
com_osvr_Vive.cpp
OSVRViveTracker.cpp
OSVRViveTracker.h
QuickProcessingDeque.h
VerifyLocked.h
"${CMAKE_CURRENT_BINARY_DIR}/com_osvr_Vive_json.h")
"${CMAKE_CURRENT_BINARY_DIR}/com_osvr_Vive_json.h"
"${CMAKE_CURRENT_BINARY_DIR}/com_osvr_ViveSync_json.h")

target_link_libraries(com_osvr_Vive ViveLoaderLib)
target_include_directories(com_osvr_Vive
Expand All @@ -135,7 +151,7 @@ if(BUILD_EXTRA_TOOLS)
ViveLoader.cpp)
target_link_libraries(ViveLoader PRIVATE ViveLoaderLib)
copy_imported_targets(ViveLoader osvr::osvrUtil)

target_include_directories(ViveLoader PRIVATE ${Boost_INCLUDE_DIRS})

add_executable(GenerateTypedPropertyEnums
GenerateTypedPropertyEnums.cpp)
Expand Down
7 changes: 4 additions & 3 deletions ChaperoneData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ getFile(std::string const &fn,
bool keepReading = true;
while (1) {
DWORD bytesRead;
auto ret = ReadFile(f, buf.data(), buf.size() - 1, &bytesRead, nullptr);
auto ret = ReadFile(f, buf.data(), static_cast<DWORD>(buf.size() - 1),
&bytesRead, nullptr);
if (ret) {
if (bytesRead == 0) {
// end of file
Expand All @@ -93,8 +94,8 @@ getFile(std::string const &fn,
} else {

errorReport("Error after reading " +
std::to_string(os.str().size()) + " bytes: " +
formatLastErrorAsString());
std::to_string(os.str().size()) +
" bytes: " + formatLastErrorAsString());
return std::string{};
}
}
Expand Down
49 changes: 23 additions & 26 deletions DisplayExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ inline UnitClippingPlane getClippingPlanes(vr::IVRDisplayComponent *display,
}

void updateCenterOfProjection(DisplayDescriptor &descriptor,
vr::ITrackedDeviceServerDriver *dev) {
vr::TrackedDeviceIndex_t idx) {
/// Get the two eye/lens center of projections.
using CenterOfProjectionIndices =
std::tuple<std::size_t, osvr::vive::Props, osvr::vive::Props>;
Expand All @@ -76,8 +76,8 @@ void updateCenterOfProjection(DisplayDescriptor &descriptor,
Props::LensCenterLeftV},
CenterOfProjectionIndices{1, Props::LensCenterRightU,
Props::LensCenterRightV}}) {
auto x = getPropertyOfType<float>(dev, get<1>(data)).first;
auto y = getPropertyOfType<float>(dev, get<2>(data)).first;
auto x = getPropertyOfType<float>(get<1>(data), idx).first;
auto y = getPropertyOfType<float>(get<2>(data), idx).first;

g_descriptor->updateCenterOfProjection(get<0>(data), {{x, y}});
}
Expand Down Expand Up @@ -106,8 +106,9 @@ bool updateFOV(DisplayDescriptor &descriptor,

// Couldn't compute the conversion - must not be symmetrical enough
// at the moment.
std::cout << PREFIX << "First attempt was not symmetrical, will symmetrize "
"and re-convert the field of view."
std::cout << PREFIX
<< "First attempt was not symmetrical, will symmetrize "
"and re-convert the field of view."
<< std::endl;
averageAndSymmetrize(leftFovs, rightFovs);
fovsResult = twoEyeFovsToMonoWithOverlap(leftFovs, rightFovs);
Expand Down Expand Up @@ -154,7 +155,7 @@ std::string generateMeshFileContents(vr::IVRDisplayComponent *display,
return mesh.getSeparateFile();
}

void handleDisplay(vr::ITrackedDeviceServerDriver *dev,
void handleDisplay(vr::TrackedDeviceIndex_t idx,
vr::IVRDisplayComponent *display) {

g_gotDisplay = true;
Expand All @@ -163,7 +164,7 @@ void handleDisplay(vr::ITrackedDeviceServerDriver *dev,
{
vr::ETrackedPropertyError err;
std::string mfr;
std::tie(mfr, err) = getProperty<Props::ManufacturerName>(dev);
std::tie(mfr, err) = getProperty<Props::ManufacturerName>(idx);
if (mfr.empty() || err != vr::TrackedProp_Success) {
std::cerr << "Error trying to read the manufacturer of the "
"attached HMD..."
Expand All @@ -173,7 +174,7 @@ void handleDisplay(vr::ITrackedDeviceServerDriver *dev,
g_descriptor->setVendor(mfr);
}
std::string model;
std::tie(model, err) = getProperty<Props::ModelNumber>(dev);
std::tie(model, err) = getProperty<Props::ModelNumber>(idx);
if (model.empty() || err != vr::TrackedProp_Success) {
std::cerr << "Error trying to read the model of the attached HMD..."
<< std::endl;
Expand All @@ -187,7 +188,7 @@ void handleDisplay(vr::ITrackedDeviceServerDriver *dev,
}

std::string serial;
std::tie(serial, err) = getProperty<Props::SerialNumber>(dev);
std::tie(serial, err) = getProperty<Props::SerialNumber>(idx);
std::string unit;
if (serial.empty() || err != vr::TrackedProp_Success) {
std::cerr << "Error trying to read the serial number of the "
Expand All @@ -211,7 +212,7 @@ void handleDisplay(vr::ITrackedDeviceServerDriver *dev,
g_descriptor->setResolution(width, height);
}

updateCenterOfProjection(*g_descriptor, dev);
updateCenterOfProjection(*g_descriptor, idx);

if (!updateFOV(*g_descriptor, display)) {
g_gotDisplay = false;
Expand Down Expand Up @@ -269,12 +270,6 @@ int main() {
<< std::endl;
return 1;
}
if (!vive.isHMDPresent()) {
std::cerr << PREFIX
<< "Driver loaded, but no Vive is connected. Exiting"
<< std::endl;
return 0;
}
if (!vive.startServerDeviceProvider()) {
// can either check return value of this, or do another if (!vive)
// after calling - equivalent.
Expand Down Expand Up @@ -308,32 +303,34 @@ int main() {

/// Power the system up.
vive.serverDevProvider().LeaveStandby();

{
auto numDevices = vive.serverDevProvider().GetTrackedDeviceCount();
DeviceHolder devHolder = std::move(vive.devices());
auto numDevices = devHolder.numDevices();
std::cout << PREFIX << "Got " << numDevices
<< " tracked devices at startup" << std::endl;
for (decltype(numDevices) i = 0; i < numDevices; ++i) {
auto dev = vive.serverDevProvider().GetTrackedDeviceDriver(
i);
vive.devices().addAndActivateDevice(dev);
std::cout << PREFIX << "Device " << i << std::endl;
for (std::uint32_t i = 0; i < numDevices; ++i) {
vr::ITrackedDeviceServerDriver *dev = &(devHolder.getDevice(i));
auto disp =
osvr::vive::getComponent<vr::IVRDisplayComponent>(dev);
if (disp) {
std::cout << PREFIX
<< "-- it's a display, too! We'll extract its "
"display parameters now."
<< std::endl;
handleDisplay(dev, disp);
vr::TrackedDeviceIndex_t idx = i;
handleDisplay(idx, disp);
break;
}
}
}

vive.stop();
if (vive.serverDevProvider().ShouldBlockStandbyMode()) {
std::cout << PREFIX << "Driver is reporting that it is busy and "
"should block standby mode, so we will wait "
"until it is finished to exit..."
std::cout << PREFIX
<< "Driver is reporting that it is busy and "
"should block standby mode, so we will wait "
"until it is finished to exit..."
<< std::endl;
do {
std::this_thread::sleep_for(std::chrono::milliseconds(20));
Expand Down
70 changes: 70 additions & 0 deletions DriverContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/** @file
@brief Implementation
@date 2017
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/

// Copyright 2017 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Internal Includes
#include "DriverContext.h"

// Library/third-party includes
// - none

// Standard includes
// - none

using namespace vr;

DriverContext::DriverContext()
: m_pServerDriverHost(nullptr), m_pVRProperties(nullptr),
m_pVRSetting(nullptr), m_pVRDriverLog(nullptr) {}

DriverContext::DriverContext(vr::ServerDriverHost *serverDriverHost,
vr::Settings *settings, vr::DriverLog *driverLog,
vr::Properties *properties)
: m_pServerDriverHost(serverDriverHost), m_pVRProperties(properties),
m_pVRSetting(settings), m_pVRDriverLog(driverLog) {}

// only consider four type of interfaces
void *DriverContext::GetGenericInterface(const char *pchInterfaceVersion,
vr::EVRInitError *peError) {
std::string interfaceVersion = pchInterfaceVersion;
if (interfaceVersion.compare(IVRServerDriverHost_Version) == 0) {
return m_pServerDriverHost;
} else if (interfaceVersion.compare(IVRSettings_Version) == 0) {
return m_pVRSetting;
} else if (interfaceVersion.compare(IVRProperties_Version) == 0) {
return m_pVRProperties;
} else if (interfaceVersion.compare(IVRDriverLog_Version) == 0) {
return m_pVRDriverLog;
} else {
std::string errMsg = "Got an unhandled interface type version - " +
std::string(pchInterfaceVersion);
m_pVRDriverLog->Log(errMsg.c_str());
return nullptr;
}
}

// not sure which driver handle to return now
vr::DriverHandle_t DriverContext::GetDriverHandle() {
vr::DriverHandle_t dh = 1;
return dh;
}
68 changes: 68 additions & 0 deletions DriverContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/** @file
@brief Header
@date 2017
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/

// Copyright 2017 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef INCLUDED_DriverContext_h_GUID_36B19EC5_76DE_49B4_5B1A_37B88E5E6C42
#define INCLUDED_DriverContext_h_GUID_36B19EC5_76DE_49B4_5B1A_37B88E5E6C42

// Internal
#include "DriverLog.h"
#include "Properties.h"
#include "ServerDriverHost.h"
#include "Settings.h"

// Library/third-party includes
#include <openvr_driver.h>

// Standard includes
#include <iostream>
#include <memory>
#include <string>
#include <utility>

namespace vr {
class DriverContext : public vr::IVRDriverContext {
public:
DriverContext();
DriverContext(vr::ServerDriverHost *serverDriverHost,
vr::Settings *settings, vr::DriverLog *driverLog,
vr::Properties *properties);

/// Returns the requested interface. If the interface was not available
/// it will return NULL and fill out the error.
virtual void *GetGenericInterface(const char *pchInterfaceVersion,
vr::EVRInitError *peError = nullptr);

/// Returns the property container handle for this driver
virtual vr::DriverHandle_t GetDriverHandle();

private:
vr::ServerDriverHost *m_pServerDriverHost;
vr::IVRProperties *m_pVRProperties;
vr::IVRSettings *m_pVRSetting;
vr::IVRDriverLog *m_pVRDriverLog;
};

} // namespace vr

#endif // INCLUDED_DriverContext_h_GUID_36B19EC5_76DE_49B4_5B1A_37B88E5E6C42
Loading

0 comments on commit 0b7963f

Please sign in to comment.