Skip to content

Commit

Permalink
Add toggle to save and load mounting reset (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erimelowo committed Apr 4, 2024
1 parent 78caab1 commit 7df8c5d
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 5 deletions.
5 changes: 5 additions & 0 deletions gui/public/i18n/en/translation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ settings-general-tracker_mechanics-drift_compensation-description =
settings-general-tracker_mechanics-drift_compensation-enabled-label = Drift compensation
settings-general-tracker_mechanics-drift_compensation-amount-label = Compensation amount
settings-general-tracker_mechanics-drift_compensation-max_resets-label = Use up to x last resets
settings-general-tracker_mechanics-save_mounting_reset = Save automatic mounting reset calibration
settings-general-tracker_mechanics-save_mounting_reset-description =
Saves the automatic mounting reset calibrations for the trackers between restarts. Useful
when wearing a suit where trackers don't move between sessions. <b>Not recommended for normal users!</b>
settings-general-tracker_mechanics-save_mounting_reset-enabled-label = Save mounting reset
## FK/Tracking settings
settings-general-fk_settings = Tracking settings
Expand Down
28 changes: 27 additions & 1 deletion gui/src/components/settings/pages/GeneralSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLocalization } from '@fluent/react';
import { Localized, useLocalization } from '@fluent/react';
import { useEffect, useState } from 'react';
import { DefaultValues, useForm } from 'react-hook-form';
import {
Expand Down Expand Up @@ -91,6 +91,7 @@ interface SettingsForm {
resetMountingFeet: boolean;
armsMountingResetMode: number;
yawResetSmoothTime: number;
saveMountingReset: boolean;
};
}

Expand Down Expand Up @@ -147,6 +148,7 @@ const defaultValues = {
resetMountingFeet: false,
armsMountingResetMode: 0,
yawResetSmoothTime: 0.0,
saveMountingReset: false,
},
};

Expand Down Expand Up @@ -269,6 +271,8 @@ export function GeneralSettings() {
values.resetsSettings.armsMountingResetMode;
resetsSettings.yawResetSmoothTime =
values.resetsSettings.yawResetSmoothTime;
resetsSettings.saveMountingReset =
values.resetsSettings.saveMountingReset;
settings.resetsSettings = resetsSettings;
}

Expand Down Expand Up @@ -659,6 +663,28 @@ export function GeneralSettings() {
step={0.05}
/>
</div>
<div className="flex flex-col pt-5 pb-3">
<Typography bold>
{l10n.getString(
'settings-general-tracker_mechanics-save_mounting_reset'
)}
</Typography>
<Localized
id="settings-general-tracker_mechanics-save_mounting_reset-description"
elems={{ b: <b></b> }}
>
<Typography color="secondary"></Typography>
</Localized>
</div>
<CheckBox
variant="toggle"
outlined
control={control}
name="resetsSettings.saveMountingReset"
label={l10n.getString(
'settings-general-tracker_mechanics-save_mounting_reset-enabled-label'
)}
/>
</>
</SettingsPagePaneLayout>
<SettingsPagePaneLayout
Expand Down
2 changes: 2 additions & 0 deletions gui/src/hooks/status-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ export function parseStatusToLocale(
}
return { trackerName: name };
}
case StatusData.StatusUnassignedHMD:
return { trackerName: 'Not implemented.' }; // TODO
}
}

