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);