forked from Blendman974/faceclaw
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:
1 parent
f803f4212c
commit
67aff19923
27 files changed
+1902
-45
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user