Build out Ring Status debug tool; fix some aspects of ring direct communication

This commit is contained in:
James Babcock committed 2026-10-06 19:53:43 -07:00
1 parent e12cfaaf38
commit f38595422c
16 files changed
+812 -173

No files matched your search

+113 -33
View File
@@ -3,13 +3,17 @@ import { GrayImage } from "../../graphics/image";
import { type InputEvent } from "../../ui/gestures";
import { Layer, type LayerContext } from "../../ui/layers";
import { shell } from "../../ui/shell/shell";
import { ringConnectionModeSetting } from "../../ui/dashboard-settings";
import { MenuLayer, type MenuItem } from "../../ui/menu";
import { ringConnectionModeSetting, ringDirectRoleSetting } from "../../ui/dashboard-settings";
import { loadDeviceAddresses } from "../../g2/device-addresses";
import {
getRingSessionStatus,
getRingSystemBluetoothState,
sendRingConfigCommand,
setDirectRingRole,
setGlassesRingLink,
type GlassesRingLinkAction,
type RingConfigAction,
type RingSessionStatus,
type RingSystemBluetoothState,
} from "../../native/ring-status";
@@ -20,26 +24,46 @@ const VALUE_X = 130;
const BUTTON_GAP = 8;
type Row = { label: string; value: string; dim?: boolean };
type Button = { label: string; action: GlassesRingLinkAction | "mode" };
type Button = "glasses" | "ring" | "mode" | "role";
const BUTTONS: readonly Button[] = [
{ label: "Disconnect", action: "disconnect" },
{ label: "Release", action: "release" },
{ label: "Reconnect", action: "connect" },
{ label: "Mode", action: "mode" },
const BUTTONS: readonly Button[] = ["glasses", "ring", "mode", "role"];
/** Glasses-side commands (sid 0x80 pair manager). */
const GLASSES_ACTIONS: readonly { label: string; action: GlassesRingLinkAction }[] = [
{ label: "Disconnect ring", action: "disconnect" },
{ label: "Release ring", action: "release" },
{ label: "Unpair ring", action: "unpair" },
{ label: "Connect ring", action: "connect" },
];
/** Ring-side commands over the direct link, and the combined flows. */
const RING_ACTIONS: readonly { label: string; action: RingConfigAction }[] = [
{ label: "Bind to these glasses", action: "bind" },
{ label: "Unbind from glasses", action: "unbind" },
{ label: "Targets: these glasses", action: "targets-glasses" },
{ label: "Targets: clear (any)", action: "targets-clear" },
{ label: "Remove ring notify", action: "remove-ring" },
{ label: "Touch source on", action: "touch-on" },
{ label: "Touch source off", action: "touch-off" },
{ label: "Pair auth (phone role)", action: "pair-auth" },
];
const ACTION_MENU_LAYOUT = { x: "center" as const, y: 8, width: 300, dimUnderneath: 0.35 };
/**
* Where R1 ring input is coming from: the phone's own Bluetooth link to the
* ring, the direct-link session state, and when input last arrived directly
* versus relayed by the glasses. A ring connected to the glasses does not
* also report gestures to a phone that connects to it directly, so the two
* "input" rows are the quickest way to see which path is live.
* versus relayed by the glasses. The ring sends gestures only to whichever
* link holds its glasses role, so the two "input" rows are the quickest way
* to see which path is live.
*
* The buttons are EXPERIMENTAL glasses-side ring link commands (sid 0x80,
* see GlassesSessionRing.kt): Disconnect / Release ask the glasses to let go
* of the ring, Reconnect hands it back, and Mode flips the Developer "Ring
* connection" setting, which applies on the next glasses connection.
* Everything below is EXPERIMENTAL (see GlassesSessionRing.kt and
* notes/ring-link-control.md). "Glasses..." sends sid 0x80 ring-link commands
* to the glasses; "Ring..." sends binding commands to the ring over the
* direct link (Mode must be direct and the link up), including Bind/Unbind,
* which do both halves in the official app's order. Mode flips the Developer
* "Ring connection" setting (applies on the next glasses connection); Role
* cycles which ring role the direct link claims and applies immediately.
*/
export class RingStatusLayer implements Layer {
private session: RingSessionStatus | null = null;
@@ -101,9 +125,7 @@ export class RingStatusLayer implements Layer {
const selected = index === this.selected;
if (selected) image.fillRoundedRect(x, buttonTop, buttonWidth, buttonHeight, 40, 4);
image.drawRoundedRect(x, buttonTop, buttonWidth, buttonHeight, selected ? 200 : 70, 4);
const text = button.action === "mode"
? (ringConnectionModeSetting.get() === "direct" ? "Mode: direct" : "Mode: glasses")
: button.label;
const text = buttonLabel(button);
image.drawText(font, x + Math.max(0, Math.floor((buttonWidth - font.measureText(text)) / 2)),
buttonTop + 4, text, selected ? 255 : 170);
});
@@ -132,11 +154,17 @@ export class RingStatusLayer implements Layer {
: "not connected";
const since = s.directStateAgeMs >= 0 ? ` ${formatAge(s.directStateAgeMs)}` : "";
const battery = s.directBattery >= 0 ? `, ${s.directBattery}%` : "";
rows.push({ label: "Direct link", value: `${state}${since}, ${s.directConnectCount} connects${battery}` });
rows.push({
label: "Direct link",
value: `${state}${since}, role ${s.directRole}, ${s.directConnectCount} connects${battery}`,
});
}
rows.push({ label: "Direct input", value: describeInput(s.lastDirectInputAgeMs, s.lastDirectInput) });
if (s.directEnabled) {
rows.push({ label: "Direct pkts", value: describeAge(s.lastDirectNotifyAgeMs) });
if (s.lastDirectRaw) {
rows.push({ label: "Direct raw", value: `${formatAge(s.lastDirectRawAgeMs)} ago: ${s.lastDirectRaw}` });
}
}
rows.push({ label: "Glasses input", value: describeInput(s.lastGlassesInputAgeMs, s.lastGlassesInput) });
rows.push({
@@ -148,27 +176,66 @@ export class RingStatusLayer implements Layer {
if (s.lastGlassesReport) {
rows.push({ label: "Glasses said", value: `${s.lastGlassesReport} (${formatAge(s.lastGlassesReportAgeMs)} ago)` });
}
if (s.lastRingCommand) {
rows.push({
label: "Ring cmd",
value: `${s.lastRingCommand} ${formatAge(s.lastRingCommandAgeMs)} ago: ${s.lastRingCommandResult}`,
});
}
if (s.lastCommand) {
rows.push({ label: "Sent", value: `${s.lastCommand} ${formatAge(s.lastCommandAgeMs)} ago` });
rows.push({ label: "Result", value: `R ${s.lastCommandResultR}; L ${s.lastCommandResultL}` });
rows.push({ label: "Glasses cmd", value: `${s.lastCommand} ${formatAge(s.lastCommandAgeMs)} ago` });
rows.push({ label: "Glasses ack", value: `R ${s.lastCommandResultR}; L ${s.lastCommandResultL}` });
}
if (s.lastDirectError) rows.push({ label: "Direct error", value: s.lastDirectError, dim: true });
return rows;
}
private activate(): void {
const button = BUTTONS[this.selected]!;
if (button.action === "mode") {
const next = ringConnectionModeSetting.get() === "direct" ? "glasses" : "direct";
ringConnectionModeSetting.set(next);
this.notice = `Ring connection set to ${ringConnectionModeSetting.displayValue(next)}; applies on next glasses connection`;
return;
private activate(ctx: LayerContext): void {
switch (BUTTONS[this.selected]!) {
case "glasses":
ctx.stack.push(this.actionMenu("Glasses ring link", GLASSES_ACTIONS.map(({ label, action }) => ({
label,
onSelect: (menuCtx) => {
this.runGlassesAction(label, action);
menuCtx.stack.pop();
},
}))));
return;
case "ring":
ctx.stack.push(this.actionMenu("Ring binding", RING_ACTIONS.map(({ label, action }) => ({
label,
onSelect: (menuCtx) => {
this.notice = `${label}: ${sendRingConfigCommand(action, this.ringAddress(), this.system?.name ?? "")}`;
this.poll();
menuCtx.stack.pop();
},
}))));
return;
case "mode": {
const next = ringConnectionModeSetting.get() === "direct" ? "glasses" : "direct";
ringConnectionModeSetting.set(next);
this.notice = `Ring connection set to ${ringConnectionModeSetting.displayValue(next)}; applies on next glasses connection`;
return;
}
case "role": {
const next = ringDirectRoleSetting.set(ringDirectRoleSetting.next());
setDirectRingRole(next);
this.notice = this.session?.directEnabled
? `Direct ring role: ${ringDirectRoleSetting.displayValue(next)}; reconnecting the direct link`
: `Direct ring role: ${ringDirectRoleSetting.displayValue(next)}; used once Mode is direct`;
return;
}
}
const address = this.ringAddress();
const name = this.system?.name ?? "";
this.notice = setGlassesRingLink(button.action, address, name)
? `${button.label} sent (experimental)`
: `${button.label} not sent (no session or no ring address)`;
}
private actionMenu(title: string, items: MenuItem[]): MenuLayer {
return new MenuLayer(title, items, ACTION_MENU_LAYOUT);
}
private runGlassesAction(label: string, action: GlassesRingLinkAction): void {
this.notice = setGlassesRingLink(action, this.ringAddress(), this.system?.name ?? "")
? `${label} sent (experimental)`
: `${label} not sent (no session or no ring address)`;
this.poll();
}
@@ -181,7 +248,7 @@ export class RingStatusLayer implements Layer {
this.selected = (this.selected + 1) % BUTTONS.length;
return;
case "click":
this.activate();
this.activate(ctx);
return;
case "double-click":
ctx.stack.pop();
@@ -192,6 +259,19 @@ export class RingStatusLayer implements Layer {
}
}
function buttonLabel(button: Button): string {
switch (button) {
case "glasses":
return "Glasses...";
case "ring":
return "Ring...";
case "mode":
return ringConnectionModeSetting.get() === "direct" ? "Mode: direct" : "Mode: glasses";
case "role":
return `Role: ${ringDirectRoleSetting.get()}`;
}
}
function describeSystem(sys: RingSystemBluetoothState | null): string {
if (!sys) return "unknown";
if (sys.error) return `error: ${sys.error}`;
+2 -1
View File
@@ -72,7 +72,7 @@ import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-a
import { appViewportRect, isOnSwitcherEdge, sidebarStripVisible, type WindowHeightMode } from "../ui/shell/geometry";
import { type LayerActions, type TextSettingsEditToggle } from "../ui/layers";
import { type KeyboardInputSession } from "../ui/shell/keyboard-input";
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayModeSetting, navigateDisplayModeSetting, navigateVerticalPositionSetting, terminalDisplayModeSetting, terminalVerticalPositionSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { appSwitcherPositionSetting, statusBarPositionSetting, statusBarVisibilitySetting, windowBorderSetting, assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, getBrightnessPreferences, displayModeSetting, navigateDisplayModeSetting, navigateVerticalPositionSetting, terminalDisplayModeSetting, terminalVerticalPositionSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, ringDirectRoleSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
import {
getInstalledEvenHubAppById,
@@ -1446,6 +1446,7 @@ class DashboardController {
right: addresses.right,
left: addresses.left,
ring: ringAddress,
ringRole: ringDirectRoleSetting.get(),
});
this.communicator = communicator;
// Size the compositor before anything else is awaited: windows opened
+5 -1
View File
@@ -199,7 +199,7 @@ export class FaceclawCommunicatorBridge {
private microphoneWork: Promise<void> = Promise.resolve();
private microphoneToken = 0;
constructor(addresses: { right: string; left: string; ring?: string }) {
constructor(addresses: { right: string; left: string; ring?: string; ringRole?: string }) {
this.communicator = FaceclawKitIosGlassesSession.alloc().initWithRightAddressLeftAddressRingAddress(
String(addresses.right ?? "").toUpperCase(),
String(addresses.left ?? "").toUpperCase(),
@@ -207,6 +207,10 @@ export class FaceclawCommunicatorBridge {
);
// The shared session halts on any other firmware ("incompatible-firmware").
this.communicator.setRequiredFirmwareRevisionRevision(REQUIRED_FACECLAW_FIRMWARE_VERSION);
// Guarded: an older framework build may not export it yet.
if (addresses.ringRole && typeof this.communicator.setDirectRingRoleRole === "function") {
this.communicator.setDirectRingRoleRole(addresses.ringRole);
}
this.listenerProxy = SessionListener.new() as SessionListener;
this.listenerProxy.bridge = this;
this.communicator.setListenerListener(this.listenerProxy);
+3 -1
View File
@@ -161,7 +161,7 @@ export class FaceclawCommunicatorBridge {
private readonly firmwareInfoListeners = new Set<(info: FirmwareInfo) => void>();
private readonly previewAnimationListeners = new Set<() => void>();
constructor(addresses: { right: string; left: string; ring?: string }) {
constructor(addresses: { right: string; left: string; ring?: string; ringRole?: string }) {
const context = Utils.android.getApplicationContext();
if (!context) throw new Error("Android application context unavailable");
@@ -173,6 +173,8 @@ export class FaceclawCommunicatorBridge {
);
// The shared session halts on any other firmware ("incompatible-firmware").
this.communicator.setRequiredFirmwareRevision(REQUIRED_FACECLAW_FIRMWARE_VERSION);
// Which R1 role the direct ring link claims; only matters with a ring address.
if (addresses.ringRole) this.communicator.setDirectRingRole(addresses.ringRole);
this.listenerProxy = new com.faceclaw.app.FaceclawBleCommunicatorListener({
onStateChange: (phase: string, status: string) => {
const state = {
+49 -2
View File
@@ -37,14 +37,38 @@ export type RingSessionStatus = {
lastCommandAgeMs: number;
lastCommandResultR: string;
lastCommandResultL: string;
/** Which ring role the direct link claims: "both", "phone" or "glasses". */
directRole: string;
lastRingCommand: string;
lastRingCommandAgeMs: number;
lastRingCommandResult: string;
/** Last direct-link notification nothing decoded: characteristic prefix and hex. */
lastDirectRaw: string;
lastDirectRawAgeMs: number;
};
/**
* EXPERIMENTAL glasses-side ring link control (sid 0x80 pair manager):
* "disconnect" drops the glasses' ring link, "release" also clears their
* connect mode (may hold off auto-reconnect), "connect" hands the ring back.
* connect mode (may hold off auto-reconnect), "unpair" makes them forget the
* ring, "connect" hands the ring back.
*/
export type GlassesRingLinkAction = "disconnect" | "release" | "connect";
export type GlassesRingLinkAction = "disconnect" | "release" | "unpair" | "connect";
/**
* EXPERIMENTAL ring-side binding commands over the direct link (see
* GlassesSessionCore.sendRingConfigCommand). "bind" and "unbind" combine the
* ring and glasses halves in the official app's order.
*/
export type RingConfigAction =
| "bind"
| "unbind"
| "pair-auth"
| "targets-glasses"
| "targets-clear"
| "touch-on"
| "touch-off"
| "remove-ring";
export type RingSystemBluetoothState = {
address: string;
@@ -100,3 +124,26 @@ export function setGlassesRingLink(action: GlassesRingLinkAction, fallbackAddres
return false;
}
}
/** A one-line outcome for the UI. */
export function sendRingConfigCommand(action: RingConfigAction, fallbackAddress: string, fallbackName: string): string {
const active = activeCommunicator();
if (!active) return "not sent: no glasses session";
try {
return String(active.sendRingConfigCommand(action, fallbackAddress, fallbackName));
} catch (error) {
console.warn(`sendRingConfigCommand failed: ${error}`);
return `failed: ${error}`;
}
}
/** Apply a direct ring role to the running session (reconnects the direct link if it is up). */
export function setDirectRingRole(role: string): void {
const active = activeCommunicator();
if (!active) return;
try {
active.setDirectRingRole(role);
} catch (error) {
console.warn(`setDirectRingRole failed: ${error}`);
}
}
+14
View File
@@ -715,6 +715,20 @@ export const ringConnectionModeSetting = new ConfigSettingEnum<RingConnectionMod
"How R1 ring input reaches the phone. Only via glasses: the ring's own link to the glasses carries its gestures, and the phone never opens a Bluetooth connection to the ring. Direct: also connect to the ring from the phone (currently unreliable). Takes effect on the next connection to the glasses.",
});
/** Which of the R1's two roles the direct link claims; see GlassesSessionCore.setDirectRingRole. */
export type RingDirectRole = "both" | "phone" | "glasses";
export const ringDirectRoleSetting = new ConfigSettingEnum<RingDirectRole>({
id: "ring-direct-role",
label: "Direct ring role",
storageKey: "developer.ringDirectRole",
defaultValue: "both",
values: ["both", "phone", "glasses"],
formatValue: (value) => (value === "phone" ? "Phone" : value === "glasses" ? "Glasses" : "Both"),
description:
"EXPERIMENTAL, only used when Ring connection is Direct. The ring has a phone role (health sync) and a glasses role (gestures). Phone: claim only the phone role, like Even's app. Glasses: claim the glasses role so ring gestures come straight to the phone; works only while the glasses are not holding the ring, and disables ring health sync. Both: the old behavior, which asks for both roles on one link.",
});
// "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
+2
View File
@@ -57,6 +57,7 @@ import {
previewColorSetting,
phoneRotationSetting,
ringConnectionModeSetting,
ringDirectRoleSetting,
sonioxApiKeySetting,
screenFadeSetting,
enumSettingMenuItem,
@@ -184,6 +185,7 @@ function settingsSections(): SettingsSection[] {
// Whether the phone opens its own BLE link to the R1 ring; the
// glasses relay ring gestures either way. Applied at connect time.
enumSettingMenuItem(ringConnectionModeSetting),
enumSettingMenuItem(ringDirectRoleSetting),
toggleSettingMenuItem(saveVoiceRecordingsSetting),
toggleSettingMenuItem(firmwareDebugFlagsSetting),
toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting),