Faceclaw support for G1s

Relies on the glasses having the firmware from
https://github.com/jimrandomh/scouter_kit, based on Mafik's Scouter Kit.
This commit is contained in:
James Babcock committed 2026-11-06 00:12:23 -08:00
1 parent f803f4212c
commit 67aff19923
27 files changed
+1902 -45

No files matched your search

+65
View File
@@ -32,6 +32,9 @@ 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). */
export type G1Firmware = "stock" | "g1v0" | "g1v0-safe";
/** True when the manufacturer data opens with Even's `"ER"` marker. */
export function hasEvenManufacturerSignature(mfg: Uint8Array): boolean {
return mfg.length >= 2 && mfg[0] === 0x45 && mfg[1] === 0x52;
@@ -71,6 +74,42 @@ export function extractG2AdvertisementFlag(mfg: Uint8Array): number | null {
return mfg[22]!;
}
/**
* ## Even G1 arm
*
* 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.
*/
export function g1FromName(name: string | null | undefined): { side: "left" | "right"; firmware: G1Firmware } | null {
if (!name) return null;
const g1v0 = /^G1V0(S?)_([LR])$/i.exec(name.trim());
if (g1v0) {
return {
side: g1v0[2]!.toUpperCase() === "L" ? "left" : "right",
firmware: g1v0[1] ? "g1v0-safe" : "g1v0",
};
}
if (!/^EVEN G1_/i.test(name.trim())) return null;
const side = g2SideFromName(name);
return side ? { side, firmware: "stock" } : null;
}
/** 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;
if (start < 0 || mfg.length <= start) return null;
let serial = "";
for (let i = start; i < mfg.length; i++) {
const byte = mfg[i]!;
if (byte === 0) break;
if (byte < 0x20 || byte > 0x7e) return null;
serial += String.fromCharCode(byte);
}
return serial.length ? serial : null;
}
/** RayNeo iO manufacturer data (company 0x5716, little-endian first): `[07][MAC x6]...`, outside pairing mode. */
export const RAYNEO_COMPANY_IDENTIFIER = 0x5716;
@@ -218,6 +257,8 @@ export type EvenAdvertisement = {
manufacturerData: string;
/** Why an otherwise Even-looking advertisement could not be fully parsed. */
note: string | null;
/** Set on an Even G1 arm (role left or right): its firmware. */
g1Firmware?: G1Firmware;
};
/**
@@ -241,6 +282,30 @@ export function classifyAdvertisement(raw: RawAdvertisement): EvenAdvertisement
const rayneoMac = extractRayNeoMac(mfg);
const looksLikeRayNeo = upper.startsWith("RAYNEO") || rayneoMac !== null;
const g1 = g1FromName(name);
if (g1) {
const serial = extractG1Serial(mfg, g1.firmware);
return {
address: normalizeMacAddress(raw.address),
name,
role: g1.side,
serial,
embeddedMac: null,
embeddedMacMismatch: false,
flag: null,
ringSerialSuffix: null,
rssi: raw.rssi,
txPower: raw.txPower,
connectable: raw.connectable,
bonded: raw.bonded,
source: raw.source,
seenAtMs: raw.seenAtMs,
manufacturerData: raw.manufacturerData ?? "",
note: serial ? null : "no serial in the advertisement (it may still be arriving)",
g1Firmware: g1.firmware,
};
}
if (!looksLikeRing && !looksLikeG2 && !hasSignature && !looksLikeRayNeo) return null;
if (looksLikeRayNeo && !hasSignature) {
+51 -3
View File
@@ -20,7 +20,7 @@ import {
type ProximityEstimate,
type ProximityZone,
} from "./ble-proximity";
import { classifyAdvertisement, normalizeMacAddress, type EvenAdvertisement, type RawAdvertisement } from "./even-advertisement";
import { classifyAdvertisement, normalizeMacAddress, type EvenAdvertisement, type G1Firmware, type RawAdvertisement } from "./even-advertisement";
import { GENERIC_G2_IMAGE_PATH, glassesImagePath, R1_IMAGE_PATH } from "./glasses-artwork";
import {
colorwayDisplayName,
@@ -48,6 +48,8 @@ export type GlassesPairCandidate = {
rssi: number | null;
proximity: ProximityEstimate | null;
lastSeenMs: number;
/** An Even G1 pair: the arms' firmware, the "lower" of the two (stock, then safe mode). Absent on a G2. */
g1Firmware?: G1Firmware;
/**
* Set when this lone arm and a lone arm of the other side carry different
* serials — the mixed-pair situation the serial check exists to name.
@@ -187,7 +189,8 @@ export class DiscoveryAggregator {
for (const record of this.byAddress.values()) {
if (record.role === "ring" || record.role === "rayneo-io") continue;
const canonical = serialKey(record.serial);
const key = canonical ? `serial:${canonical}` : `arm:${record.address}`;
const family = record.g1Firmware ? "g1:" : "";
const key = canonical ? `${family}serial:${canonical}` : `arm:${record.address}`;
const group = groups.get(key) ?? { left: null, right: null };
const slot = record.role === "left" ? "left" : "right";
const incumbent = group[slot];
@@ -208,7 +211,9 @@ export class DiscoveryAggregator {
pairs.push({
id: serialKey(serial) ?? `arm:${any.address}`,
serial,
identity: GlassesHardwareIdentity.decode(serial),
// Even's G2 serial scheme; a G1's says nothing to it.
identity: any.g1Firmware ? null : GlassesHardwareIdentity.decode(serial),
...(any.g1Firmware ? { g1Firmware: g1PairFirmware(left, right) } : {}),
left: left ? stripSmoothing(left) : null,
right: right ? stripSmoothing(right) : null,
completeness: left && right ? "complete" : left ? "left-only" : "right-only",
@@ -367,7 +372,50 @@ function embeddedMacMismatchWarning(subject: string, ad: EvenAdvertisement | nul
return `${subject} advertised address ${ad.embeddedMac} differs from its radio address ${ad.address}.`;
}
/** The pair can only do what its less capable arm can. */
function g1PairFirmware(left: EvenAdvertisement | null, right: EvenAdvertisement | null): G1Firmware {
const firmwares = [left?.g1Firmware, right?.g1Firmware];
if (firmwares.includes("stock")) return "stock";
return firmwares.includes("g1v0-safe") ? "g1v0-safe" : "g1v0";
}
export function g1Row(pair: GlassesPairCandidate, context: RowContext = {}): PairingRowPresentation {
const isPreviouslyPairedRow = isPreviouslyPaired(pair.serial, context.pairedSerial);
const isNearest = !!context.nearestId && context.nearestId === pair.id;
const warnings: string[] = [];
if (pair.mismatchWarning) warnings.push(pair.mismatchWarning);
let armsSummary: string;
let canSelect = false;
if (pair.g1Firmware === "stock") {
armsSummary = "Needs the Faceclaw firmware for the G1, which is installed from a computer";
} else if (pair.g1Firmware === "g1v0-safe") {
armsSummary = "In safe mode: the firmware restarted repeatedly. Reinstall it from a computer";
} else if (pair.completeness !== "complete") {
armsSummary = pair.completeness === "left-only"
? "Only the left arm has been seen — waiting for the right"
: "Only the right arm has been seen — waiting for the left";
} else {
armsSummary = "Left + right arms found. To pair, keep them in the case with the lid open";
canSelect = true;
}
return {
id: pair.id,
kind: "glasses",
modelTitle: "Even Realities G1",
deviceName: pair.serial ?? (pair.left ?? pair.right)!.name,
variantSummary: null,
colorway: null,
swatchHex: null,
imagePath: GENERIC_G2_IMAGE_PATH,
hasVariantImage: false,
...presentationBase(pair.proximity, isNearest, isPreviouslyPairedRow, warnings),
armsSummary,
canSelect,
};
}
export function glassesRow(pair: GlassesPairCandidate, context: RowContext = {}): PairingRowPresentation {
if (pair.g1Firmware) return g1Row(pair, context);
const identity = pair.identity;
const imagePath = glassesImagePath(identity);
const isPreviouslyPairedRow = isPreviouslyPaired(pair.serial, context.pairedSerial);
+1
View File
@@ -260,6 +260,7 @@ export class FaceclawCommunicatorBridge {
);
// The shared session halts on any other firmware ("incompatible-firmware").
this.communicator.setRequiredFirmwareRevisionRevision(REQUIRED_FACECLAW_FIRMWARE_VERSION);
if (addresses.glassesType === "g1") this.communicator.useG1();
// Guarded: an older framework build may not export it yet.
if (addresses.ringRole && typeof this.communicator.setDirectRingRoleRole === "function") {
this.communicator.setDirectRingRoleRole(addresses.ringRole);
+2
View File
@@ -184,6 +184,8 @@ export class FaceclawCommunicatorBridge {
this.communicator.setRequiredFirmwareRevision(REQUIRED_FACECLAW_FIRMWARE_VERSION);
// RayNeo iO: one link (its address in both arm slots), its own handshake and page lease.
if (addresses.glassesType === "rayneo-io") this.communicator.useRayNeoIo();
// Even G1 on g1v0: two links, like a G2's arms, but frames composed here and sent to each arm.
if (addresses.glassesType === "g1") this.communicator.useG1();
// 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({
+11 -4
View File
@@ -186,9 +186,9 @@ export class PairingViewModel extends Observable {
get instructions(): string {
return (
"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."
"Select your G2 or G1 glasses or RayNeo iO, and your R1 ring if you have one, below. Wear the glasses or take them out of the case " +
"(a G1 pairs only in its case, with the lid open), and keep the glasses and phone nearby. If your glasses are not detected, " +
"make sure no other apps are connected."
);
}
@@ -358,7 +358,8 @@ export class PairingViewModel extends Observable {
ring: ringAddress,
};
saveDeviceAddresses(addresses);
if (pair) glassesTypeSetting.set("g2");
const g1 = !!pair?.g1Firmware;
if (pair) glassesTypeSetting.set(g1 ? "g1" : "g2");
if (pair) {
savePairedGlassesIdentity({
serial: pair.serial ?? "",
@@ -385,6 +386,12 @@ export class PairingViewModel extends Observable {
this.dispose();
if (this.onboarding) {
setPreviewOnlyMode(false);
if (g1) {
// The G2 firmware check and flash pages don't apply: a G1's firmware is installed from a
// computer, and the session reports incompatible firmware if it lacks the display path.
finishOnboardingNavigation();
return;
}
// Continue the onboarding chain: check the glasses' firmware next.
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-firmware-check-page" });
return;
+4 -4
View File
@@ -385,14 +385,14 @@ export const distanceUnitSetting = new ConfigSettingEnum<DistanceUnit>({
export type AppSwitcherPosition = "left" | "right" | "bottom" | "popup";
/** Which glasses the saved addresses belong to (set by pairing; see g2/device-addresses.ts). */
export type GlassesType = "g2" | "rayneo-io";
export type GlassesType = "g2" | "rayneo-io" | "g1";
export const glassesTypeSetting = new ConfigSettingEnum<GlassesType>({
id: "glasses-type",
label: "Glasses",
storageKey: "deviceType", // graphics/screen-size.ts GLASSES_TYPE_KEY reads it directly
defaultValue: "g2",
values: ["g2", "rayneo-io"],
values: ["g2", "rayneo-io", "g1"],
reportInAnalytics: false,
});
@@ -909,11 +909,11 @@ export const ringConnectionModeSetting = new ConfigSettingEnum<RingConnectionMod
/**
* 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
* RayNeo iO or Even G1, 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();
return glassesTypeSetting.get() !== "g2" ? "direct" : ringConnectionModeSetting.get();
}
// "whisper" (no "onboard-" prefix) is OpenAI's CLOUD realtime model
+2 -2
View File
@@ -608,13 +608,13 @@ function readBundledDoc(fileName: string): string {
*/
function ringConnectionMenuItem(): MenuItem {
const item = enumSettingMenuItem(ringConnectionModeSetting);
const io = () => glassesTypeSetting.get() === "rayneo-io";
const io = () => glassesTypeSetting.get() !== "g2";
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)");
drawRightValueMenuItem(args.image, getDefaultSmallFont(), args.x, args.y, args.width, item.label, glassesTypeSetting.get() === "g1" ? "Direct (Even G1)" : "Direct (RayNeo iO)");
},
};
}