mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
fix(glasses): correct One Pro+ tracking and enable verified controls (#2680)
* fix(glasses): correct One Pro+ tracking and enable verified controls * fix(i18n): translate current XREAL family guidance
This commit is contained in:
1 parent
2a51b044c5
commit
ee6cf20ae4
42 files changed
+325
-68
No files matched your search
@@ -265,6 +265,34 @@ class GlassesUsbTest {
|
||||
assertEquals(null, Glasses.deviceModel(device(0x043e, 0x1234, "XREAL 1S")))
|
||||
}
|
||||
|
||||
@Test fun xrealProPlusUsesEthernetPermissionAndItsOwnOptics() {
|
||||
val pro = device(0x0444, 0x3318, "XREAL 1 Pro+")
|
||||
manager.devices[pro.deviceName] = pro
|
||||
field("linkDevice").set(null, pro)
|
||||
field("link").set(null, object : GlassesLink {
|
||||
override val hasImu = true
|
||||
override fun send(msgId: Int, payload: ByteArray) = true
|
||||
override fun close() {}
|
||||
})
|
||||
try {
|
||||
refresh(ask = true)
|
||||
assertEquals("XREAL One Pro+", state.value.model)
|
||||
assertEquals(Glasses.Permission.GRANTED, state.value.permission)
|
||||
assertTrue(manager.requests.isEmpty())
|
||||
assertTrue(state.value.canControl)
|
||||
assertTrue(state.value.hardwareControls)
|
||||
assertTrue(state.value.supportsScreen3dof)
|
||||
assertFalse(state.value.supportsSpatial)
|
||||
assertEquals(57f, state.value.diagonalFovDeg, 0f)
|
||||
assertEquals(9, state.value.brightnessMax)
|
||||
assertEquals(0, state.value.volumeMax)
|
||||
} finally {
|
||||
field("link").set(null, null)
|
||||
field("linkDevice").set(null, null)
|
||||
(field("handler").get(null) as Handler).removeCallbacksAndMessages(null)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun rokidMaxRoutesThroughItsOwnModelAndSharedVendorIdNeedsTheName() {
|
||||
val max = Glasses.deviceModel(device(0x162f, 0x04d2, "Rokid Max"))
|
||||
assertTrue(max is RokidModel)
|
||||
|
||||
@@ -38,7 +38,7 @@ class XrealLinkTest {
|
||||
override fun close() { closed = true; bytes.clear(); bytes.offer(-1) }
|
||||
}
|
||||
|
||||
private class Channels : XrealChannels {
|
||||
private class Channels(private val displayMode: Int = 2) : XrealChannels {
|
||||
override val controlInput = Input()
|
||||
override val reports = Input()
|
||||
val wrote = LinkedBlockingQueue<Int>()
|
||||
@@ -53,7 +53,7 @@ class XrealLinkTest {
|
||||
val id = ByteBuffer.wrap(request.body).int and Int.MAX_VALUE
|
||||
wrote.offer(request.command)
|
||||
if (acknowledge) controlInput.add(XrealProtocolTest.response(request.command, id,
|
||||
if (request.command == XrealProtocol.GET_DISPLAY) byteArrayOf(0x22, 2, 0x10, 2) else byteArrayOf(0x22, 0)))
|
||||
if (request.command == XrealProtocol.GET_DISPLAY) byteArrayOf(0x22, 2, 0x10, displayMode.toByte()) else byteArrayOf(0x22, 0)))
|
||||
}
|
||||
}
|
||||
override fun close() { controlInput.close(); reports.close(); closed.countDown() }
|
||||
@@ -113,6 +113,27 @@ class XrealLinkTest {
|
||||
} finally { link.close() }
|
||||
}
|
||||
|
||||
@Test fun proPlusRejects1sOnlyModesAndKeepsBrightnessWithinTheSupportedRange() {
|
||||
val channels = Channels(9)
|
||||
val listener = Listener()
|
||||
val link = XrealLink(object : XrealConnector {
|
||||
override fun connect() = channels
|
||||
override fun close() = channels.close()
|
||||
}, listener, XrealModel.ONE_PRO_PLUS)
|
||||
try {
|
||||
assertTrue(listener.ready.await(2, TimeUnit.SECONDS))
|
||||
assertEquals(VitureProtocol.MSG_GET_DISPLAY to 9, listener.values.poll(2, TimeUnit.SECONDS))
|
||||
assertEquals(XrealProtocol.GET_DISPLAY, channels.wrote.poll(2, TimeUnit.SECONDS))
|
||||
assertFalse(link.send(VitureProtocol.MSG_DISPLAY, byteArrayOf(29)))
|
||||
assertFalse(link.send(VitureProtocol.MSG_DISPLAY, byteArrayOf(2)))
|
||||
assertFalse(link.send(VitureProtocol.MSG_BRIGHTNESS, byteArrayOf(10)))
|
||||
assertTrue(channels.wrote.isEmpty())
|
||||
assertTrue(link.send(VitureProtocol.MSG_BRIGHTNESS, byteArrayOf(9)))
|
||||
assertEquals(VitureProtocol.MSG_BRIGHTNESS to 9, listener.values.poll(2, TimeUnit.SECONDS))
|
||||
assertEquals(XrealProtocol.SET_BRIGHTNESS, channels.wrote.poll(2, TimeUnit.SECONDS))
|
||||
} finally { link.close() }
|
||||
}
|
||||
|
||||
@Test fun missingNetworkIsReportedAndCloseCancelsRetry() {
|
||||
val listener = Listener()
|
||||
val closed = AtomicBoolean()
|
||||
|
||||
@@ -61,9 +61,9 @@ class XrealOrientationFilterTest {
|
||||
}
|
||||
|
||||
@Test fun auraAxesAreNotFlippedLikeTheRestOfTheOneFamily() {
|
||||
val aura = XrealOrientationFilter(flipYz = false).update(sample(1000000, accel = Vec3(0f, 9.81f, 0f)))!!
|
||||
val aura = XrealOrientationFilter(XrealModel.AURA).update(sample(1000000, accel = Vec3(0f, 9.81f, 0f)))!!
|
||||
assertTrue(matrix(aura)[7] > 0.99f)
|
||||
assertNull(XrealOrientationFilter(flipYz = false).update(sample(1000000, accel = Vec3(0f, 0f, 0f))))
|
||||
assertNull(XrealOrientationFilter(XrealModel.AURA).update(sample(1000000, accel = Vec3(0f, 0f, 0f))))
|
||||
}
|
||||
|
||||
@Test fun capturedNeutralGravityStartsUprightBeforeRecenter() {
|
||||
@@ -73,4 +73,93 @@ class XrealOrientationFilterTest {
|
||||
val screen = matrix(pose)
|
||||
assertTrue(screen[7] > 0.99f)
|
||||
}
|
||||
|
||||
@Test fun proPlusMountStartsUprightBeforeRecenter() {
|
||||
val neutral = sample(1000000)
|
||||
val expected = matrix(XrealOrientationFilter().update(neutral)!!)
|
||||
val actual = matrix(XrealOrientationFilter(XrealModel.ONE_PRO_PLUS).update(proPlusSample(neutral))!!)
|
||||
assertArrayEquals(expected, actual, 0.0001f)
|
||||
assertEquals(1f, actual[7], 0.0001f)
|
||||
}
|
||||
|
||||
@Test fun proPlusMountKeepsBothDirectionsOfEveryAxisCorrectThroughBothRecenterModes() {
|
||||
for (axis in listOf("pitch", "yaw", "roll")) for (direction in listOf(-1, 1)) {
|
||||
val ideal = XrealOrientationFilter()
|
||||
val mounted = XrealOrientationFilter(XrealModel.ONE_PRO_PLUS)
|
||||
val initial = sample(1000000)
|
||||
val firstIdeal = matrix(ideal.update(initial)!!)
|
||||
val firstMounted = matrix(mounted.update(proPlusSample(initial))!!)
|
||||
var middleIdeal = firstIdeal
|
||||
var middleMounted = firstMounted
|
||||
var lastIdeal = firstIdeal
|
||||
var lastMounted = firstMounted
|
||||
val rate = direction * (Math.PI / 6).toFloat()
|
||||
repeat(1000) {
|
||||
val angle = rate * (it + 1) / 1000f
|
||||
val accel = when (axis) {
|
||||
"pitch" -> Vec3(0f, -9.81f * cos(angle), 9.81f * sin(angle))
|
||||
"yaw" -> Vec3(0f, -9.81f, 0f)
|
||||
else -> Vec3(-9.81f * sin(angle), -9.81f * cos(angle), 0f)
|
||||
}
|
||||
val gyro = when (axis) {
|
||||
"pitch" -> Vec3(rate, 0f, 0f)
|
||||
"yaw" -> Vec3(0f, -rate, 0f)
|
||||
else -> Vec3(0f, 0f, rate)
|
||||
}
|
||||
val frame = sample((it + 2) * 1000000L, gyro, accel)
|
||||
lastIdeal = matrix(ideal.update(frame)!!)
|
||||
lastMounted = matrix(mounted.update(proPlusSample(frame))!!)
|
||||
if (it == 499) {
|
||||
middleIdeal = lastIdeal
|
||||
middleMounted = lastMounted
|
||||
}
|
||||
}
|
||||
for (centerView in listOf(false, true)) {
|
||||
val label = "$axis $direction centerView=$centerView"
|
||||
val idealView = HeadPose.relative(HeadPose.recenter(firstIdeal, centerView), lastIdeal)
|
||||
val mountedView = HeadPose.relative(HeadPose.recenter(firstMounted, centerView), lastMounted)
|
||||
assertArrayEquals(label, axisMatrix(axis, rate), mountedView, 0.002f)
|
||||
assertArrayEquals(label, idealView, mountedView, 0.0001f)
|
||||
|
||||
val idealRecentered = HeadPose.relative(HeadPose.recenter(middleIdeal, centerView), lastIdeal)
|
||||
val mountedRecentered = HeadPose.relative(HeadPose.recenter(middleMounted, centerView), lastMounted)
|
||||
val recenteredAngle = if (centerView || axis == "yaw") rate / 2 else rate
|
||||
assertArrayEquals("$label after mid-turn recenter", axisMatrix(axis, recenteredAngle), mountedRecentered, 0.002f)
|
||||
assertArrayEquals("$label after mid-turn recenter", idealRecentered, mountedRecentered, 0.0001f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun recordedProPlusTurnAxesStayOnYawAndRoll() {
|
||||
val recordedAxes = mapOf("yaw" to Vec3(0.052f, 0.867f, -0.496f), "roll" to Vec3(0.033f, 0.625f, 0.780f))
|
||||
for ((label, gyro) in recordedAxes) {
|
||||
val filter = XrealOrientationFilter(XrealModel.ONE_PRO_PLUS)
|
||||
val first = matrix(filter.update(sample(1000000))!!)
|
||||
var last = first
|
||||
repeat(100) {
|
||||
last = matrix(filter.update(sample((it + 2) * 1000000L, gyro, Vec3(0f, 0f, 0f)))!!)
|
||||
}
|
||||
val view = HeadPose.relative(HeadPose.recenter(first, centerView = true), last)
|
||||
val axis = Vec3(view[7] - view[5], view[2] - view[6], view[3] - view[1]).normalized()
|
||||
val projection = if (label == "yaw") -axis.y else -axis.z
|
||||
assertTrue("Recorded $label axis should be within 10 degrees of the display axis",
|
||||
projection > cos(Math.toRadians(10.0).toFloat()))
|
||||
}
|
||||
}
|
||||
|
||||
private fun proPlusSample(sample: XrealProtocol.Sample): XrealProtocol.Sample {
|
||||
val angle = Math.toRadians(-35.0).toFloat()
|
||||
fun mounted(v: Vec3) = Vec3(v.x, cos(angle) * v.y - sin(angle) * v.z, sin(angle) * v.y + cos(angle) * v.z)
|
||||
return XrealProtocol.Sample(sample.timeNs, mounted(sample.gyro), mounted(sample.accel))
|
||||
}
|
||||
|
||||
private fun axisMatrix(axis: String, angle: Float): FloatArray {
|
||||
val c = cos(angle)
|
||||
val s = sin(angle)
|
||||
return when (axis) {
|
||||
"pitch" -> floatArrayOf(1f, 0f, 0f, 0f, c, -s, 0f, s, c)
|
||||
"yaw" -> floatArrayOf(c, 0f, s, 0f, 1f, 0f, -s, 0f, c)
|
||||
else -> floatArrayOf(c, s, 0f, -s, c, 0f, 0f, 0f, 1f)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,17 +70,24 @@ class XrealProtocolTest {
|
||||
}
|
||||
|
||||
@Test fun stereoOnlyControlSwitches3dWithoutDisplayModeCommands() {
|
||||
val output = ByteArrayOutputStream()
|
||||
val replies = response(XrealProtocol.GET_INPUT, 1, byteArrayOf(0x22, 0)) +
|
||||
response(XrealProtocol.SET_INPUT, 2, byteArrayOf(0x22, 0)) +
|
||||
response(XrealProtocol.GET_INPUT, 3, byteArrayOf(0x22, 2, 0x10, 1))
|
||||
val control = XrealControl(channels(replies.inputStream(), output), stereoOnly = true, settleDelayMs = 0)
|
||||
assertEquals(XrealModel.NATIVE_60HZ, control.display())
|
||||
assertEquals(5, control.changeDisplay(5))
|
||||
val written = output.toByteArray().inputStream()
|
||||
val commands = List(3) { XrealProtocol.read(written).command }
|
||||
assertEquals(listOf(XrealProtocol.GET_INPUT, XrealProtocol.SET_INPUT, XrealProtocol.GET_INPUT), commands)
|
||||
assertFalse(commands.any { it == XrealProtocol.GET_DISPLAY || it == XrealProtocol.SET_DISPLAY })
|
||||
for (model in listOf(XrealModel.ONE, XrealModel.ONE_PRO, XrealModel.AURA)) {
|
||||
assertFalse(model.hardwareControls)
|
||||
assertFalse(model.hasSunblock)
|
||||
assertEquals(listOf(60), model.rates2d)
|
||||
assertFalse(model.supportsDisplayMode(9))
|
||||
assertFalse(model.supportsDisplayMode(3))
|
||||
val output = ByteArrayOutputStream()
|
||||
val replies = response(XrealProtocol.GET_INPUT, 1, byteArrayOf(0x22, 0)) +
|
||||
response(XrealProtocol.SET_INPUT, 2, byteArrayOf(0x22, 0)) +
|
||||
response(XrealProtocol.GET_INPUT, 3, byteArrayOf(0x22, 2, 0x10, 1))
|
||||
val control = XrealControl(channels(replies.inputStream(), output), model = model, settleDelayMs = 0)
|
||||
assertEquals(XrealModel.NATIVE_60HZ, control.display())
|
||||
assertEquals(5, control.changeDisplay(5))
|
||||
val written = output.toByteArray().inputStream()
|
||||
val commands = List(3) { XrealProtocol.read(written).command }
|
||||
assertEquals(listOf(XrealProtocol.GET_INPUT, XrealProtocol.SET_INPUT, XrealProtocol.GET_INPUT), commands)
|
||||
assertFalse(commands.any { it == XrealProtocol.GET_DISPLAY || it == XrealProtocol.SET_DISPLAY })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun unrelatedResponsesCannotKeepControlWaitingForever() {
|
||||
@@ -125,6 +132,44 @@ class XrealProtocolTest {
|
||||
assertThrows(IOException::class.java) { control.changeDisplay(5) }
|
||||
}
|
||||
|
||||
@Test fun proPlusKeeps1080pModesSeparateFrom1sNative1200p() {
|
||||
val pro = XrealModel.ONE_PRO_PLUS
|
||||
assertEquals(9, pro.mode(60, false))
|
||||
assertEquals(3, pro.mode(90, false))
|
||||
assertEquals(4, pro.mode(120, false))
|
||||
assertEquals(5, pro.mode(120, true))
|
||||
assertFalse(pro.sbs90)
|
||||
assertEquals(listOf(60, 90, 120), pro.rates2d)
|
||||
assertEquals(57f, pro.diagonalFovDeg, 0f)
|
||||
assertEquals(29, XrealModel.ONE_S.mode(60, false))
|
||||
assertEquals(52f, XrealModel.ONE_S.diagonalFovDeg, 0f)
|
||||
}
|
||||
|
||||
@Test fun proPlusRejects1sOnlyDisplayResponsesAndCommands() {
|
||||
for (mode in listOf(2, 29)) {
|
||||
val response = response(XrealProtocol.GET_DISPLAY, 1, byteArrayOf(0x22, 2, 0x10, mode.toByte()))
|
||||
val output = ByteArrayOutputStream()
|
||||
val control = XrealControl(channels(response.inputStream(), output), model = XrealModel.ONE_PRO_PLUS)
|
||||
assertThrows(IOException::class.java) { control.display() }
|
||||
output.reset()
|
||||
assertThrows(IllegalArgumentException::class.java) { control.changeDisplay(mode) }
|
||||
assertEquals(0, output.size())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun proPlusCanReturnFromStereoToIts1080p60HzMode() {
|
||||
val output = ByteArrayOutputStream()
|
||||
val replies = response(XrealProtocol.SET_INPUT, 1, byteArrayOf(0x22, 0)) +
|
||||
response(XrealProtocol.GET_DISPLAY, 2, byteArrayOf(0x22, 0)) +
|
||||
response(XrealProtocol.GET_DISPLAY, 3, byteArrayOf(0x22, 2, 0x10, 9))
|
||||
val control = XrealControl(channels(replies.inputStream(), output), 0, XrealModel.ONE_PRO_PLUS)
|
||||
assertEquals(9, control.changeDisplay(XrealModel.ONE_PRO_PLUS.mode(60, false)))
|
||||
val requests = output.toByteArray().inputStream()
|
||||
assertEquals(XrealProtocol.SET_INPUT, XrealProtocol.read(requests).command)
|
||||
repeat(2) { assertEquals(XrealProtocol.GET_DISPLAY, XrealProtocol.read(requests).command) }
|
||||
assertEquals(0, requests.available())
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun sensor(time: Long = 123456789L): ByteArray = ByteBuffer.allocate(128).order(ByteOrder.LITTLE_ENDIAN)
|
||||
.putLong(8, time).putInt(24, 11).putFloat(32, 0.5f).putFloat(44, 9.81f).array()
|
||||
|
||||
Reference in new issue
Block a user