mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Head tracking for the XREAL One, One Pro, One Pro+ and Aura (#2532)
* Head tracking for the XREAL One, One Pro, One Pro+ and Aura These glasses use the same USB Ethernet link and 128-byte IMU report as the 1S. XrealModel now has one model per product: the 1S keeps its tested display-mode control, and the others switch 2D and 3D only with GET_INPUT (0x2821) and SET_INPUT (0x2822). Display-mode set (0x275f), brightness and the dimmer are never sent to them. The Aura's IMU reads x right, y up, z back (about +9.8 m/s2 on y at rest), so its axes are not flipped like the rest of the family. Recovery-mode product ids (one below each) stay excluded. Signed-off-by: Mike Haye <84657517+mhaye20@users.noreply.github.com> * Describe the wider XREAL support in the glasses panel and docs The panel's help text and docs/smart-glasses-support.md named only the 1S. They now list the One, One Pro, One Pro+ and Aura, say what was tested on the Aura (head tracking and 2D/3D switching), and note that these models get 2D and SBS only, without brightness, dimming or display-mode set commands. Translations still describe the 1S only. Signed-off-by: Mike Haye <84657517+mhaye20@users.noreply.github.com> * Docs: XREAL support is no longer 1S only The paragraph under the support matrix still said the One and One Pro were excluded. Signed-off-by: Mike Haye <84657517+mhaye20@users.noreply.github.com> --------- Signed-off-by: Mike Haye <84657517+mhaye20@users.noreply.github.com>
This commit is contained in:
1 parent
253756d45f
commit
33cd43237e
11 files changed
+136
-45
No files matched your search
@@ -563,7 +563,7 @@ object Glasses {
|
||||
val device = selected?.first
|
||||
val m = selected?.second
|
||||
val controllable = m?.let(::canOpenModel) == true
|
||||
val permitted = controllable && device != null && (m === XrealModel || usb.hasPermission(device))
|
||||
val permitted = controllable && device != null && (m is XrealModel || usb.hasPermission(device))
|
||||
val identity = device?.let {
|
||||
GlassesModeState.Device(it.productId, if (permitted) runCatching { it.serialNumber }.getOrNull() else null)
|
||||
}
|
||||
@@ -614,9 +614,9 @@ object Glasses {
|
||||
sbs = sbsByDisplay,
|
||||
switching3d = modeState.pendingStereo,
|
||||
brightnessMax = m?.brightnessMax ?: 8, volumeMax = m?.volumeMax ?: 8,
|
||||
sunblock = if (m === XrealModel) it.sunblock else _settings.value.sunblock ?: it.sunblock,
|
||||
sunblock = if (m is XrealModel) it.sunblock else _settings.value.sunblock ?: it.sunblock,
|
||||
hardwareControls = m?.hardwareControls == true &&
|
||||
(device?.vendorId == VitureProtocol.VENDOR_ID || m === XrealModel || m is RokidModel),
|
||||
(device?.vendorId == VitureProtocol.VENDOR_ID || m is XrealModel || m is RokidModel),
|
||||
supportsDisplayModeControl = m?.supportsDisplayModeControl == true,
|
||||
hasSunblock = m?.hasSunblock == true,
|
||||
diagonalFovDeg = m?.diagonalFovDeg ?: 46f,
|
||||
@@ -624,7 +624,7 @@ object Glasses {
|
||||
noSignal = noSignal,
|
||||
sbs90 = m?.sbs90 == true,
|
||||
rates2d = m?.rates2d ?: listOf(60, 90, 120),
|
||||
experimental = m === XrealModel || (m is VitureProtocol.Model && m.family == VitureProtocol.Family.PRO2 && !m.needsSdk),
|
||||
experimental = m is XrealModel || (m is VitureProtocol.Model && m.family == VitureProtocol.Family.PRO2 && !m.needsSdk),
|
||||
supportsScreen3dof = link?.hasImu == true,
|
||||
supports30Hz = display?.let(::supports30Hz) == true,
|
||||
supportsSpatial = (link as? VitureSdkLink)?.isCarina == true,
|
||||
@@ -660,8 +660,8 @@ object Glasses {
|
||||
else VitureSdk.marketName(device.productId)?.let(VitureProtocol::sdkModel)
|
||||
?: VitureProtocol.model(device.productId, name)
|
||||
}
|
||||
else if (XrealModel.matches(device.vendorId, device.productId)) XrealModel
|
||||
else RokidModel.model(device.vendorId, device.productId, name)
|
||||
else XrealModel.model(device.vendorId, device.productId)
|
||||
?: RokidModel.model(device.vendorId, device.productId, name)
|
||||
?: RayNeoModel.model(device.vendorId, device.productId, name)
|
||||
}
|
||||
|
||||
@@ -729,8 +729,8 @@ object Glasses {
|
||||
VitureSdkLink.open(usb, device, File(app.noBackupFilesDir, "viture"), sdkListener(generation),
|
||||
(model as? VitureProtocol.Model)?.family, spatial)
|
||||
} else VitureLink.open(usb, device, linkListener(generation))
|
||||
} else if (model === XrealModel) {
|
||||
XrealLink.open(app, xrealListener(generation))
|
||||
} else if (model is XrealModel) {
|
||||
XrealLink.open(app, model as XrealModel, xrealListener(generation))
|
||||
} else if (model is RokidModel) {
|
||||
RokidLink.open(usb, device, rokidListener(generation))
|
||||
} else {
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.concurrent.atomic.AtomicReference
|
||||
internal class XrealLink internal constructor(
|
||||
private val connector: XrealConnector,
|
||||
private val listener: Listener,
|
||||
private val model: XrealModel = XrealModel.ONE_S,
|
||||
) : GlassesLink {
|
||||
interface Listener {
|
||||
fun onReady()
|
||||
@@ -29,7 +30,8 @@ internal class XrealLink internal constructor(
|
||||
private val worker = Thread(::run, "xreal-control").apply { isDaemon = true; start() }
|
||||
|
||||
companion object {
|
||||
fun open(context: Context, listener: Listener) = XrealLink(AndroidXrealConnector(context), listener)
|
||||
fun open(context: Context, model: XrealModel, listener: Listener) =
|
||||
XrealLink(AndroidXrealConnector(context), listener, model)
|
||||
}
|
||||
|
||||
override fun send(msgId: Int, payload: ByteArray): Boolean {
|
||||
@@ -43,9 +45,10 @@ internal class XrealLink internal constructor(
|
||||
if (msgId == VitureProtocol.MSG_GET_IMU) return true
|
||||
val valid = when (msgId) {
|
||||
VitureProtocol.MSG_GET_DISPLAY -> true
|
||||
VitureProtocol.MSG_DISPLAY -> value in 2..5 || value == XrealModel.NATIVE_60HZ
|
||||
VitureProtocol.MSG_BRIGHTNESS -> value in 0..9
|
||||
VitureProtocol.MSG_FILM -> value in 0..1
|
||||
VitureProtocol.MSG_DISPLAY -> if (model.stereoOnlyControl) value == 5 || value == XrealModel.NATIVE_60HZ
|
||||
else value in 2..5 || value == XrealModel.NATIVE_60HZ
|
||||
VitureProtocol.MSG_BRIGHTNESS -> !model.stereoOnlyControl && value in 0..9
|
||||
VitureProtocol.MSG_FILM -> !model.stereoOnlyControl && value in 0..1
|
||||
else -> false
|
||||
}
|
||||
return valid && commands.offer(Command(msgId, value))
|
||||
@@ -61,12 +64,12 @@ internal class XrealLink internal constructor(
|
||||
channels = connector.connect()
|
||||
connection.set(channels)
|
||||
if (!running) break
|
||||
val control = XrealControl(channels)
|
||||
val control = XrealControl(channels, stereoOnly = model.stereoOnlyControl)
|
||||
listener.onValue(VitureProtocol.MSG_GET_DISPLAY, control.display())
|
||||
val current = channels
|
||||
reports = Thread({
|
||||
try {
|
||||
var filter = XrealOrientationFilter()
|
||||
var filter = XrealOrientationFilter(model.flipsYz)
|
||||
var wasTracking = false
|
||||
var lastSensor = System.nanoTime()
|
||||
while (running && connection.get() === current) {
|
||||
@@ -75,7 +78,7 @@ internal class XrealLink internal constructor(
|
||||
if (sample != null) {
|
||||
lastSensor = System.nanoTime()
|
||||
val enabled = tracking
|
||||
if (enabled && !wasTracking) filter = XrealOrientationFilter()
|
||||
if (enabled && !wasTracking) filter = XrealOrientationFilter(model.flipsYz)
|
||||
wasTracking = enabled
|
||||
if (enabled) filter.update(sample)?.let {
|
||||
if (running && ready && tracking && connection.get() === current)
|
||||
@@ -149,7 +152,11 @@ internal class XrealLink internal constructor(
|
||||
}
|
||||
}
|
||||
|
||||
internal class XrealControl(private val channels: XrealChannels, private val settleDelayMs: Long = 150) {
|
||||
internal class XrealControl(
|
||||
private val channels: XrealChannels,
|
||||
private val settleDelayMs: Long = 150,
|
||||
private val stereoOnly: Boolean = false,
|
||||
) {
|
||||
private var transaction = 0
|
||||
private fun exchange(command: Int, value: Int? = null): ByteArray {
|
||||
transaction = if (transaction == Int.MAX_VALUE) 1 else transaction + 1
|
||||
@@ -163,26 +170,42 @@ internal class XrealControl(private val channels: XrealChannels, private val set
|
||||
throw IOException("XREAL control response was not received")
|
||||
}
|
||||
fun display(): Int {
|
||||
if (stereoOnly) return stereoDisplay()
|
||||
val reply = exchange(XrealProtocol.GET_DISPLAY)
|
||||
return XrealProtocol.numeric(reply)?.takeIf { it in 2..5 || it == XrealModel.NATIVE_60HZ }
|
||||
?: throw IOException("Unsupported XREAL display response: ${reply.take(32).joinToString("") { "%02x".format(it) }}")
|
||||
}
|
||||
private fun stereoDisplay(): Int {
|
||||
val reply = exchange(XrealProtocol.GET_INPUT)
|
||||
return when {
|
||||
XrealProtocol.acknowledged(reply) -> XrealModel.NATIVE_60HZ
|
||||
else -> when (XrealProtocol.numeric(reply)) {
|
||||
0 -> XrealModel.NATIVE_60HZ
|
||||
1 -> 5
|
||||
else -> throw IOException("Unsupported XREAL stereo response: ${reply.take(32).joinToString("") { "%02x".format(it) }}")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun changeDisplay(mode: Int): Int {
|
||||
val stereo = mode == 5
|
||||
set(XrealProtocol.SET_INPUT, if (stereo) 1 else 0)
|
||||
val current = awaitDisplay { (it == 5) == stereo }
|
||||
if (current == mode) return current
|
||||
if (current == mode || stereoOnly) return current
|
||||
set(XrealProtocol.SET_DISPLAY, mode)
|
||||
return awaitDisplay { it == mode }
|
||||
}
|
||||
private fun awaitDisplay(matches: (Int) -> Boolean): Int {
|
||||
val deadline = System.nanoTime() + 8_000_000_000L
|
||||
repeat(40) {
|
||||
val reply = exchange(XrealProtocol.GET_DISPLAY)
|
||||
val value = XrealProtocol.numeric(reply)
|
||||
if (value != null && matches(value)) return value
|
||||
if (value == null && !XrealProtocol.acknowledged(reply))
|
||||
throw IOException("Invalid XREAL display transition response")
|
||||
if (stereoOnly) {
|
||||
stereoDisplay().let { if (matches(it)) return it }
|
||||
} else {
|
||||
val reply = exchange(XrealProtocol.GET_DISPLAY)
|
||||
val value = XrealProtocol.numeric(reply)
|
||||
if (value != null && matches(value)) return value
|
||||
if (value == null && !XrealProtocol.acknowledged(reply))
|
||||
throw IOException("Invalid XREAL display transition response")
|
||||
}
|
||||
if (System.nanoTime() > deadline) throw IOException("XREAL display transition timed out")
|
||||
Thread.sleep(settleDelayMs)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,63 @@
|
||||
package com.droiddeck.launcher.glasses
|
||||
|
||||
object XrealModel : GlassesModel {
|
||||
const val VENDOR_ID = 0x3318
|
||||
const val PRODUCT_1S = 0x043e
|
||||
const val NATIVE_60HZ = 29
|
||||
override val name = "XREAL 1S"
|
||||
internal class XrealModel private constructor(
|
||||
override val name: String,
|
||||
val family: Family,
|
||||
override val diagonalFovDeg: Float,
|
||||
) : GlassesModel {
|
||||
enum class Family {
|
||||
ONE_S,
|
||||
ONE,
|
||||
AURA,
|
||||
}
|
||||
|
||||
override val controllable = true
|
||||
override val brightnessMax = 9
|
||||
override val volumeMax = 0
|
||||
override val hasSunblock = true
|
||||
override val diagonalFovDeg = 52f
|
||||
override val hasSunblock get() = family == Family.ONE_S
|
||||
override val hardwareControls get() = family == Family.ONE_S
|
||||
override val sbs90 = false
|
||||
override val rates2d get() = if (family == Family.ONE_S) super.rates2d else listOf(60)
|
||||
|
||||
fun matches(vid: Int, pid: Int) = vid == VENDOR_ID && pid == PRODUCT_1S
|
||||
fun isDisplay(name: String) = name.contains("XREAL", ignoreCase = true)
|
||||
// Only the 1S has been exercised with SET_DISPLAY; the Aura is known to reboot on an unexpected index.
|
||||
val stereoOnlyControl get() = family != Family.ONE_S
|
||||
|
||||
// The Aura reports x right, y up, z back; the rest of the One family is a half turn about x from it.
|
||||
val flipsYz get() = family != Family.AURA
|
||||
|
||||
override fun mode(hz: Int, sbs: Boolean) = when {
|
||||
sbs -> 5
|
||||
stereoOnlyControl -> NATIVE_60HZ
|
||||
hz >= 120 -> 4
|
||||
hz >= 90 -> 3
|
||||
else -> NATIVE_60HZ
|
||||
}
|
||||
override fun modeForStep(step: Int): Int? = null
|
||||
|
||||
override fun toString() = name
|
||||
|
||||
companion object {
|
||||
const val VENDOR_ID = 0x3318
|
||||
const val PRODUCT_1S = 0x043e
|
||||
const val NATIVE_60HZ = 29
|
||||
|
||||
val ONE_S = XrealModel("XREAL 1S", Family.ONE_S, 52f)
|
||||
val ONE = XrealModel("XREAL One", Family.ONE, 50f)
|
||||
val ONE_PRO = XrealModel("XREAL One Pro", Family.ONE, 57f)
|
||||
val ONE_PRO_PLUS = XrealModel("XREAL One Pro+", Family.ONE, 57f)
|
||||
val AURA = XrealModel("XREAL Aura", Family.AURA, 70f)
|
||||
|
||||
// The odd product ids one below these are the glasses' recovery mode.
|
||||
private val products = mapOf(
|
||||
PRODUCT_1S to ONE_S,
|
||||
0x0438 to ONE,
|
||||
0x0436 to ONE_PRO,
|
||||
0x0444 to ONE_PRO_PLUS,
|
||||
0x043a to AURA,
|
||||
)
|
||||
|
||||
fun model(vid: Int, pid: Int): XrealModel? = if (vid == VENDOR_ID) products[pid] else null
|
||||
fun matches(vid: Int, pid: Int) = model(vid, pid) != null
|
||||
fun isDisplay(name: String) = name.contains("XREAL", ignoreCase = true)
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,13 @@ package com.droiddeck.launcher.glasses
|
||||
|
||||
import kotlin.math.abs
|
||||
|
||||
internal class XrealOrientationFilter {
|
||||
internal class XrealOrientationFilter(private val flipYz: Boolean = true) {
|
||||
private val fusion = ImuFusion()
|
||||
|
||||
fun update(sample: XrealProtocol.Sample): FloatArray? = fusion.update(sample.timeNs,
|
||||
Vec3(sample.accel.x, -sample.accel.y, -sample.accel.z),
|
||||
Vec3(sample.gyro.x, -sample.gyro.y, -sample.gyro.z))
|
||||
sample.accel.headAxes(), sample.gyro.headAxes())
|
||||
|
||||
private fun Vec3.headAxes() = if (flipYz) Vec3(x, -y, -z) else this
|
||||
}
|
||||
|
||||
internal class ImuFusion {
|
||||
|
||||
@@ -13,6 +13,7 @@ internal object XrealProtocol {
|
||||
const val REPORT = 0x2836
|
||||
const val GET_DISPLAY = 0x275e
|
||||
const val SET_DISPLAY = 0x275f
|
||||
const val GET_INPUT = 0x2821
|
||||
const val SET_INPUT = 0x2822
|
||||
const val SET_BRIGHTNESS = 0x271c
|
||||
const val SET_DIMMER = 0x2727
|
||||
|
||||
Reference in new issue
Block a user