forked from Blendman974/faceclaw
Add proximity-based pairing for Even devices
Stream BLE advertisements into a dedicated pairing flow with arm, ring, serial, and hardware variant detection. Add proximity ranking, device artwork, pairing safeguards, and unit coverage for discovery and candidate grouping.
This commit is contained in:
35 files changed
+3309
-140
No files matched your search
@@ -1,7 +1,16 @@
|
||||
import { Frame, Observable } from "@nativescript/core";
|
||||
|
||||
import { ensureBlePermissions } from "../g2/android-permissions";
|
||||
import { isValidMacAddress, loadDeviceAddresses, normalizeMacAddress, saveDeviceAddresses } from "../g2/device-addresses";
|
||||
import {
|
||||
isValidMacAddress,
|
||||
loadDeviceAddresses,
|
||||
loadPairedGlassesIdentityForAddresses,
|
||||
normalizeMacAddress,
|
||||
saveDeviceAddresses,
|
||||
type PairedGlassesIdentity,
|
||||
} from "../g2/device-addresses";
|
||||
import { glassesImagePath } from "../g2/glasses-artwork";
|
||||
import { GlassesHardwareIdentity } from "../g2/glasses-hardware-identity";
|
||||
import { buildAddressSet, DeviceDiscoveryBridge } from "../native/device-discovery";
|
||||
|
||||
type TextChangeArgs = { value?: string; object?: { text?: string } };
|
||||
@@ -15,6 +24,7 @@ export class ConfigViewModel extends Observable {
|
||||
private _status = "";
|
||||
private _discoveryLog = "";
|
||||
private _discovering = false;
|
||||
private pairedIdentity: PairedGlassesIdentity | null = null;
|
||||
|
||||
constructor(options?: { onboarding?: boolean }) {
|
||||
super();
|
||||
@@ -23,9 +33,69 @@ export class ConfigViewModel extends Observable {
|
||||
this.rightAddress = stored.right;
|
||||
this.leftAddress = stored.left;
|
||||
this.ringAddress = stored.ring;
|
||||
this.refreshIdentity();
|
||||
this.status = this.onboarding
|
||||
? "Load the addresses from the glasses you paired with the official Even app, or scan / enter them, then Continue."
|
||||
: "Edit addresses manually, or load them from paired devices or a scan.";
|
||||
? "Scan for glasses to pick yours by model and serial, load the addresses of devices paired with this phone, or enter them by hand, then Continue."
|
||||
: "Edit addresses manually, scan for glasses, or load them from paired devices.";
|
||||
}
|
||||
|
||||
// --- paired identity card --------------------------------------------------
|
||||
|
||||
/** The identity saved by the pairing scan, shown only while it still describes the entered addresses. */
|
||||
private refreshIdentity(): void {
|
||||
this.pairedIdentity = loadPairedGlassesIdentityForAddresses({
|
||||
right: this._rightAddress,
|
||||
left: this._leftAddress,
|
||||
ring: this._ringAddress,
|
||||
});
|
||||
for (const property of [
|
||||
"identityVisibility",
|
||||
"identityImagePath",
|
||||
"identityTitle",
|
||||
"identityVariant",
|
||||
"identityVariantVisibility",
|
||||
"identitySerial",
|
||||
"identityDetail",
|
||||
] as const) {
|
||||
this.notifyPropertyChange(property, this[property]);
|
||||
}
|
||||
}
|
||||
|
||||
private get decodedIdentity(): GlassesHardwareIdentity | null {
|
||||
return GlassesHardwareIdentity.decode(this.pairedIdentity?.serial);
|
||||
}
|
||||
|
||||
get identityVisibility(): "visible" | "collapse" {
|
||||
return this.pairedIdentity ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get identityImagePath(): string {
|
||||
return glassesImagePath(this.decodedIdentity);
|
||||
}
|
||||
|
||||
get identityTitle(): string {
|
||||
return this.decodedIdentity?.productName ?? "Even Realities G2";
|
||||
}
|
||||
|
||||
get identityVariant(): string {
|
||||
return this.decodedIdentity?.variantSummary ?? "";
|
||||
}
|
||||
|
||||
get identityVariantVisibility(): "visible" | "collapse" {
|
||||
return this.identityVariant ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get identitySerial(): string {
|
||||
return this.pairedIdentity ? `Serial ${this.pairedIdentity.serial}` : "";
|
||||
}
|
||||
|
||||
get identityDetail(): string {
|
||||
const identity = this.pairedIdentity;
|
||||
if (!identity) return "";
|
||||
const parts = [`Left ${identity.leftName || identity.leftAddress}`, `Right ${identity.rightName || identity.rightAddress}`];
|
||||
if (identity.ringName) parts.push(`Ring ${identity.ringName}`);
|
||||
if (identity.pairedAtMs) parts.push(`paired ${new Date(identity.pairedAtMs).toLocaleDateString()}`);
|
||||
return parts.join(" · ");
|
||||
}
|
||||
|
||||
get saveLabel(): string {
|
||||
@@ -100,10 +170,12 @@ export class ConfigViewModel extends Observable {
|
||||
|
||||
onRightAddressTextChange(args: TextChangeArgs): void {
|
||||
this.rightAddress = args.object?.text ?? args.value ?? "";
|
||||
this.refreshIdentity();
|
||||
}
|
||||
|
||||
onLeftAddressTextChange(args: TextChangeArgs): void {
|
||||
this.leftAddress = args.object?.text ?? args.value ?? "";
|
||||
this.refreshIdentity();
|
||||
}
|
||||
|
||||
onRingAddressTextChange(args: TextChangeArgs): void {
|
||||
@@ -114,8 +186,12 @@ export class ConfigViewModel extends Observable {
|
||||
await this.populateFromDiscovery(async () => this.discovery.getBondedCandidates(), "Loaded paired devices.");
|
||||
}
|
||||
|
||||
async onScanTap(): Promise<void> {
|
||||
await this.populateFromDiscovery(async () => this.discovery.scanCandidates(6000), "Scanned nearby devices.");
|
||||
/** The live scan page identifies pairs by serial, model, and distance; hand off to it. */
|
||||
onScanTap(): void {
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/pairing-page",
|
||||
context: { onboarding: this.onboarding },
|
||||
});
|
||||
}
|
||||
|
||||
onBackTap(): void {
|
||||
@@ -186,6 +262,7 @@ export class ConfigViewModel extends Observable {
|
||||
if (selection.right) this.rightAddress = selection.right;
|
||||
if (selection.left) this.leftAddress = selection.left;
|
||||
if (selection.ring) this.ringAddress = selection.ring;
|
||||
this.refreshIdentity();
|
||||
this.discoveryLog = selection.summary;
|
||||
this.status = successMessage;
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user