Expand Down
3 changes: 3 additions & 0 deletions server/core/src/main/java/dev/slimevr/config/ResetsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ResetsConfig {
// Yaw reset smoothing time in seconds
var yawResetSmoothTime = 0.0f

// Save automatic mounting reset calibration
var saveMountingReset = false

fun updateTrackersResetsSettings() {
for (t in VRServer.instance.allTrackers) {
if (t.needsReset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TrackerConfig {
var hide: Boolean = false
var adjustment: ObjectQuaternion? = null
var mountingOrientation: ObjectQuaternion? = null
var mountingResetOrientation: ObjectQuaternion? = null
var allowDriftCompensation: Boolean? = null

constructor()
Expand Down
5 changes: 4 additions & 1 deletion server/core/src/main/java/dev/slimevr/config/VRConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ class VRConfig {
val config = getTracker(tracker)
tracker.readConfig(config)
if (tracker.isImu()) tracker.resetsHandler.readDriftCompensationConfig(driftCompensation)
if (tracker.needsReset) tracker.resetsHandler.readResetConfig(resetsConfig)
if (tracker.needsReset) {
tracker.resetsHandler.readResetConfig(resetsConfig)
tracker.saveMountingResetOrientation(config)
}
if (tracker.allowFiltering) {
tracker
.filteringHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ public static int createArmsResetModeSettings(
fbb,
resetsConfig.getResetMountingFeet(),
resetsConfig.getMode().getId(),
resetsConfig.getYawResetSmoothTime()
resetsConfig.getYawResetSmoothTime(),
resetsConfig.getSaveMountingReset()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class RPCSettingsHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
resetsConfig.mode = mode
}
resetsConfig.resetMountingFeet = req.resetsSettings().resetMountingFeet()
resetsConfig.saveMountingReset = req.resetsSettings().saveMountingReset()
resetsConfig.yawResetSmoothTime = req.resetsSettings().yawResetSmoothTime()
resetsConfig.updateTrackersResetsSettings()
}
Expand Down
21 changes: 21 additions & 0 deletions server/core/src/main/java/dev/slimevr/tracking/trackers/Tracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class Tracker @JvmOverloads constructor(
getByDesignation(designation)?.let { trackerPosition = it }
} ?: run { trackerPosition = null }
if (needsMounting) {
// Load manual mounting
config.mountingOrientation?.let { resetsHandler.mountingOrientation = it.toValue() }
}
if (this.isImu() && config.allowDriftCompensation == null) {
Expand All @@ -241,13 +242,33 @@ class Tracker @JvmOverloads constructor(
trackerPosition?.let { config.designation = it.designation } ?: run { config.designation = null }
customName?.let { config.customName = it }
if (needsMounting) {
// Save manual mounting
config.mountingOrientation = resetsHandler.mountingOrientation.toObject()
}
if (this.isImu()) {
config.allowDriftCompensation = resetsHandler.allowDriftCompensation
}
}

/**
* Loads the mounting reset quaternion from disk
*/
fun saveMountingResetOrientation(config: TrackerConfig) {
// Load automatic mounting
config.mountingResetOrientation?.let {
resetsHandler.trySetMountingReset(it.toValue())
}
}

/**
* Saves the mounting reset quaternion to disk
*/
fun saveMountingResetOrientation(quat: Quaternion?) {
val configManager = VRServer.instance.configManager
configManager.vrConfig.getTracker(this).mountingResetOrientation = quat?.toObject()
configManager.saveConfig()
}

/**
* Synchronized with the VRServer's 1000hz while loop
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TrackerResetsHandler(val tracker: Tracker) {
private var armsResetMode = ArmsResetModes.BACK
private var yawResetSmoothTime = 0.0f
private lateinit var fpsTimer: NanoTimer
var saveMountingReset = false
var allowDriftCompensation = false
var lastResetQuaternion: Quaternion? = null

Expand Down Expand Up @@ -112,7 +113,7 @@ class TrackerResetsHandler(val tracker: Tracker) {
}

/**
* Reads/loads arms reset mode settings from given config
* Reads/loads reset settings from the given config
*/
fun readResetConfig(config: ResetsConfig) {
resetMountingFeet = config.resetMountingFeet
Expand All @@ -121,6 +122,13 @@ class TrackerResetsHandler(val tracker: Tracker) {
if (!::fpsTimer.isInitialized) {
fpsTimer = VRServer.instance.fpsTimer
}
saveMountingReset = config.saveMountingReset
}

fun trySetMountingReset(quat: Quaternion) {
if (saveMountingReset) {
mountRotFix = quat
}
}

/**
Expand Down Expand Up @@ -323,6 +331,9 @@ class TrackerResetsHandler(val tracker: Tracker) {

// Make an adjustment quaternion from the angle
mountRotFix = EulerAngles(EulerOrder.YZX, 0f, yawAngle, 0f).toQuaternion()

// save mounting reset
if (saveMountingReset) tracker.saveMountingResetOrientation(mountRotFix)
}

fun clearMounting() {
Expand Down
2 changes: 1 addition & 1 deletion solarxr-protocol
Submodule solarxr-protocol updated 28 files
+98 −11 protocol/cpp/include/solarxr_protocol/generated/all_generated.h
+9 −1 protocol/java/src/solarxr_protocol/data_feed/tracker/TrackerInfo.java
+6 −0 protocol/java/src/solarxr_protocol/data_feed/tracker/TrackerInfoT.java
+11 −4 protocol/java/src/solarxr_protocol/rpc/ResetsSettings.java
+6 −0 protocol/java/src/solarxr_protocol/rpc/ResetsSettingsT.java
+2 −1 protocol/java/src/solarxr_protocol/rpc/StatusData.java
+2 −0 protocol/java/src/solarxr_protocol/rpc/StatusDataUnion.java
+4 −0 protocol/java/src/solarxr_protocol/rpc/StatusMessage.java
+61 −0 protocol/java/src/solarxr_protocol/rpc/StatusUnassignedHMD.java
+22 −0 protocol/java/src/solarxr_protocol/rpc/StatusUnassignedHMDT.java
+11 −1 protocol/kotlin/src/solarxr_protocol/data_feed/tracker/TrackerInfo.kt
+11 −3 protocol/kotlin/src/solarxr_protocol/rpc/ResetsSettings.kt
+2 −1 protocol/kotlin/src/solarxr_protocol/rpc/StatusData.kt
+57 −0 protocol/kotlin/src/solarxr_protocol/rpc/StatusUnassignedHMD.kt
+2 −0 protocol/rust/src/generated/mod.rs
+18 −0 protocol/rust/src/generated/solarxr_protocol/data_feed/tracker/tracker_info_generated.rs
+17 −0 protocol/rust/src/generated/solarxr_protocol/rpc/resets_settings_generated.rs
+7 −3 protocol/rust/src/generated/solarxr_protocol/rpc/status_data_generated.rs
+23 −0 protocol/rust/src/generated/solarxr_protocol/rpc/status_message_generated.rs
+109 −0 protocol/rust/src/generated/solarxr_protocol/rpc/status_unassigned_hmd_generated.rs
+1 −0 protocol/typescript/src/all_generated.ts
+19 −3 protocol/typescript/src/solarxr-protocol/data-feed/tracker/tracker-info.ts
+19 −5 protocol/typescript/src/solarxr-protocol/rpc/resets-settings.ts
+9 −5 protocol/typescript/src/solarxr-protocol/rpc/status-data.ts
+2 −1 protocol/typescript/src/solarxr-protocol/rpc/status-message.ts
+78 −0 protocol/typescript/src/solarxr-protocol/rpc/status-unassigned-hmd.ts
+3 −0 schema/data_feed/tracker.fbs
+7 −0 schema/rpc.fbs

0 comments on commit 7df8c5d

Please sign in to comment.