forked from Blendman974/faceclaw
Flashing uses 2.2.9 as base version
This commit is contained in:
1 parent
c7d4e7a630
commit
76825f68a7
8 files changed
+324
-91
No files matched your search
@@ -6,20 +6,32 @@ export type FlashPromptState =
|
||||
| "connecting"
|
||||
| "connected"
|
||||
| "prompting"
|
||||
| "battery"
|
||||
| "result"
|
||||
| "cancelled"
|
||||
| "timeout"
|
||||
| "disconnected"
|
||||
| "error";
|
||||
|
||||
/** Per-arm battery percent; null when that arm didn't answer. */
|
||||
export type FlashPromptBattery = { right: number | null; left: number | null };
|
||||
|
||||
function normalizePercent(value: number): number | null {
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) && n >= 0 ? n : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* TS wrapper around the native FaceclawFlashPromptCommunicator — the
|
||||
* stock-firmware-compatible BLE path that shows the pre-flash confirmation on
|
||||
* the glasses and reports the user's Yes/No choice. Separate from
|
||||
* FaceclawCommunicatorBridge on purpose (different, minimal protocol subset).
|
||||
*
|
||||
* Talks to the right arm only: the lenses relay messages between themselves,
|
||||
* and acks/events always come from the right arm.
|
||||
* Connects and authenticates both arms (so any OS pairing prompts happen up
|
||||
* front, before flashing), shows the prompt via the right arm (the lenses relay
|
||||
* messages between themselves, and acks/events always come from the right
|
||||
* arm), then reads each arm's battery. With `skipPrompt` the on-glasses
|
||||
* confirmation is omitted and only the battery is read.
|
||||
*/
|
||||
export class FlashPromptCommunicator {
|
||||
private readonly communicator: any;
|
||||
@@ -27,20 +39,32 @@ export class FlashPromptCommunicator {
|
||||
private readonly logListeners = new Set<(line: string) => void>();
|
||||
private readonly stateListeners = new Set<(state: FlashPromptState, detail: string) => void>();
|
||||
private readonly resultListeners = new Set<(approved: boolean) => void>();
|
||||
private readonly batteryListeners = new Set<(battery: FlashPromptBattery) => void>();
|
||||
|
||||
constructor(rightAddress: string, warningText: string) {
|
||||
constructor(
|
||||
addresses: { right: string; left: string },
|
||||
warningText: string,
|
||||
options?: { skipPrompt?: boolean },
|
||||
) {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
if (!context) throw new Error("Android application context unavailable");
|
||||
|
||||
this.communicator = new com.faceclaw.app.FaceclawFlashPromptCommunicator(
|
||||
context,
|
||||
rightAddress,
|
||||
addresses.right,
|
||||
addresses.left,
|
||||
warningText,
|
||||
Boolean(options?.skipPrompt),
|
||||
);
|
||||
this.listenerProxy = new com.faceclaw.app.FaceclawFlashPromptListener({
|
||||
onLog: (line: string) => this.emit(this.logListeners, String(line)),
|
||||
onState: (state: string, detail: string) =>
|
||||
this.emit(this.stateListeners, String(state) as FlashPromptState, String(detail ?? "")),
|
||||
onBattery: (rightPercent: number, leftPercent: number) =>
|
||||
this.emit(this.batteryListeners, {
|
||||
right: normalizePercent(rightPercent),
|
||||
left: normalizePercent(leftPercent),
|
||||
}),
|
||||
onResult: (approved: boolean) => this.emit(this.resultListeners, Boolean(approved)),
|
||||
});
|
||||
this.communicator.setListener(this.listenerProxy);
|
||||
@@ -56,6 +80,11 @@ export class FlashPromptCommunicator {
|
||||
return () => this.stateListeners.delete(listener);
|
||||
}
|
||||
|
||||
onBattery(listener: (battery: FlashPromptBattery) => void): () => void {
|
||||
this.batteryListeners.add(listener);
|
||||
return () => this.batteryListeners.delete(listener);
|
||||
}
|
||||
|
||||
onResult(listener: (approved: boolean) => void): () => void {
|
||||
this.resultListeners.add(listener);
|
||||
return () => this.resultListeners.delete(listener);
|
||||
|
||||
Reference in new issue
Block a user