mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
On stock 2.2.9 the settings read on the right lens goes unanswered even after a successful security-auth exchange and fresh pairing. Since no 2.2.9-era capture of a settings read exists (g2flash only exercises auth + OTA), turn the probe into an experiment that a single on-device run can settle: - Log every control-channel frame (sid/flag/type/magic/frag/payload prefix) and every write under the FaceclawDeviceInfo logcat tag. - Retry the settings read once before concluding a lens is silent. - Accept a sid-0x09 frame carrying firmware versions on the device's own magic (an unsolicited push) as an answer, not just the awaited ack. - If the right lens stays silent, run the same connect/auth/prelude/read against the LEFT lens and use its answer, logging which lens replied, to test whether 2.2.9 moved the settings endpoint. The probe now takes both arm addresses; the firmware-check page passes them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ZqzwmRQ3HQxasBz5rYyZV
102 lines
3.1 KiB
TypeScript
102 lines
3.1 KiB
TypeScript
import { Utils } from "@nativescript/core";
|
|
|
|
declare const com: any;
|
|
|
|
export type DeviceInfo = {
|
|
leftVersion: string;
|
|
rightVersion: string;
|
|
capabilities: string;
|
|
};
|
|
|
|
export type DeviceInfoState = "connecting" | "authenticating" | "querying";
|
|
|
|
/**
|
|
* TS wrapper around the native FaceclawDeviceInfoProbe — a one-shot,
|
|
* stock-compatible connect + firmware/device-info read. `run()` resolves with
|
|
* the firmware versions and CFW capability string, or rejects on failure.
|
|
*/
|
|
export class DeviceInfoProbe {
|
|
private readonly probe: any;
|
|
private readonly listenerProxy: any;
|
|
private readonly logListeners = new Set<(line: string) => void>();
|
|
private readonly stateListeners = new Set<(state: DeviceInfoState, detail: string) => void>();
|
|
|
|
private settled = false;
|
|
private resolveFn: ((info: DeviceInfo) => void) | null = null;
|
|
private rejectFn: ((error: Error) => void) | null = null;
|
|
|
|
constructor(rightAddress: string, leftAddress = "") {
|
|
const context = Utils.android.getApplicationContext();
|
|
if (!context) throw new Error("Android application context unavailable");
|
|
|
|
this.probe = new com.faceclaw.app.FaceclawDeviceInfoProbe(context, rightAddress, leftAddress);
|
|
this.listenerProxy = new com.faceclaw.app.FaceclawDeviceInfoProbeListener({
|
|
onLog: (line: string) => this.emit(this.logListeners, String(line)),
|
|
onState: (state: string, detail: string) =>
|
|
this.emit(this.stateListeners, String(state) as DeviceInfoState, String(detail ?? "")),
|
|
onResult: (leftVersion: string, rightVersion: string, capabilities: string) =>
|
|
this.settle(null, {
|
|
leftVersion: String(leftVersion),
|
|
rightVersion: String(rightVersion),
|
|
capabilities: String(capabilities),
|
|
}),
|
|
onError: (message: string) => this.settle(new Error(String(message)), null),
|
|
});
|
|
this.probe.setListener(this.listenerProxy);
|
|
}
|
|
|
|
onLog(listener: (line: string) => void): () => void {
|
|
this.logListeners.add(listener);
|
|
return () => this.logListeners.delete(listener);
|
|
}
|
|
|
|
onStateChange(listener: (state: DeviceInfoState, detail: string) => void): () => void {
|
|
this.stateListeners.add(listener);
|
|
return () => this.stateListeners.delete(listener);
|
|
}
|
|
|
|
run(): Promise<DeviceInfo> {
|
|
return new Promise<DeviceInfo>((resolve, reject) => {
|
|
this.resolveFn = resolve;
|
|
this.rejectFn = reject;
|
|
this.probe.start();
|
|
});
|
|
}
|
|
|
|
cancel(): void {
|
|
try {
|
|
this.probe.cancel();
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}
|
|
|
|
close(): void {
|
|
try {
|
|
this.probe.close();
|
|
} catch {
|
|
// ignore
|
|
}
|
|
}
|
|
|
|
private settle(error: Error | null, info: DeviceInfo | null): void {
|
|
if (this.settled) return;
|
|
this.settled = true;
|
|
this.close();
|
|
if (error) {
|
|
this.rejectFn?.(error);
|
|
} else if (info) {
|
|
this.resolveFn?.(info);
|
|
}
|
|
}
|
|
|
|
private emit<A extends unknown[]>(listeners: Set<(...args: A) => void>, ...args: A): void {
|
|
const snapshot = Array.from(listeners);
|
|
setTimeout(() => {
|
|
for (const listener of snapshot) {
|
|
listener(...args);
|
|
}
|
|
}, 0);
|
|
}
|
|
}
|