mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Add support for using RayNeo iO together with an R1 ring
This commit is contained in:
1 parent
dee60bbcd2
commit
fde847a31a
10 files changed
+172
-47
No files matched your search
@@ -4,7 +4,7 @@ import { type InputEvent } from "../../ui/gestures";
|
||||
import { Layer, type LayerContext } from "../../ui/layers";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { MenuLayer, type MenuItem } from "../../ui/menu";
|
||||
import { ringConnectionModeSetting } from "../../ui/dashboard-settings";
|
||||
import { effectiveRingConnectionMode, ringConnectionModeSetting } from "../../ui/dashboard-settings";
|
||||
import { loadDeviceAddresses } from "../../g2/device-addresses";
|
||||
import {
|
||||
getRingSessionStatus,
|
||||
@@ -146,7 +146,7 @@ export class RingStatusLayer implements Layer {
|
||||
}
|
||||
|
||||
if (!s.directEnabled) {
|
||||
const pending = ringConnectionModeSetting.get() !== "glasses";
|
||||
const pending = effectiveRingConnectionMode() !== "glasses";
|
||||
rows.push({ label: "Direct link", value: pending ? "on after glasses reconnect" : "off (only via glasses)", dim: true });
|
||||
} else {
|
||||
const state = s.directNotificationsReady ? "subscribed"
|
||||
|
||||
@@ -78,7 +78,7 @@ import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-a
|
||||
import { appViewportRect, isOnSwitcherEdge, screenHeight, screenWidth, sidebarStripVisible, type ScreenRect, type WindowHeightMode } from "../ui/shell/geometry";
|
||||
import { type ContinuousCaptureOptions, type LayerActions, type TextSettingsEditToggle, type TranscriptionChoice } from "../ui/layers";
|
||||
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
|
||||
import { appSwitcherPositionSetting, glassesTypeSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||
import { appSwitcherPositionSetting, glassesTypeSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayLayoutSetting, navigateDisplayLayoutSetting, terminalDisplayLayoutSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, whisperServerApiKeySetting, whisperServerLanguageSetting, whisperServerModelSetting, whisperServerUrlSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, effectiveRingConnectionMode, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||
import {
|
||||
getInstalledEvenHubAppById,
|
||||
@@ -1047,9 +1047,11 @@ class DashboardController {
|
||||
|
||||
/**
|
||||
* A Direct-mode session may have unpaired the R1 from the glasses (see
|
||||
* GlassesSessionRing.releaseRingFromGlassesLocked). The first session in
|
||||
* another mode asks the glasses to connect to it again; the ring's own
|
||||
* glasses targets were cleared, so it accepts them. Called on connect.
|
||||
* GlassesSessionRing.releaseRingFromGlassesLocked), and a RayNeo iO
|
||||
* session (always Direct) may have cleared the ring's glasses targets.
|
||||
* The first G2 session in another mode asks the glasses to connect to it
|
||||
* again; the ring's own glasses targets were cleared, so it accepts them.
|
||||
* Called on connect.
|
||||
*/
|
||||
private handRingBackToGlassesIfNeeded(): void {
|
||||
if (this.ringModeAtConnect === "direct" || !getBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, false)) return;
|
||||
@@ -1488,20 +1490,21 @@ class DashboardController {
|
||||
this.refreshEvenAppStatus();
|
||||
this.setPhase("connecting");
|
||||
this.setStatus("Connecting to the glasses...");
|
||||
// "Only via glasses" (the default) means the phone never opens its own
|
||||
// link to the ring: the glasses relay its gestures to us anyway. An empty
|
||||
// address disables every direct-ring code path in the communicator.
|
||||
const ringMode = ringConnectionModeSetting.get();
|
||||
// "Only via glasses" (the G2's default) means the phone never opens its
|
||||
// own link to the ring: the glasses relay its gestures to us anyway. An
|
||||
// empty address disables every direct-ring code path in the communicator.
|
||||
// A RayNeo iO (one link, its address in both arm slots) can't relay a
|
||||
// ring, so with one the phone always takes the ring directly.
|
||||
const ringMode = effectiveRingConnectionMode();
|
||||
this.ringModeAtConnect = ringMode;
|
||||
// A RayNeo iO is one link (its address in both arm slots) and has no ring.
|
||||
const glassesType = glassesTypeSetting.get();
|
||||
const ringAddress = ringMode !== "glasses" && glassesType === "g2" ? addresses.ring : "";
|
||||
const ringAddress = ringMode !== "glasses" ? addresses.ring : "";
|
||||
// Direct mode may unpair the ring from the glasses; remember to hand it
|
||||
// back once a later session runs in another mode.
|
||||
if (ringMode === "direct" && ringAddress) setBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, true);
|
||||
this.appendLog(glassesType === "rayneo-io"
|
||||
this.appendLog((glassesType === "rayneo-io"
|
||||
? `Using configured RayNeo iO: ${addresses.right}`
|
||||
: `Using configured arms: R=${addresses.right} L=${addresses.left}${ringAddress ? ` ring=${ringAddress}` : ""}`,
|
||||
: `Using configured arms: R=${addresses.right} L=${addresses.left}`) + (ringAddress ? ` ring=${ringAddress}` : ""),
|
||||
);
|
||||
|
||||
let communicator: FaceclawCommunicatorBridge | null = null;
|
||||
|
||||
@@ -68,7 +68,7 @@ export class PairingViewModel extends Observable {
|
||||
private _ringRows: PairingRowItem[] = [];
|
||||
private selectedPair: GlassesPairCandidate | null = null;
|
||||
private selectedRing: RingCandidate | null = null;
|
||||
/** A RayNeo iO instead of a G2 pair (the two are exclusive). */
|
||||
/** A RayNeo iO instead of a G2 pair (the two are exclusive; either takes a ring). */
|
||||
private selectedIo: RayNeoCandidate | null = null;
|
||||
private readonly previouslyPairedSerial: string | null;
|
||||
private readonly previouslyPairedRing: string;
|
||||
@@ -186,7 +186,7 @@ export class PairingViewModel extends Observable {
|
||||
|
||||
get instructions(): string {
|
||||
return (
|
||||
"Select your G2 glasses and R1 ring, or your RayNeo iO, below. Wear the glasses or take them out of the case, " +
|
||||
"Select your G2 glasses or RayNeo iO, and your R1 ring if you have one, below. Wear the glasses or take them out of the case, " +
|
||||
"and keep the glasses and phone nearby. If your glasses are not detected, make sure no other " +
|
||||
"apps are connected."
|
||||
);
|
||||
@@ -298,10 +298,7 @@ export class PairingViewModel extends Observable {
|
||||
if (row.kind === "rayneo-io") {
|
||||
const io = this.aggregator.rayneos().find((candidate) => candidate.id === row.id) ?? null;
|
||||
this.selectedIo = this.selectedIo?.id === io?.id ? null : io;
|
||||
if (this.selectedIo) {
|
||||
this.selectedPair = null;
|
||||
this.selectedRing = null;
|
||||
}
|
||||
if (this.selectedIo) this.selectedPair = null;
|
||||
} else if (row.kind === "glasses") {
|
||||
const pair = this.aggregator.pairs().find((candidate) => candidate.id === row.id) ?? null;
|
||||
if (!pair) return;
|
||||
@@ -314,17 +311,24 @@ export class PairingViewModel extends Observable {
|
||||
} else {
|
||||
const ring = this.aggregator.rings().find((candidate) => candidate.id === row.id) ?? null;
|
||||
this.selectedRing = this.selectedRing?.id === ring?.id ? null : ring;
|
||||
if (this.selectedRing) this.selectedIo = null;
|
||||
}
|
||||
this.refresh();
|
||||
};
|
||||
|
||||
onPrimaryTap(): void {
|
||||
const io = this.selectedIo;
|
||||
const pair = this.selectedPair;
|
||||
const ring = this.selectedRing;
|
||||
const existing = loadDeviceAddresses();
|
||||
// Glasses saved without a ring selected keep the ring paired before.
|
||||
const ringAddress = ring?.advertisement.address ?? existing.ring;
|
||||
const ringName = ring?.advertisement.name ??
|
||||
(ringAddress === existing.ring ? (loadPairedGlassesIdentity()?.ringName ?? "") : "");
|
||||
if (io) {
|
||||
// One link: the same address stands for both arms; no ring.
|
||||
// One link: the same address stands for both arms. The iO can't relay a
|
||||
// ring, so the session connects to it directly (Direct ring mode).
|
||||
const address = io.advertisement.address;
|
||||
saveDeviceAddresses({ right: address, left: address, ring: "" });
|
||||
saveDeviceAddresses({ right: address, left: address, ring: ringAddress });
|
||||
glassesTypeSetting.set("rayneo-io");
|
||||
savePairedGlassesIdentity({
|
||||
serial: io.advertisement.embeddedMac ?? address,
|
||||
@@ -332,8 +336,8 @@ export class PairingViewModel extends Observable {
|
||||
rightName: io.advertisement.name,
|
||||
leftAddress: address,
|
||||
rightAddress: address,
|
||||
ringName: "",
|
||||
ringAddress: "",
|
||||
ringName,
|
||||
ringAddress,
|
||||
pairedAtMs: Date.now(),
|
||||
});
|
||||
this.dispose();
|
||||
@@ -343,18 +347,15 @@ export class PairingViewModel extends Observable {
|
||||
finishOnboardingNavigation();
|
||||
return;
|
||||
}
|
||||
const pair = this.selectedPair;
|
||||
const ring = this.selectedRing;
|
||||
if (!pair && !ring) return;
|
||||
// refresh() drops a selection whose pair regressed below complete, but the
|
||||
// tap can race a prune: never fall back to previously stored addresses for
|
||||
// a missing arm — that silently welds together arms of two different pairs.
|
||||
if (pair && (!pair.left || !pair.right)) return;
|
||||
const existing = loadDeviceAddresses();
|
||||
const addresses = {
|
||||
right: pair ? pair.right!.address : existing.right,
|
||||
left: pair ? pair.left!.address : existing.left,
|
||||
ring: ring?.advertisement.address ?? existing.ring,
|
||||
ring: ringAddress,
|
||||
};
|
||||
saveDeviceAddresses(addresses);
|
||||
if (pair) glassesTypeSetting.set("g2");
|
||||
@@ -365,8 +366,8 @@ export class PairingViewModel extends Observable {
|
||||
rightName: pair.right!.name,
|
||||
leftAddress: pair.left!.address,
|
||||
rightAddress: pair.right!.address,
|
||||
ringName: ring?.advertisement.name ?? (addresses.ring === existing.ring ? (loadPairedGlassesIdentity()?.ringName ?? "") : ""),
|
||||
ringAddress: addresses.ring,
|
||||
ringName,
|
||||
ringAddress,
|
||||
pairedAtMs: Date.now(),
|
||||
});
|
||||
} else if (ring) {
|
||||
|
||||
@@ -874,9 +874,18 @@ export const ringConnectionModeSetting = new ConfigSettingEnum<RingConnectionMod
|
||||
formatValue: (value) =>
|
||||
value === "direct" ? "Direct to phone" : value === "health" ? "Via glasses + health sync" : "Only via glasses",
|
||||
description:
|
||||
"How the R1 ring reaches the phone. Only via glasses: the glasses relay the ring's gestures and the phone never connects to it. Via glasses + health sync: the same, plus the phone connects to the ring to sync health data. Direct to phone (experimental): the phone takes the ring over from the glasses and gets its gestures and battery itself; the glasses lose ring input. Health still syncs, but each sync (on opening Health, and at :01 and :31) pauses ring gestures for up to a minute while the phone briefly reconnects to the ring in its health role. Leaving Direct hands the ring back to the glasses. Takes effect on the next connection to the glasses.",
|
||||
"How the R1 ring reaches the phone. Only via glasses: the glasses relay the ring's gestures and the phone never connects to it. Via glasses + health sync: the same, plus the phone connects to the ring to sync health data. Direct to phone (experimental): the phone takes the ring over from the glasses and gets its gestures and battery itself; the glasses lose ring input. Health still syncs, but each sync (on opening Health, and at :01 and :31) pauses ring gestures for up to a minute while the phone briefly reconnects to the ring in its health role. Leaving Direct hands the ring back to the glasses. A RayNeo iO has no ring link of its own, so with one the phone always connects to the ring directly. Takes effect on the next connection to the glasses.",
|
||||
});
|
||||
|
||||
/**
|
||||
* The ring connection in effect: the setting with G2 glasses; Direct with a
|
||||
* RayNeo iO, which cannot relay a ring, so the phone holds the ring's
|
||||
* glasses role itself (gestures, battery; health in brief phone-role windows).
|
||||
*/
|
||||
export function effectiveRingConnectionMode(): RingConnectionMode {
|
||||
return glassesTypeSetting.get() === "rayneo-io" ? "direct" : ringConnectionModeSetting.get();
|
||||
}
|
||||
|
||||
// "whisper" (no "onboard-" prefix) is OpenAI's CLOUD realtime model
|
||||
// (gpt-realtime-whisper); "onboard-whisper" is the on-device sherpa-onnx
|
||||
// Whisper backend. Same underlying model family, two different places it
|
||||
|
||||
@@ -67,6 +67,7 @@ import {
|
||||
previewScalingSetting,
|
||||
phoneRotationSetting,
|
||||
ringConnectionModeSetting,
|
||||
glassesTypeSetting,
|
||||
sonioxApiKeySetting,
|
||||
saveTranscribeAudioSetting,
|
||||
whisperServerApiKeySetting,
|
||||
@@ -224,7 +225,7 @@ function settingsSections(): SettingsSection[] {
|
||||
items: [
|
||||
// Whether and how the phone opens its own BLE link to the R1 ring.
|
||||
// Applied at connect time.
|
||||
enumSettingMenuItem(ringConnectionModeSetting),
|
||||
ringConnectionMenuItem(),
|
||||
toggleSettingMenuItem(saveVoiceRecordingsSetting),
|
||||
toggleSettingMenuItem(firmwareDebugFlagsSetting),
|
||||
toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting),
|
||||
@@ -598,6 +599,24 @@ function readBundledDoc(fileName: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Developer > Ring connection: the setting, except with a RayNeo iO, which
|
||||
* always takes the ring directly (effectiveRingConnectionMode): then a fixed,
|
||||
* disabled "Direct" row, the stored choice kept for G2 glasses.
|
||||
*/
|
||||
function ringConnectionMenuItem(): MenuItem {
|
||||
const item = enumSettingMenuItem(ringConnectionModeSetting);
|
||||
const io = () => glassesTypeSetting.get() === "rayneo-io";
|
||||
return {
|
||||
...item,
|
||||
disabled: io,
|
||||
render: (args) => {
|
||||
if (!io()) return item.render?.(args);
|
||||
drawRightValueMenuItem(args.image, getDefaultSmallFont(), args.x, args.y, args.width, item.label, "Direct (RayNeo iO)");
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function renderWatchStatus(args: { image: GrayImage; x: number; y: number; width: number }): number {
|
||||
const { image, x, y, width } = args;
|
||||
const font = getDefaultSmallFont();
|
||||
|
||||
+6
-4
@@ -1792,14 +1792,15 @@ class GlassesSessionCore(
|
||||
return
|
||||
}
|
||||
val uuid = characteristicUuid.lowercase()
|
||||
if (isIo) {
|
||||
ioOnNotification(address, uuid, data)
|
||||
return
|
||||
}
|
||||
// The phone's own R1 link, beside either glasses (the iO's ring is always direct).
|
||||
if (isDirectRingNotification(address, uuid)) {
|
||||
handleDirectRingNotification(uuid, data)
|
||||
return
|
||||
}
|
||||
if (isIo) {
|
||||
ioOnNotification(address, uuid, data)
|
||||
return
|
||||
}
|
||||
if (BleProtocol.RENDER_NOTIFY_UUID == uuid) {
|
||||
handleRenderNotification(address, data)
|
||||
return
|
||||
@@ -2100,6 +2101,7 @@ class GlassesSessionCore(
|
||||
lastConnectionOrInputAtMs = arrivalMs
|
||||
lastDirectRingInputAtMs = arrivalMs
|
||||
lastDirectRingInputLabel = decoded.label + " " + decoded.detail
|
||||
if (isIo) ioReclaimPageOnInputLocked()
|
||||
}
|
||||
logLine("direct ring " + decoded.label + " " + decoded.detail + " raw=" + hex(data))
|
||||
val frameId = frameTimings.startFrame("input:ring:" + decoded.label)
|
||||
|
||||
+12
-6
@@ -519,6 +519,17 @@ private fun GlassesSessionCore.ioHandlePage(payload: ByteArray) {
|
||||
interruptibleSleep.interrupt()
|
||||
}
|
||||
|
||||
/**
|
||||
* The wearer gave input (a temple touch, or the R1's) after closing our page:
|
||||
* take it back. Caller holds `monitor`.
|
||||
*/
|
||||
internal fun GlassesSessionCore.ioReclaimPageOnInputLocked() {
|
||||
if (io.pageWanted || !sessionReady) return
|
||||
io.pageWanted = true
|
||||
shutdownRequested = false
|
||||
io.pageRequestSentAtMs = 0
|
||||
}
|
||||
|
||||
private fun GlassesSessionCore.ioHandleGesture(gesture: RayNeoIoProtocol.Gesture) {
|
||||
val event: G2Event? = when (gesture.eventType) {
|
||||
// Same numbering as the G2's OsEventTypeList; head up wakes like the G2 CFW's forward.
|
||||
@@ -529,12 +540,7 @@ private fun GlassesSessionCore.ioHandleGesture(gesture: RayNeoIoProtocol.Gesture
|
||||
monitor.withLock {
|
||||
lastIncomingAtMs = now()
|
||||
if (event != null) lastConnectionOrInputAtMs = lastIncomingAtMs
|
||||
if (event != null && "sys-event" == event.kind && !io.pageWanted && sessionReady) {
|
||||
// The wearer touched the glasses after closing our page: take it back.
|
||||
io.pageWanted = true
|
||||
shutdownRequested = false
|
||||
io.pageRequestSentAtMs = 0
|
||||
}
|
||||
if (event != null && "sys-event" == event.kind) ioReclaimPageOnInputLocked()
|
||||
}
|
||||
logLine("RayNeo iO gesture type=" + gesture.eventType + " source=" + gesture.source + (if (event == null) " (ignored)" else ""))
|
||||
if (event == null) return
|
||||
|
||||
+10
@@ -971,6 +971,13 @@ internal fun macWireBytes(address: String): ByteArray? {
|
||||
internal fun GlassesSessionCore.queueGlassesRingLinkCommandLocked(
|
||||
action: String, fallbackAddress: String, fallbackName: String,
|
||||
): Boolean {
|
||||
if (isIo) {
|
||||
// A RayNeo iO has no ring link of its own; the phone holds the ring directly.
|
||||
lastRingLinkCommand = "$action: not applicable (RayNeo iO)"
|
||||
lastRingLinkCommandAtMs = now()
|
||||
logLine("glasses ring $action skipped: RayNeo iO glasses have no ring link")
|
||||
return false
|
||||
}
|
||||
val reported = glassesRingMac
|
||||
val mac = reported ?: macWireBytes(fallbackAddress)
|
||||
if (mac == null) {
|
||||
@@ -1091,6 +1098,9 @@ internal fun GlassesSessionCore.queueRingConfigCommandLocked(
|
||||
frame = RingProtocol.buildPairAuth(seq)
|
||||
}
|
||||
"targets-glasses" -> {
|
||||
// The iO never connects to the ring: naming it would make the ring drop
|
||||
// the phone's glasses-role link (the advStart check, ~20 s later).
|
||||
if (isIo) return "not sent: RayNeo iO glasses don't hold the ring"
|
||||
val right = macWireBytes(rightAddress)
|
||||
val left = macWireBytes(leftAddress)
|
||||
if (right == null || left == null) return "not sent: glasses addresses unparseable"
|
||||
|
||||
@@ -85,3 +85,16 @@ test('a RayNeo iO defaults the app switcher to the left, and keeps a chosen posi
|
||||
api.glassesTypeSetting.set('rayneo-io');
|
||||
assert.equal(api.appSwitcherPositionSetting.get(), 'left');
|
||||
});
|
||||
|
||||
test('a RayNeo iO always takes the R1 directly, leaving the G2\'s ring connection setting alone', () => {
|
||||
const store = new Map();
|
||||
const api = settingsFixture(store);
|
||||
assert.equal(api.effectiveRingConnectionMode(), 'glasses');
|
||||
api.ringConnectionModeSetting.set('health');
|
||||
assert.equal(api.effectiveRingConnectionMode(), 'health');
|
||||
api.glassesTypeSetting.set('rayneo-io');
|
||||
assert.equal(api.effectiveRingConnectionMode(), 'direct');
|
||||
assert.equal(api.ringConnectionModeSetting.get(), 'health');
|
||||
api.glassesTypeSetting.set('g2');
|
||||
assert.equal(api.effectiveRingConnectionMode(), 'health');
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
private const val IO = "00:6A:5E:5F:33:C2"
|
||||
private const val RING = "FF:AA:F1:F6:7E:28"
|
||||
private val PHONE_ID = byteArrayOf(1, 2, 3, 4, 5, 6)
|
||||
|
||||
private class IoClock(private val base: ProtocolPlatform) : ProtocolPlatform by base {
|
||||
@@ -50,6 +51,14 @@ private class FakeIoGlasses(platform: ProtocolPlatform) : SessionLink {
|
||||
|
||||
val controls: List<Int> get() = lock.withLock { controlsList.toList() }
|
||||
val messages: List<ByteArray> get() = lock.withLock { messagesList.toList() }
|
||||
/** Writes to the R1 on [RING] (characteristic, bytes), and the CCCDs the session enabled on it. */
|
||||
private val ringWritesList = ArrayList<Pair<String, ByteArray>>()
|
||||
private val ringCccdsList = ArrayList<String>()
|
||||
val ringWrites: List<Pair<String, ByteArray>> get() = lock.withLock { ringWritesList.toList() }
|
||||
val ringCccds: List<String> get() = lock.withLock { ringCccdsList.toList() }
|
||||
|
||||
/** A notification from the R1, as its link delivers it. */
|
||||
fun ringNotify(characteristicUuid: String, data: ByteArray) = core.onNotification(RING, characteristicUuid, data)
|
||||
|
||||
fun notify(business: Int, payload: ByteArray) {
|
||||
val frame = lock.withLock { RayNeoIoProtocol.encodeFrame(number++, business, payload) }
|
||||
@@ -70,10 +79,19 @@ private class FakeIoGlasses(platform: ProtocolPlatform) : SessionLink {
|
||||
|
||||
override fun discoverServices(address: String, timeoutMs: Int): Boolean = true
|
||||
|
||||
override fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean =
|
||||
characteristicUuid == RayNeoIoBle.NOTIFY_CHAR_UUID
|
||||
override fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean {
|
||||
if (address == RING) {
|
||||
lock.withLock { ringCccdsList.add(characteristicUuid) }
|
||||
return true
|
||||
}
|
||||
return characteristicUuid == RayNeoIoBle.NOTIFY_CHAR_UUID
|
||||
}
|
||||
|
||||
override fun writeFrames(address: String, characteristicUuid: String, frames: List<ByteArray>, mode: GattWriteMode, timeoutMs: Int): Boolean {
|
||||
if (address == RING) {
|
||||
lock.withLock { for (frame in frames) ringWritesList.add(characteristicUuid to frame) }
|
||||
return true
|
||||
}
|
||||
assertEquals(RayNeoIoBle.WRITE_CHAR_UUID, characteristicUuid)
|
||||
assertTrue(frames.all { it.size <= 185 - 3 }, "writes must fit the MTU")
|
||||
val decoded = lock.withLock { frames.flatMap { inbound.ingest(it) } }
|
||||
@@ -170,6 +188,7 @@ private class IoListener : FaceclawBleCommunicatorListener {
|
||||
@Volatile var lastStatus = ""
|
||||
val events = ArrayList<String>()
|
||||
val batteries = ArrayList<String>()
|
||||
val ringBatteries = ArrayList<String>()
|
||||
val firmware = ArrayList<String>()
|
||||
|
||||
override fun onStateChange(phase: String?, status: String?) {
|
||||
@@ -183,6 +202,7 @@ private class IoListener : FaceclawBleCommunicatorListener {
|
||||
|
||||
override fun onBatteryState(headsetBattery: Int, headsetCharging: Int, ringBattery: Int, ringCharging: Int) {
|
||||
batteries.add("$headsetBattery/$headsetCharging")
|
||||
if (ringBattery >= 0) ringBatteries.add("$ringBattery/$ringCharging")
|
||||
}
|
||||
|
||||
override fun onSilentMode(silent: Boolean) {}
|
||||
@@ -202,7 +222,8 @@ private class IoListener : FaceclawBleCommunicatorListener {
|
||||
}
|
||||
}
|
||||
|
||||
private class IoSession {
|
||||
/** An iO session; with [ring], also the phone's own link to an R1 in the glasses role (Direct). */
|
||||
private class IoSession(ring: String = "") {
|
||||
val platform = IoClock(testPlatform())
|
||||
val glasses = FakeIoGlasses(platform)
|
||||
private val host = object : SessionHost {
|
||||
@@ -243,13 +264,14 @@ private class IoSession {
|
||||
}
|
||||
}
|
||||
val listener = IoListener()
|
||||
val core = GlassesSessionCore(glasses, host, FrameTimingsCore(platform), platform, IO, IO, "")
|
||||
val core = GlassesSessionCore(glasses, host, FrameTimingsCore(platform), platform, IO, IO, ring)
|
||||
|
||||
init {
|
||||
glasses.core = core
|
||||
core.setListener(listener)
|
||||
core.setRequiredFirmwareRevision(38)
|
||||
core.useRayNeoIo(PHONE_ID, "Pixel", "Google", "Pixel 11")
|
||||
if (ring.isNotEmpty()) core.setDirectRingRole("glasses")
|
||||
}
|
||||
|
||||
fun pageUp(): Boolean = core.monitor.withLock { core.sessionReady && core.fixedLayoutCreated }
|
||||
@@ -377,4 +399,44 @@ class RayNeoIoSessionTest {
|
||||
s.core.close()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anR1BesideTheIoIsTheSessionsOwnRingInput() {
|
||||
val s = IoSession(RING)
|
||||
s.core.configureCompositorScreen(540, 220)
|
||||
try {
|
||||
assertTrue(s.core.start())
|
||||
assertTrue(awaitTrue(5_000) { s.pageUp() }, s.tail())
|
||||
// The phone takes the ring's glasses role itself: legacy CCCD, the glasses
|
||||
// pair-auth, then the touch source on, all on the ring's link.
|
||||
assertTrue(awaitTrue(5_000) { s.glasses.ringWrites.size >= 2 }, "ring setup not sent:\n" + s.tail())
|
||||
assertTrue(BleProtocol.R1_LEGACY_NOTIFY_CHAR_UUID in s.glasses.ringCccds)
|
||||
val (authChar, auth) = s.glasses.ringWrites[0]
|
||||
assertEquals(BleProtocol.R1_LEGACY_WRITE_CHAR_UUID, authChar)
|
||||
assertTrue(auth.contentEquals(RingProtocol.LEGACY_GLASSES_PAIR_AUTH))
|
||||
|
||||
// Its battery and gestures reach the listener as they do beside a G2,
|
||||
// not the iO's protocol parser.
|
||||
s.glasses.ringNotify(BleProtocol.R1_LEGACY_NOTIFY_CHAR_UUID, byteArrayOf(0x00, 0x09, 0x8b.toByte(), 0x00, 64, 1))
|
||||
assertTrue(awaitTrue(2_000) { "64/1" in s.listener.ringBatteries }, s.listener.ringBatteries.toString())
|
||||
val swipe = byteArrayOf(0x00, 0x09, 0x61, 0x00, 0x04, 0x35, 0x00, 0x09, 0xcc.toByte(), 0x00, 0x00)
|
||||
s.glasses.ringNotify(BleProtocol.R1_LEGACY_NOTIFY_CHAR_UUID, swipe)
|
||||
assertTrue(awaitTrue(2_000) { s.listener.events.isNotEmpty() }, s.tail())
|
||||
val expected = FaceclawRingEventDecoder.decode(swipe)!!.event
|
||||
assertEquals("${expected.kind}:${expected.eventType}:${expected.eventSource}", s.listener.events.single())
|
||||
|
||||
// The wearer closed the page: a ring gesture takes it back, as a temple touch does.
|
||||
s.glasses.pageOpen = false
|
||||
s.glasses.page(0, 4)
|
||||
s.platform.offsetMs += 4_000
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
sleepMs(300)
|
||||
assertFalse(s.pageUp())
|
||||
s.glasses.ringNotify(BleProtocol.R1_LEGACY_NOTIFY_CHAR_UUID, byteArrayOf(0x00, 0x09, 0x61, 0x00, 0x01, 0x00, 0x00, 0x10, 0xcc.toByte(), 0x00, 0x00))
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
assertTrue(awaitTrue(5_000) { s.pageUp() }, "ring input did not reopen:\n" + s.tail())
|
||||
} finally {
|
||||
s.core.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user