Skip to content

Commit

Permalink
Improve logic of magnetometer toggle (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImUrX authored Oct 31, 2024
1 parent 7a02927 commit e676a15
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
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

0 comments on commit e676a15

Please sign in to comment.