forked from Blendman974/faceclaw
Autoconfigure ring for direct connection
This commit is contained in:
1 parent
f38595422c
commit
d7a02f25fb
11 files changed
+294
-89
No files matched your search
@@ -4,13 +4,12 @@ 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, ringDirectRoleSetting } from "../../ui/dashboard-settings";
|
||||
import { ringConnectionModeSetting } from "../../ui/dashboard-settings";
|
||||
import { loadDeviceAddresses } from "../../g2/device-addresses";
|
||||
import {
|
||||
getRingSessionStatus,
|
||||
getRingSystemBluetoothState,
|
||||
sendRingConfigCommand,
|
||||
setDirectRingRole,
|
||||
setGlassesRingLink,
|
||||
type GlassesRingLinkAction,
|
||||
type RingConfigAction,
|
||||
@@ -24,9 +23,9 @@ const VALUE_X = 130;
|
||||
const BUTTON_GAP = 8;
|
||||
|
||||
type Row = { label: string; value: string; dim?: boolean };
|
||||
type Button = "glasses" | "ring" | "mode" | "role";
|
||||
type Button = "glasses" | "ring" | "mode";
|
||||
|
||||
const BUTTONS: readonly Button[] = ["glasses", "ring", "mode", "role"];
|
||||
const BUTTONS: readonly Button[] = ["glasses", "ring", "mode"];
|
||||
|
||||
/** Glasses-side commands (sid 0x80 pair manager). */
|
||||
const GLASSES_ACTIONS: readonly { label: string; action: GlassesRingLinkAction }[] = [
|
||||
@@ -62,8 +61,9 @@ const ACTION_MENU_LAYOUT = { x: "center" as const, y: 8, width: 300, dimUndernea
|
||||
* 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.
|
||||
* "Ring connection" setting (applies on the next glasses connection). In
|
||||
* Direct mode the session does the setup on its own (see
|
||||
* GlassesSessionRing.runRingGlassesSetup); the menus are for experiments.
|
||||
*/
|
||||
export class RingStatusLayer implements Layer {
|
||||
private session: RingSessionStatus | null = null;
|
||||
@@ -146,8 +146,8 @@ export class RingStatusLayer implements Layer {
|
||||
}
|
||||
|
||||
if (!s.directEnabled) {
|
||||
const pending = ringConnectionModeSetting.get() === "direct";
|
||||
rows.push({ label: "Direct link", value: pending ? "on after glasses reconnect" : "off (mode: glasses)", dim: true });
|
||||
const pending = ringConnectionModeSetting.get() !== "glasses";
|
||||
rows.push({ label: "Direct link", value: pending ? "on after glasses reconnect" : "off (only via glasses)", dim: true });
|
||||
} else {
|
||||
const state = s.directNotificationsReady ? "subscribed"
|
||||
: s.directConnected ? "connected, subscribing"
|
||||
@@ -159,6 +159,12 @@ export class RingStatusLayer implements Layer {
|
||||
value: `${state}${since}, role ${s.directRole}, ${s.directConnectCount} connects${battery}`,
|
||||
});
|
||||
}
|
||||
if (s.directEnabled && s.directRole === "glasses") {
|
||||
rows.push({
|
||||
label: "Direct auth",
|
||||
value: s.directGlassesAuth ? `${s.directGlassesAuth} ${formatAge(s.directGlassesAuthAgeMs)} ago` : "not sent yet",
|
||||
});
|
||||
}
|
||||
rows.push({ label: "Direct input", value: describeInput(s.lastDirectInputAgeMs, s.lastDirectInput) });
|
||||
if (s.directEnabled) {
|
||||
rows.push({ label: "Direct pkts", value: describeAge(s.lastDirectNotifyAgeMs) });
|
||||
@@ -212,19 +218,10 @@ export class RingStatusLayer implements Layer {
|
||||
}))));
|
||||
return;
|
||||
case "mode": {
|
||||
const next = ringConnectionModeSetting.get() === "direct" ? "glasses" : "direct";
|
||||
ringConnectionModeSetting.set(next);
|
||||
const next = ringConnectionModeSetting.set(ringConnectionModeSetting.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,9 +263,7 @@ function buttonLabel(button: Button): string {
|
||||
case "ring":
|
||||
return "Ring...";
|
||||
case "mode":
|
||||
return ringConnectionModeSetting.get() === "direct" ? "Mode: direct" : "Mode: glasses";
|
||||
case "role":
|
||||
return `Role: ${ringDirectRoleSetting.get()}`;
|
||||
return `Mode: ${ringConnectionModeSetting.get()}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ import { weatherBridge } from "../native/weather";
|
||||
import { ALL_NOTIFICATIONS, onAndroidNotificationPosted, readActiveNotifications } from "../native/notification-icons";
|
||||
import { shouldShowNotificationOnGlasses } from "../native/notification-sources";
|
||||
import { openEvenAppSettings, readEvenAppNotificationState } from "../native/even-app-conflict";
|
||||
import { defaultRingName, setGlassesRingLink } from "../native/ring-status";
|
||||
import { getBooleanSetting, setBooleanSetting } from "../native/settings-store";
|
||||
import { grayImageToPreviewSource } from "../native/gray-image-preview";
|
||||
import { firmwareIncompatibilityMessage, hasCompatibleFirmware } from "./firmware-compat";
|
||||
import { hasExtractedEvenHubFonts } from "./firmware-builder";
|
||||
@@ -72,7 +74,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, ringDirectRoleSetting, 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, type RingConnectionMode, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings";
|
||||
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||
import {
|
||||
getInstalledEvenHubAppById,
|
||||
@@ -238,6 +240,9 @@ function sourceName(eventSource: number): string {
|
||||
return EventSourceTypeName[eventSource] ?? `SOURCE_${eventSource}`;
|
||||
}
|
||||
|
||||
/** Set while a Direct ring session may have taken the R1 from the glasses; see handRingBackToGlassesIfNeeded. */
|
||||
const RING_TAKEN_FROM_GLASSES_KEY = "developer.ringTakenFromGlasses";
|
||||
|
||||
class DashboardController {
|
||||
private phase: ConnectionPhase = "disconnected";
|
||||
private status = "Disconnected.";
|
||||
@@ -315,6 +320,8 @@ class DashboardController {
|
||||
/** Faceclaw's firmware at the required revision reported in; its extensions can be used. */
|
||||
private customFirmwareConfirmed = false;
|
||||
private faceclawWakeLeaseState: boolean | null = null;
|
||||
/** Ring connection mode the current session was started with (it applies per connection). */
|
||||
private ringModeAtConnect: RingConnectionMode = "glasses";
|
||||
private glassesWorn: boolean | null = null;
|
||||
/** Put on while charging: Java reconnects on that, and the wake waits for the new session. */
|
||||
private wakeAfterChargingReconnect = false;
|
||||
@@ -991,6 +998,25 @@ class DashboardController {
|
||||
this.evenHubSuspendTimer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private handRingBackToGlassesIfNeeded(): void {
|
||||
if (this.ringModeAtConnect === "direct" || !getBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, false)) return;
|
||||
const ring = loadDeviceAddresses().ring;
|
||||
if (!ring) {
|
||||
setBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, false);
|
||||
return;
|
||||
}
|
||||
if (setGlassesRingLink("connect", ring, defaultRingName(ring))) {
|
||||
setBooleanSetting(RING_TAKEN_FROM_GLASSES_KEY, false);
|
||||
this.appendLog(`Handing the R1 ring ${ring} back to the glasses`);
|
||||
}
|
||||
}
|
||||
|
||||
private pushFirmwareDebugFlags(): void {
|
||||
if (!this.communicator) return;
|
||||
void this.communicator
|
||||
@@ -1423,10 +1449,14 @@ class DashboardController {
|
||||
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, and the
|
||||
// direct link is currently unreliable. An empty address disables every
|
||||
// direct-ring code path in the communicator.
|
||||
const ringAddress = ringConnectionModeSetting.get() === "direct" ? addresses.ring : "";
|
||||
// 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();
|
||||
this.ringModeAtConnect = ringMode;
|
||||
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(
|
||||
`Using configured arms: R=${addresses.right} L=${addresses.left}${ringAddress ? ` ring=${ringAddress}` : ""}`,
|
||||
);
|
||||
@@ -1446,7 +1476,9 @@ class DashboardController {
|
||||
right: addresses.right,
|
||||
left: addresses.left,
|
||||
ring: ringAddress,
|
||||
ringRole: ringDirectRoleSetting.get(),
|
||||
// Direct mode acts as the ring's glasses (gestures, battery); health
|
||||
// sync needs the phone role instead.
|
||||
ringRole: ringMode === "direct" ? "glasses" : "phone",
|
||||
});
|
||||
this.communicator = communicator;
|
||||
// Size the compositor before anything else is awaited: windows opened
|
||||
@@ -1493,6 +1525,7 @@ class DashboardController {
|
||||
// mode-7 control message once the dashboard container is warmed up.
|
||||
this.pushFirmwareDebugFlags();
|
||||
this.pushBrightness(true);
|
||||
this.handRingBackToGlassesIfNeeded();
|
||||
}
|
||||
if (mappedPhase !== "connected" && mappedPhase !== "charging") {
|
||||
// A wear snapshot is session-scoped. CFW reports a fresh value when
|
||||
|
||||
+12
-10
@@ -37,8 +37,11 @@ export type RingSessionStatus = {
|
||||
lastCommandAgeMs: number;
|
||||
lastCommandResultR: string;
|
||||
lastCommandResultL: string;
|
||||
/** Which ring role the direct link claims: "both", "phone" or "glasses". */
|
||||
/** Which ring role the direct link claims: "phone" or "glasses". */
|
||||
directRole: string;
|
||||
/** Glasses role only: what the ring made of our legacy pair-auth this connection ("" = not sent). */
|
||||
directGlassesAuth: string;
|
||||
directGlassesAuthAgeMs: number;
|
||||
lastRingCommand: string;
|
||||
lastRingCommandAgeMs: number;
|
||||
lastRingCommandResult: string;
|
||||
@@ -137,13 +140,12 @@ export function sendRingConfigCommand(action: RingConfigAction, fallbackAddress:
|
||||
}
|
||||
}
|
||||
|
||||
/** 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}`);
|
||||
}
|
||||
/**
|
||||
* The R1's advertised name, "EVEN R1_" plus the last three address bytes
|
||||
* (e.g. FF:AA:F1:F6:7E:28 -> "EVEN R1_F67E28"). The glasses store it with the
|
||||
* ring's MAC when told to connect.
|
||||
*/
|
||||
export function defaultRingName(address: string): string {
|
||||
const hex = address.replace(/[^0-9a-fA-F]/g, "").toUpperCase();
|
||||
return hex.length === 12 ? `EVEN R1_${hex.slice(6)}` : "";
|
||||
}
|
||||
@@ -702,31 +702,24 @@ export const showBleBandwidthSetting = new ConfigSettingBoolean({
|
||||
"Show Bluetooth messages and bytes sent, throughput, acknowledged display fps, and bytes per frame at the bottom of the phone screen. Rates use a five-second window; bytes include control traffic and protocol framing.",
|
||||
});
|
||||
|
||||
export type RingConnectionMode = "glasses" | "direct";
|
||||
/**
|
||||
* How the phone talks to the R1. The ring has one phone role (health sync) and
|
||||
* one glasses role (gestures, battery pushes), so "health" and "direct" are
|
||||
* the two ways a phone link can be useful; see
|
||||
* GlassesSessionCore.setDirectRingRole and notes/ring-link-control.md.
|
||||
*/
|
||||
export type RingConnectionMode = "glasses" | "health" | "direct";
|
||||
|
||||
export const ringConnectionModeSetting = new ConfigSettingEnum<RingConnectionMode>({
|
||||
id: "ring-connection-mode",
|
||||
label: "Ring connection",
|
||||
storageKey: "developer.ringConnectionMode",
|
||||
defaultValue: "glasses",
|
||||
values: ["glasses", "direct"],
|
||||
formatValue: (value) => (value === "direct" ? "Direct" : "Only via glasses"),
|
||||
values: ["glasses", "health", "direct"],
|
||||
formatValue: (value) =>
|
||||
value === "direct" ? "Direct to phone" : value === "health" ? "Via glasses + health sync" : "Only via glasses",
|
||||
description:
|
||||
"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.",
|
||||
"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 and ring health sync is off. Leaving Direct hands the ring back to the glasses. Takes effect on the next connection to the glasses.",
|
||||
});
|
||||
|
||||
// "whisper" (no "onboard-" prefix) is OpenAI's CLOUD realtime model
|
||||
|
||||
@@ -57,7 +57,6 @@ import {
|
||||
previewColorSetting,
|
||||
phoneRotationSetting,
|
||||
ringConnectionModeSetting,
|
||||
ringDirectRoleSetting,
|
||||
sonioxApiKeySetting,
|
||||
screenFadeSetting,
|
||||
enumSettingMenuItem,
|
||||
@@ -182,10 +181,9 @@ function settingsSections(): SettingsSection[] {
|
||||
{
|
||||
label: "Developer",
|
||||
items: [
|
||||
// Whether the phone opens its own BLE link to the R1 ring; the
|
||||
// glasses relay ring gestures either way. Applied at connect time.
|
||||
// Whether and how the phone opens its own BLE link to the R1 ring.
|
||||
// Applied at connect time.
|
||||
enumSettingMenuItem(ringConnectionModeSetting),
|
||||
enumSettingMenuItem(ringDirectRoleSetting),
|
||||
toggleSettingMenuItem(saveVoiceRecordingsSetting),
|
||||
toggleSettingMenuItem(firmwareDebugFlagsSetting),
|
||||
toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting),
|
||||
|
||||
Reference in new issue
Block a user