mirror of
https://github.com/hyblocker/OpenVR-SpaceCalibrator.git
synced 2026-10-14 21:00:51 +02:00
chore: enum to string for config
This commit is contained in:
2 files changed
+145
-4
No files matched your search
@@ -1,10 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "platform.h"
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
BEGIN_EXTERNAL_HEADERS
|
||||
#include <glaze/glaze.hpp>
|
||||
END_EXTERNAL_HEADERS
|
||||
|
||||
namespace spacecal {
|
||||
namespace config {
|
||||
namespace versioned {
|
||||
@@ -12,8 +17,9 @@ namespace spacecal {
|
||||
enum class DataVersions : uint32_t {
|
||||
Legacy = 0xFFFFFFFFU, // pushrax / bd versions
|
||||
_0 = 0, // nova v1
|
||||
_1, // nova v1 (enum anchor mode)
|
||||
|
||||
Current = _0,
|
||||
Current = _1,
|
||||
Count,
|
||||
};
|
||||
|
||||
@@ -109,7 +115,7 @@ namespace spacecal {
|
||||
bool calibrate_motion_vectors = true;
|
||||
bool attempt_auto_fix_playspace_jumps = true;
|
||||
bool enforce_minimum_rotation_variance = true;
|
||||
uint64_t calibration_speed = 0;
|
||||
uint64_t calibration_speed = 100;
|
||||
|
||||
TrackingDevice reference_device;
|
||||
TrackingDevice target_device;
|
||||
@@ -132,7 +138,76 @@ namespace spacecal {
|
||||
std::vector<Calibration_t> calibrations;
|
||||
};
|
||||
|
||||
typedef Configuration_0 Configuration_Latest;
|
||||
struct Configuration_1 {
|
||||
spacecal::config::versioned::DataVersions dataVersion = spacecal::config::versioned::DataVersions::_1;
|
||||
|
||||
enum class AnchorMode : uint32_t {
|
||||
FixedWorld = 0, // Worldspace calibration
|
||||
HmdRelative = 1 // Relative to reference device (typically HMD)
|
||||
};
|
||||
|
||||
struct TrackingDevice {
|
||||
std::string model;
|
||||
std::string serial;
|
||||
std::string tracking_system;
|
||||
};
|
||||
struct Transform {
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f; // pos, meters
|
||||
float yaw = 0.0f, pitch = 0.0f, roll = 0.0f; // rot, deg
|
||||
};
|
||||
|
||||
struct ContinuousCalibrationData {
|
||||
bool is_active = false;
|
||||
bool hide_reference_tracker = false;
|
||||
};
|
||||
|
||||
struct Calibration_t {
|
||||
bool is_active = false;
|
||||
|
||||
Transform calibrated_transform;
|
||||
float scale = 1.0f;
|
||||
|
||||
AnchorMode anchor_mode = AnchorMode::FixedWorld;
|
||||
ContinuousCalibrationData continuous;
|
||||
|
||||
bool calibrate_motion_vectors = true;
|
||||
bool attempt_auto_fix_playspace_jumps = true;
|
||||
bool enforce_minimum_rotation_variance = true;
|
||||
uint64_t calibration_speed = 100;
|
||||
|
||||
TrackingDevice reference_device;
|
||||
TrackingDevice target_device;
|
||||
};
|
||||
|
||||
struct BaseStationManagementData {
|
||||
bool auto_power_management_enabled = false;
|
||||
bool auto_turn_on_during_startup = true;
|
||||
bool auto_turn_off_during_shutdown = true;
|
||||
bool off_should_use_standby = false;
|
||||
std::unordered_map<std::string, std::string> nicknames; // KV pair -> "LHB XXXXXXXX" to "my nick name"
|
||||
};
|
||||
|
||||
std::string ui_locale = "system";
|
||||
bool advanced_settings = false;
|
||||
bool ignore_stage_tracking_warning = false;
|
||||
|
||||
BaseStationManagementData base_stations;
|
||||
|
||||
std::vector<Calibration_t> calibrations;
|
||||
};
|
||||
|
||||
typedef Configuration_1 Configuration_Latest;
|
||||
} // namespace versioned
|
||||
} // namespace config
|
||||
} // namespace spacecal
|
||||
} // namespace spacecal
|
||||
|
||||
// enum to str:
|
||||
|
||||
template <>
|
||||
struct glz::meta<spacecal::config::versioned::Configuration_1::AnchorMode> {
|
||||
using enum spacecal::config::versioned::Configuration_1::AnchorMode;
|
||||
static constexpr auto value = glz::enumerate(
|
||||
FixedWorld,
|
||||
HmdRelative
|
||||
);
|
||||
};
|
||||
@@ -146,6 +146,13 @@ namespace spacecal {
|
||||
}
|
||||
}
|
||||
|
||||
// @FIXME: remove once we support multiple calibrations in the UI
|
||||
// ensure at least one calibration exists until we add support in the ui for dynamically making new ones
|
||||
if (m_config.calibrations.empty()) {
|
||||
LOG_WARN("Config loaded with 0 calibrations. Creating initial calibration entry...");
|
||||
m_config.calibrations.emplace_back();
|
||||
}
|
||||
|
||||
return ConfigurationError::Ok;
|
||||
}
|
||||
|
||||
@@ -176,6 +183,13 @@ namespace spacecal {
|
||||
if (!jsonData)
|
||||
return false;
|
||||
|
||||
constexpr glz::opts options{
|
||||
.comments = true,
|
||||
.error_on_unknown_keys = false,
|
||||
.error_on_missing_keys = false,
|
||||
.error_on_const_read = false
|
||||
};
|
||||
|
||||
DataVersions version = (DataVersions)readVersion;
|
||||
|
||||
if (version == DataVersions::Legacy) {
|
||||
@@ -266,6 +280,58 @@ namespace spacecal {
|
||||
}
|
||||
|
||||
if (version == DataVersions::_0) {
|
||||
// parse into struct and re-map
|
||||
Configuration_0 calib = {};
|
||||
Configuration_1 nextConfig = {};
|
||||
auto ec = glz::read_json<Configuration_0>(calib, *jsonData);
|
||||
if (!ec) {
|
||||
nextConfig.dataVersion = DataVersions::_1;
|
||||
|
||||
nextConfig.advanced_settings = calib.advanced_settings;
|
||||
nextConfig.ignore_stage_tracking_warning = calib.ignore_stage_tracking_warning;
|
||||
nextConfig.ui_locale = calib.ui_locale;
|
||||
|
||||
nextConfig.base_stations.auto_power_management_enabled = calib.base_stations.auto_power_management_enabled;
|
||||
nextConfig.base_stations.auto_turn_on_during_startup = calib.base_stations.auto_turn_on_during_startup;
|
||||
nextConfig.base_stations.auto_turn_off_during_shutdown = calib.base_stations.auto_turn_off_during_shutdown;
|
||||
nextConfig.base_stations.off_should_use_standby = calib.base_stations.off_should_use_standby;
|
||||
nextConfig.base_stations.nicknames = std::move(calib.base_stations.nicknames);
|
||||
|
||||
nextConfig.calibrations.resize(calib.calibrations.size());
|
||||
for (size_t i = 0; i < calib.calibrations.size(); i++) {
|
||||
nextConfig.calibrations[i].target_device.model = calib.calibrations[i].target_device.model;
|
||||
nextConfig.calibrations[i].target_device.serial = calib.calibrations[i].target_device.serial;
|
||||
nextConfig.calibrations[i].target_device.tracking_system = calib.calibrations[i].target_device.tracking_system;
|
||||
|
||||
nextConfig.calibrations[i].reference_device.model = calib.calibrations[i].reference_device.model;
|
||||
nextConfig.calibrations[i].reference_device.serial = calib.calibrations[i].reference_device.serial;
|
||||
nextConfig.calibrations[i].reference_device.tracking_system = calib.calibrations[i].reference_device.tracking_system;
|
||||
|
||||
nextConfig.calibrations[i].is_active = calib.calibrations[i].is_active;
|
||||
nextConfig.calibrations[i].scale = calib.calibrations[i].scale;
|
||||
nextConfig.calibrations[i].anchor_mode = (Configuration_1::AnchorMode) calib.calibrations[i].anchor_mode;
|
||||
nextConfig.calibrations[i].calibrate_motion_vectors = calib.calibrations[i].calibrate_motion_vectors;
|
||||
nextConfig.calibrations[i].attempt_auto_fix_playspace_jumps = calib.calibrations[i].attempt_auto_fix_playspace_jumps;
|
||||
nextConfig.calibrations[i].enforce_minimum_rotation_variance = calib.calibrations[i].enforce_minimum_rotation_variance;
|
||||
nextConfig.calibrations[i].calibration_speed = calib.calibrations[i].calibration_speed;
|
||||
|
||||
nextConfig.calibrations[i].continuous.is_active = calib.calibrations[i].continuous.is_active;
|
||||
nextConfig.calibrations[i].continuous.hide_reference_tracker = calib.calibrations[i].continuous.hide_reference_tracker;
|
||||
|
||||
nextConfig.calibrations[i].calibrated_transform.x = calib.calibrations[i].calibrated_transform.x;
|
||||
nextConfig.calibrations[i].calibrated_transform.y = calib.calibrations[i].calibrated_transform.y;
|
||||
nextConfig.calibrations[i].calibrated_transform.z = calib.calibrations[i].calibrated_transform.z;
|
||||
nextConfig.calibrations[i].calibrated_transform.yaw = calib.calibrations[i].calibrated_transform.yaw;
|
||||
nextConfig.calibrations[i].calibrated_transform.pitch = calib.calibrations[i].calibrated_transform.pitch;
|
||||
nextConfig.calibrations[i].calibrated_transform.roll = calib.calibrations[i].calibrated_transform.roll;
|
||||
}
|
||||
|
||||
m_config = std::move(nextConfig);
|
||||
version = DataVersions::_1;
|
||||
}
|
||||
}
|
||||
|
||||
if (version == DataVersions::_1) {
|
||||
// @TODO: fill on config version bump
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user