forked from Blendman974/faceclaw
Port developer debug tests to iOS
This commit is contained in:
1 parent
bc57557f04
commit
a5eda29368
16 files changed
+737
-151
No files matched your search
@@ -50,32 +50,24 @@ function debugTestsMenu(openInputEvents: OpenPage, openMicrophones: OpenPage): M
|
||||
},
|
||||
{
|
||||
label: "Buzzer demo",
|
||||
disabled: global.isIOS,
|
||||
description: global.isIOS ? "Glasses sound playback is not available on iOS yet." : undefined,
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new BuzzerDemoLayer());
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Accelerometer demo",
|
||||
disabled: global.isIOS,
|
||||
description: global.isIOS ? "Not available on iOS yet." : undefined,
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new AccelerometerDemoLayer(DEVELOPER_WINDOW_ID, ctx.actions.requestRender));
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Light sensor",
|
||||
disabled: global.isIOS,
|
||||
description: global.isIOS ? "Not available on iOS yet." : undefined,
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new LightSensorDemoLayer(DEVELOPER_WINDOW_ID, ctx.actions.requestRender));
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Microphones",
|
||||
disabled: global.isIOS,
|
||||
description: global.isIOS ? "Not available on iOS yet." : undefined,
|
||||
onSelect: openMicrophones,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||
import { useMicControlSetting } from "../../ui/dashboard-settings";
|
||||
import { toJavaBytes } from "../../native/cloud-stt";
|
||||
import { toUint8Array } from "../../util/array-util";
|
||||
import { addMicStatusListener, micControlSession, sendMicControlRecord } from "../../native/mic-control-link";
|
||||
import {
|
||||
MIC_LEASE_MS,
|
||||
decodeMicStatus,
|
||||
@@ -14,8 +13,6 @@ import {
|
||||
type MicStatus,
|
||||
} from "./mic-protocol";
|
||||
|
||||
declare const com: any;
|
||||
|
||||
/**
|
||||
* Host-side controller for the CFW mic_control array: sends the same config
|
||||
* to both temples (each temple is its own endpoint and its own 2-mic array),
|
||||
@@ -30,15 +27,6 @@ const LEASE_RENEW_MS = Math.floor(MIC_LEASE_MS / 3);
|
||||
|
||||
export type MicArrayStatuses = { left: MicStatus | null; right: MicStatus | null };
|
||||
|
||||
function activeCommunicator(): any {
|
||||
if (!global.isAndroid) return null;
|
||||
try {
|
||||
return com.faceclaw.app.FaceclawBleCommunicator.getActive();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the "Use microphone control" developer setting is on. With the
|
||||
* setting off, Faceclaw behaves exactly as it would on firmware without the
|
||||
@@ -71,9 +59,9 @@ export function saveMicConfig(config: MicConfig): void {
|
||||
class MicArrayController {
|
||||
private readonly statusListeners = new Set<(statuses: MicArrayStatuses) => void>();
|
||||
private statuses: MicArrayStatuses = { left: null, right: null };
|
||||
// The Java listener proxy must stay referenced or it gets GC'd.
|
||||
private statusProxy: any = null;
|
||||
private proxyCommunicator: any = null;
|
||||
// Holds the native listener proxy, which must stay referenced or it gets GC'd.
|
||||
private unsubscribeStatus: (() => void) | null = null;
|
||||
private statusSession: unknown = null;
|
||||
private leaseTimer: ReturnType<typeof setInterval> | null = null;
|
||||
private armed = false;
|
||||
|
||||
@@ -158,39 +146,28 @@ class MicArrayController {
|
||||
rightTemple = true,
|
||||
leftTemple = true,
|
||||
): boolean {
|
||||
const communicator = activeCommunicator();
|
||||
if (!communicator) return false;
|
||||
const session = micControlSession();
|
||||
if (!session) return false;
|
||||
try {
|
||||
this.ensureStatusProxy(communicator);
|
||||
const record = encodeMicControl(op, config);
|
||||
// False when the session wasn't ready and nothing was queued.
|
||||
return communicator.sendFaceclawMicControl(toJavaBytes(record), label, rightTemple, leftTemple) !== false;
|
||||
this.ensureStatusListener(session);
|
||||
return sendMicControlRecord(session, encodeMicControl(op, config), label, rightTemple, leftTemple);
|
||||
} catch (error) {
|
||||
console.warn(`mic control ${label} failed: ${error}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private ensureStatusProxy(communicator: any): void {
|
||||
if (this.statusProxy && this.proxyCommunicator === communicator) return;
|
||||
if (this.statusProxy && this.proxyCommunicator) {
|
||||
try {
|
||||
this.proxyCommunicator.removeMicStatusListener(this.statusProxy);
|
||||
} catch {
|
||||
// The old communicator instance may be gone after a reconnect.
|
||||
}
|
||||
}
|
||||
this.statusProxy = new com.faceclaw.app.FaceclawMicStatusListener({
|
||||
onMicStatus: (body: any, arm: string) => {
|
||||
const status = decodeMicStatus(toUint8Array(body));
|
||||
if (!status) return;
|
||||
const side: MicSide = String(arm) === "L" ? "left" : "right";
|
||||
this.statuses = { ...this.statuses, [side]: { ...status, side } };
|
||||
this.statusListeners.forEach((listener) => listener(this.statuses));
|
||||
},
|
||||
private ensureStatusListener(session: unknown): void {
|
||||
if (this.unsubscribeStatus && this.statusSession === session) return;
|
||||
this.unsubscribeStatus?.();
|
||||
this.statusSession = session;
|
||||
this.unsubscribeStatus = addMicStatusListener(session, (body, arm) => {
|
||||
const status = decodeMicStatus(body);
|
||||
if (!status) return;
|
||||
const side: MicSide = arm === "L" ? "left" : "right";
|
||||
this.statuses = { ...this.statuses, [side]: { ...status, side } };
|
||||
this.statusListeners.forEach((listener) => listener(this.statuses));
|
||||
});
|
||||
this.proxyCommunicator = communicator;
|
||||
communicator.addMicStatusListener(this.statusProxy);
|
||||
}
|
||||
|
||||
private syncLeaseTimer(): void {
|
||||
|
||||
Reference in new issue
Block a user