Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logic of magnetometer toggle #1225

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions gui/src/components/tracker/TrackerSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,15 @@ export function TrackerSettingsPage() {
</div>
</div>
)}
{tracker?.tracker.info?.isImu && (
<MagnetometerToggleSetting
settingType="tracker"
trackerNum={tracker.tracker.trackerId?.trackerNum}
deviceId={tracker.tracker.trackerId?.deviceId?.id}
/>
)}
{tracker?.tracker.info?.isImu &&
tracker?.tracker.info?.magnetometer !==
MagnetometerStatus.NOT_SUPPORTED && (
<MagnetometerToggleSetting
settingType="tracker"
trackerNum={tracker.tracker.trackerId?.trackerNum}
deviceId={tracker.tracker.trackerId?.deviceId?.id}
/>
)}
<div className="flex flex-col gap-2 w-full mt-3">
<Typography variant="section-title">
{l10n.getString('tracker-settings-name_section')}
Expand Down
30 changes: 23 additions & 7 deletions server/core/src/main/java/dev/slimevr/config/ServerConfig.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.slimevr.config

import dev.slimevr.VRServer
import dev.slimevr.tracking.trackers.udp.MagnetometerStatus
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
Expand All @@ -20,18 +21,33 @@ class ServerConfig {

VRServer.instance.deviceManager.devices.filter { it.magSupport }.map {
async {
// Not using 255 as it sometimes could make one of the sensors go into
// error mode (if there is more than one sensor inside the device)
if (!state) {
it.setMag(false)
val trackers = it.trackers.filterValues {
it.magStatus != MagnetometerStatus.NOT_SUPPORTED
}
// if(trackers.size == it.trackers.size) {
// it.setMag(false)
// } else {
trackers.map { (_, t) ->
async { it.setMag(false, t.trackerNum) }
}.awaitAll()
// }
return@async
}

val every = it.trackers.all { (_, t) -> t.config.shouldHaveMagEnabled == true }
if (every) {
it.setMag(true)
return@async
}
// val every = it.trackers.all { (_, t) -> t.config.shouldHaveMagEnabled == true
// && t.magStatus != MagnetometerStatus.NOT_SUPPORTED }
// if (every) {
// it.setMag(true)
// return@async
// }

it.trackers.filterValues { it.config.shouldHaveMagEnabled == true }
it.trackers.filterValues {
it.config.shouldHaveMagEnabled == true &&
it.magStatus != MagnetometerStatus.NOT_SUPPORTED
}
.map { (_, t) ->
async {
// FIXME: Tracker gets restarted after each setMag, what will happen for devices with 3 trackers?
Expand Down