Skip to content

Commit

Permalink
Merge pull request #17 from direct-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pushrax committed Apr 6, 2020
2 parents eebf287 + 7cf363e commit 9744585
Show file tree
Hide file tree
Showing 9 changed files with 3,535 additions and 591 deletions.
2 changes: 1 addition & 1 deletion OpenVR-SpaceCalibrator/Calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void ScanAndApplyProfile(CalibrationContext &ctx)
continue;
}

if (deviceClass == vr::TrackedDeviceClass_TrackingReference || deviceClass == vr::TrackedDeviceClass_HMD)
if (/*deviceClass == vr::TrackedDeviceClass_TrackingReference ||*/ deviceClass == vr::TrackedDeviceClass_HMD)
{
//auto p = ctx.devicePoses[id].mDeviceToAbsoluteTracking.m;
//printf("REF %d: %f %f %f\n", id, p[0][3], p[1][3], p[2][3]);
Expand Down
43 changes: 4 additions & 39 deletions OpenVR-SpaceCalibrator/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ static void ParseProfileV2(CalibrationContext &ctx, std::istream &stream);

static std::string ConfigFileName()
{
std::string vrRuntimeConfigName = vr::VR_RuntimePath();
char cruntimePath[MAX_PATH] = { 0 };
unsigned int pathLen;
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);
std::string vrRuntimeConfigName(cruntimePath);
return vrRuntimeConfigName + "\\..\\..\\..\\config\\01spacecalibrator\\calibration.json";
}

Expand Down Expand Up @@ -197,41 +200,3 @@ static void UpgradeProfileV1(CalibrationContext &ctx)
file.close();
std::remove("openvr_space_calibration.txt");
}

void WriteActivateMultipleDriversToConfig()
{
std::string configPath = vr::VR_RuntimePath();
configPath += "\\..\\..\\..\\config\\steamvr.vrsettings";

std::ifstream ifile(configPath);
if (!ifile.good())
throw std::runtime_error("failed to read steamvr.vrsettings");

picojson::value v;
std::string err = picojson::parse(v, ifile);
if (!err.empty())
throw std::runtime_error(err);

ifile.close();

if (!v.is<picojson::object>())
throw std::runtime_error("steamvr.vrsettings is empty");

auto &root = v.get<picojson::object>();

if (!root["steamvr"].is<picojson::object>())
throw std::runtime_error("steamvr.vrsettings is missing \"steamvr\" key");

auto &steamvr = root["steamvr"].get<picojson::object>();

const bool tru = true; // MSVC picks the wrong specialization when passing a literal...
steamvr["activateMultipleDrivers"].set<bool>(tru);

std::ofstream ofile(configPath);
if (!ofile.good())
throw std::runtime_error("failed to write steamvr.vrsettings");

v.serialize(std::ostream_iterator<char>(ofile), true);

std::cout << "Successfully set activateMultipleDrivers to true" << std::endl;
}
1 change: 0 additions & 1 deletion OpenVR-SpaceCalibrator/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@

void LoadProfile(CalibrationContext &ctx);
void SaveProfile(CalibrationContext &ctx);
void WriteActivateMultipleDriversToConfig();
51 changes: 45 additions & 6 deletions OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,45 @@ void TryCreateVROverlay()

vr::VROverlay()->SetOverlayWidthInMeters(overlayMainHandle, 3.0f);
vr::VROverlay()->SetOverlayInputMethod(overlayMainHandle, vr::VROverlayInputMethod_Mouse);
vr::VROverlay()->SetOverlayFlag(overlayMainHandle, vr::VROverlayFlags_SendVRScrollEvents, true);
vr::VROverlay()->SetOverlayFlag(overlayMainHandle, vr::VROverlayFlags_SendVRDiscreteScrollEvents, true);

std::string iconPath = cwd;
iconPath += "\\icon.png";
vr::VROverlay()->SetOverlayFromFile(overlayThumbnailHandle, iconPath.c_str());
}

void ActivateMultipleDrivers()
{
vr::EVRSettingsError vrSettingsError;
bool enabled = vr::VRSettings()->GetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool, &vrSettingsError);

if (vrSettingsError != vr::VRSettingsError_None)
{
std::string err = "Could not read \"" + std::string(vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool) + "\" setting: "
+ vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);

throw std::runtime_error(err);
}

if (!enabled)
{
vr::VRSettings()->SetBool(vr::k_pch_SteamVR_Section, vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool, true, &vrSettingsError);
if (vrSettingsError != vr::VRSettingsError_None)
{
std::string err = "Could not set \"" + std::string(vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool) + "\" setting: "
+ vr::VRSettings()->GetSettingsErrorNameFromEnum(vrSettingsError);

throw std::runtime_error(err);
}

std::cerr << "Enabled \"" << vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool << "\" setting" << std::endl;
}
else
{
std::cerr << "\"" << vr::k_pch_SteamVR_ActivateMultipleDrivers_Bool << "\" setting previously enabled" << std::endl;
}
}

void InitVR()
{
auto initError = vr::VRInitError_None;
Expand All @@ -148,6 +180,8 @@ void InitVR()
{
throw std::runtime_error("OpenVR error: Outdated IVROverlay_Version");
}

ActivateMultipleDrivers();
}

void RunLoop()
Expand Down Expand Up @@ -192,10 +226,11 @@ void RunLoop()
char buf[0x400];
ImGui::GetActiveText(buf, sizeof buf);
buf[0x3ff] = 0;
uint32_t unFlags = 0; // EKeyboardFlags

vr::VROverlay()->ShowKeyboardForOverlay(
overlayMainHandle, vr::k_EGamepadTextInputModeNormal, vr::k_EGamepadTextInputLineModeSingleLine,
"Space Calibrator Overlay", sizeof buf, buf, false, 0
unFlags, "Space Calibrator Overlay", sizeof buf, buf, 0
);
keyboardOpen = true;
}
Expand All @@ -214,7 +249,7 @@ void RunLoop()
case vr::VREvent_MouseButtonUp:
io.MouseDown[vrEvent.data.mouse.button == vr::VRMouseButton_Left ? 0 : 1] = false;
break;
case vr::VREvent_Scroll:
case vr::VREvent_ScrollDiscrete:
io.MouseWheelH += vrEvent.data.scroll.xdelta * 360.0f * 8.0f;
io.MouseWheel += vrEvent.data.scroll.ydelta * 360.0f * 8.0f;
break;
Expand Down Expand Up @@ -342,7 +377,11 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
if (vrErr == vr::VRInitError_None)
{
printf("%s", vr::VR_RuntimePath());
char cruntimePath[MAX_PATH] = { 0 };
unsigned int pathLen;
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);

printf("%s", cruntimePath);
vr::VR_Shutdown();
exit(0);
}
Expand Down Expand Up @@ -421,12 +460,12 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
{
try
{
WriteActivateMultipleDriversToConfig();
ActivateMultipleDrivers();
ret = 0;
}
catch (std::runtime_error &e)
{
std::cerr << "Failed to set activateMultipleDrivers: " << e.what() << std::endl;
std::cerr << e.what() << std::endl;
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion OpenVR-SpaceCalibrator/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <algorithm>
#include <imgui/imgui.h>

#define VERSION_STRING "0.8"
#define VERSION_STRING "0.8.1"

struct VRDevice
{
Expand Down
Binary file modified lib/openvr/lib/win32/openvr_api.lib
Binary file not shown.
Binary file modified lib/openvr/lib/win64/openvr_api.lib
Binary file not shown.
Loading

0 comments on commit 9744585

Please sign in to comment.