Skip to content

Commit

Permalink
Don't ask twice to reset non-imu trackers (#760)
Browse files Browse the repository at this point in the history
Co-authored-by: Uriel <[email protected]>
  • Loading branch information
Erimelowo and ImUrX authored Jul 4, 2023
1 parent e71ed5c commit 3068fad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 39 deletions.
61 changes: 30 additions & 31 deletions server/src/main/java/dev/slimevr/tracking/trackers/Tracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import solarxr_protocol.rpc.StatusData
import solarxr_protocol.rpc.StatusDataUnion
import solarxr_protocol.rpc.StatusTrackerErrorT
import solarxr_protocol.rpc.StatusTrackerResetT
import kotlin.properties.Delegates

const val TIMEOUT_MS = 2000L

Expand Down Expand Up @@ -59,40 +60,33 @@ class Tracker @JvmOverloads constructor(
/**
* If the tracker has gotten disconnected after it was initialized first time
*/
var disconnectedRecently = false
var statusResetRecently = false
private var alreadyInitialized = false
var status = TrackerStatus.DISCONNECTED
set(value) {
if (field == value) return

field = value

if (field == TrackerStatus.DISCONNECTED && alreadyInitialized) {
disconnectedRecently = true
}
if (field.sendData) {
alreadyInitialized = true
}
if (!isInternal) {
// If the status of a non-internal tracker has changed, inform
// the VRServer to recreate the skeleton, as it may need to
// assign or un-assign the tracker to a body part
vrServer.updateSkeletonModel()

checkReportErrorStatus()
checkReportRequireReset()
var status: TrackerStatus by Delegates.observable(TrackerStatus.DISCONNECTED) {
_, _, new ->
if (!new.reset) {
if (alreadyInitialized) {
statusResetRecently = true
}
alreadyInitialized = true
}
if (!isInternal) {
// If the status of a non-internal tracker has changed, inform
// the VRServer to recreate the skeleton, as it may need to
// assign or un-assign the tracker to a body part
vrServer.updateSkeletonModel()

checkReportErrorStatus()
checkReportRequireReset()
}
}

var trackerPosition = trackerPosition
set(value) {
if (field == value) return
field = value

if (!isInternal) {
checkReportRequireReset()
}
var trackerPosition: TrackerPosition? by Delegates.observable(trackerPosition) {
_, _, _ ->
if (!isInternal) {
checkReportRequireReset()
}
}

// Computed value to simplify availability checks
val hasAdjustedRotation = hasRotation && (allowFiltering || needsReset)
Expand All @@ -116,9 +110,11 @@ class Tracker @JvmOverloads constructor(
}

private fun checkReportRequireReset() {
if (needsReset && trackerPosition != null && lastResetStatus == 0u && status.sendData) {
if (needsReset && trackerPosition != null && lastResetStatus == 0u &&
!status.reset && (isImu() || !statusResetRecently)
) {
reportRequireReset()
} else if (lastResetStatus != 0u && (trackerPosition == null || !status.sendData)) {
} else if (lastResetStatus != 0u && (trackerPosition == null || status.reset)) {
vrServer.statusSystem.removeStatus(lastResetStatus)
lastResetStatus = 0u
}
Expand Down Expand Up @@ -203,6 +199,9 @@ class Tracker @JvmOverloads constructor(
resetsHandler.allowDriftCompensation = it
}
}
if (!isInternal && !(!isImu() && (trackerPosition == TrackerPosition.LEFT_HAND || trackerPosition == TrackerPosition.RIGHT_HAND))) {
checkReportRequireReset()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ class TrackerResetsHandler(val tracker: Tracker) {

// Let's just remove the status if you do yaw reset if the tracker was
// disconnected and then connected back
if (this.tracker.lastResetStatus != 0u && this.tracker.disconnectedRecently) {
if (this.tracker.lastResetStatus != 0u && this.tracker.statusResetRecently) {
vrServer.statusSystem.removeStatus(this.tracker.lastResetStatus)
this.tracker.disconnectedRecently = false
this.tracker.statusResetRecently = false
this.tracker.lastResetStatus = 0u
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package dev.slimevr.tracking.trackers

enum class TrackerStatus(val id: Int, val sendData: Boolean) {
enum class TrackerStatus(val id: Int, val sendData: Boolean, val reset: Boolean) {

DISCONNECTED(0, false),
OK(1, true),
BUSY(2, true),
ERROR(3, false),
OCCLUDED(4, false),
DISCONNECTED(0, false, true),
OK(1, true, false),
BUSY(2, true, false),
ERROR(3, false, true),
OCCLUDED(4, false, false),
;

companion object {
Expand Down

0 comments on commit 3068fad

Please sign in to comment.