G1 support: Preserve connections after flashing, debug

This commit is contained in:
James Babcock committed 2026-11-07 04:16:15 -08:00
1 parent 595b462b2e
commit b353483ac2
38 files changed
+1291 -178

No files matched your search

+20 -5
View File
@@ -32,7 +32,7 @@ export const EVEN_COMPANY_IDENTIFIER = 0x5245;
export type EvenDeviceRole = "left" | "right" | "ring" | "rayneo-io";
/** The firmware an Even G1 arm's name shows: Even's, or g1v0 (in safe mode: only updates work). */
/** The firmware an Even G1 arm advertises: Even's, or Faceclaw's g1v0 (in safe mode: only updates work). */
export type G1Firmware = "stock" | "g1v0" | "g1v0-safe";
/** True when the manufacturer data opens with Even's `"ER"` marker. */
@@ -79,11 +79,15 @@ export function extractG2AdvertisementFlag(mfg: Uint8Array): number | null {
*
* On Even's firmware the name is `Even G1_<token>_<L|R>_<hex6>` and the manufacturer data `[01 right | 02 left]` +
* the ASCII serial, zero-padded (the first two bytes read as a "company id" that differs per arm). On g1v0 the name
* is `G1v0_L` or `G1v0_R` (`G1v0S_…` in safe mode) and the scan response holds company 0xFFFF, a format byte (1), a
* flags byte, and the pair ID in ASCII: the frame serial, the same on both arms.
* is `G1CFW_<L|R>_<hex6>` with the same digits and address as stock's, and the scan response holds company 0xFFFF, a
* format byte (2), a flags byte (bit 3: safe mode), the firmware's version in three bytes, and the pair ID in ASCII:
* the frame serial, the same on both arms. Before 0.5.66: `G1v0_L` or `G1v0_R` (`G1v0S_…` in safe mode), format 1, no
* version.
*/
export function g1FromName(name: string | null | undefined): { side: "left" | "right"; firmware: G1Firmware } | null {
if (!name) return null;
const custom = /^G1CFW_([LR])_[0-9A-F]{6}$/i.exec(name.trim());
if (custom) return { side: custom[1]!.toUpperCase() === "L" ? "left" : "right", firmware: "g1v0" };
const g1v0 = /^G1V0(S?)_([LR])$/i.exec(name.trim());
if (g1v0) {
return {
@@ -96,9 +100,16 @@ export function g1FromName(name: string | null | undefined): { side: "left" | "r
return side ? { side, firmware: "stock" } : null;
}
/** What g1v0's pair record says beyond the serial; null when there is no record of a format that says it. */
export function parseG1Record(mfg: Uint8Array): { version: string; safeMode: boolean } | null {
if (mfg.length < 7 || mfg[0] !== 0xff || mfg[1] !== 0xff || mfg[2] !== 2) return null;
return { version: `${mfg[4]}.${mfg[5]}.${mfg[6]}`, safeMode: (mfg[3]! & 8) !== 0 };
}
/** The pair's serial from an arm's manufacturer data, on either firmware; null when absent. */
export function extractG1Serial(mfg: Uint8Array, firmware: G1Firmware): string | null {
const start = firmware === "stock" ? 1 : mfg.length >= 4 && mfg[0] === 0xff && mfg[1] === 0xff && mfg[2] === 1 ? 4 : -1;
const record = mfg.length >= 4 && mfg[0] === 0xff && mfg[1] === 0xff;
const start = firmware === "stock" ? 1 : record && mfg[2] === 2 ? 7 : record && mfg[2] === 1 ? 4 : -1;
if (start < 0 || mfg.length <= start) return null;
let serial = "";
for (let i = start; i < mfg.length; i++) {
@@ -259,6 +270,8 @@ export type EvenAdvertisement = {
note: string | null;
/** Set on an Even G1 arm (role left or right): its firmware. */
g1Firmware?: G1Firmware;
/** The version g1v0 advertises (0.5.66+); absent when it doesn't say. */
g1Version?: string;
};
/**
@@ -285,6 +298,7 @@ export function classifyAdvertisement(raw: RawAdvertisement): EvenAdvertisement
const g1 = g1FromName(name);
if (g1) {
const serial = extractG1Serial(mfg, g1.firmware);
const record = g1.firmware === "stock" ? null : parseG1Record(mfg);
return {
address: normalizeMacAddress(raw.address),
name,
@@ -302,7 +316,8 @@ export function classifyAdvertisement(raw: RawAdvertisement): EvenAdvertisement
seenAtMs: raw.seenAtMs,
manufacturerData: raw.manufacturerData ?? "",
note: serial ? null : "no serial in the advertisement (it may still be arriving)",
g1Firmware: g1.firmware,
g1Firmware: record?.safeMode ? "g1v0-safe" : g1.firmware,
...(record ? { g1Version: record.version } : {}),
};
}
+15 -1
View File
@@ -1,12 +1,26 @@
import { classifyAdvertisement, hasEvenManufacturerSignature, type EvenAdvertisement } from './even-advertisement'
import { classifyAdvertisement, g1FromName, hasEvenManufacturerSignature, type EvenAdvertisement } from './even-advertisement'
import { hexToBytes } from '../util/hex-util'
export type IosAdvertisement = { identifier: string; name: string; manufacturerData: string; rssi: number; connectable: boolean }
export type IosDevice = EvenAdvertisement & { identifier: string }
/**
* A G1 arm advertises no full MAC, and CoreBluetooth hides the real one. Faceclaw's addresses are MAC-shaped everywhere, so its
* address on this phone is made from the peripheral identifier. It's stable as long as the identifier is, which on firmware
* 0.5.66 and later is across installs too, and it only has to mean something on this phone: nobody types it in.
*/
export function g1IosAddress(identifier: string): string {
return identifier.replace(/-/g, '').slice(0, 12).toUpperCase().replace(/(..)(?=.)/g, '$1:')
}
/** Only a full vendor-advertised MAC may bind a manually entered address. */
export function identifyIosPeripheral(raw: IosAdvertisement): IosDevice | null {
if (!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(raw.identifier)) return null
if (g1FromName(raw.name)) {
const arm = classifyAdvertisement({ ...raw, address: g1IosAddress(raw.identifier), source: 'scan', bonded: false,
txPower: null, seenAtMs: Date.now() })
return arm && { ...arm, identifier: raw.identifier.toUpperCase() }
}
if (!hasEvenManufacturerSignature(hexToBytes(raw.manufacturerData))) return null
const candidate = classifyAdvertisement({ ...raw, address: '', source: 'scan', bonded: false,
txPower: null, seenAtMs: Date.now() })
+2 -2
View File
@@ -54,7 +54,7 @@ import { onAnySettingChanged,
previewColorSetting, lockScreenEnabledSetting, getBrightnessPreferences, getStringSettingById,
nightscoutSiteUrlSetting, nightscoutApiTokenSetting, voiceProviderSetting, elevenLabsApiKeySetting,
openAiApiKeySetting, sonioxApiKeySetting, whisperServerApiKeySetting, whisperServerLanguageSetting,
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting } from '../ui/dashboard-settings'
whisperServerModelSetting, whisperServerUrlSetting, ringConnectionModeSetting, saveTranscribeAudioSetting, glassesTypeSetting } from '../ui/dashboard-settings'
import { transcriptionKey, type VoiceProviderSelection } from '../native/cloud-stt-provider'
import type { PhoneGesture } from '../phone-ui/phone-gestures'
import { claimGlassesOnboardingAutoLaunch, ONBOARDING_APP_ID } from '../apps/onboarding/onboarding-progress'
@@ -881,7 +881,7 @@ export class IosPreviewController {
return
}
if (this.communicator) await this.closeCommunicator()
const communicator = new FaceclawCommunicatorBridge(identifiers)
const communicator = new FaceclawCommunicatorBridge({ ...identifiers, glassesType: glassesTypeSetting.get() })
this.teardownPreviewDisplay()
this.communicator = communicator
this.wearDetectionRequested = false