Show in Diagnostics what the glasses deliver (event types only)
During the second device session a tap on the glasses did nothing and the phone page could not show whether the Even app had delivered any event. The Even adapter now counts gesture/lifecycle events, ignored events and audio frames and records the last non-audio event by envelope and type code (never audio or content). The phone's Diagnostics shows it and refreshes when an event arrives, including one that changes no state. Not reviewed. Not deployed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -170,10 +170,52 @@ export class EvenDevice implements DevicePort {
|
||||
|
||||
onEvent(listener: (event: DeviceEvent) => void): () => void {
|
||||
return this.bridge.onEvenHubEvent((event) => {
|
||||
for (const normalized of normalizeEvent(event as RawEvenHubEvent)) listener(normalized);
|
||||
const normalized = normalizeEvent(event as RawEvenHubEvent);
|
||||
this.recordInput(event as RawEvenHubEvent, normalized);
|
||||
for (const one of normalized) listener(one);
|
||||
});
|
||||
}
|
||||
|
||||
// ---- input diagnostics: what the host has delivered, by type only -------------------
|
||||
private input = { gestures: 0, audioFrames: 0, unrecognised: 0, last: 'none yet', lastAt: 0 };
|
||||
private readonly inputListeners = new Set<() => void>();
|
||||
|
||||
private recordInput(raw: RawEvenHubEvent, normalized: DeviceEvent[]): void {
|
||||
const audioOnly = normalized.length > 0 && normalized.every((e) => e.type === 'audio');
|
||||
if (audioOnly) {
|
||||
// Counted, not announced: frames arrive ten times a second.
|
||||
this.input.audioFrames += 1;
|
||||
return;
|
||||
}
|
||||
// Envelope names and numeric type codes only. Never payload content.
|
||||
const envelopes = (['sysEvent', 'textEvent', 'listEvent', 'menuItemClickEvent'] as const)
|
||||
.filter((key) => raw[key] !== undefined)
|
||||
.map((key) => {
|
||||
const env = raw[key] as { eventType?: number; eventSource?: number; itemID?: number };
|
||||
const parts = [`type=${env.eventType ?? 'none'}`];
|
||||
if (env.eventSource !== undefined) parts.push(`source=${env.eventSource}`);
|
||||
if (env.itemID !== undefined) parts.push(`item=${env.itemID}`);
|
||||
return `${key}(${parts.join(',')})`;
|
||||
});
|
||||
const meaning = normalized.filter((e) => e.type !== 'audio').map((e) => e.type);
|
||||
if (meaning.length) this.input.gestures += 1;
|
||||
else this.input.unrecognised += 1;
|
||||
this.input.last = `${envelopes.join('+') || 'no known envelope'} -> ${meaning.join(',') || 'ignored'}`;
|
||||
this.input.lastAt = Date.now();
|
||||
for (const l of this.inputListeners) l();
|
||||
}
|
||||
|
||||
inputSummary(): string {
|
||||
const { gestures, audioFrames, unrecognised, last, lastAt } = this.input;
|
||||
const when = lastAt ? ` at ${new Date(lastAt).toISOString().slice(11, 19)} UTC` : '';
|
||||
return `${gestures} gesture/lifecycle event(s), ${unrecognised} ignored, ${audioFrames} audio frame(s); last: ${last}${when}`;
|
||||
}
|
||||
|
||||
onInputActivity(listener: () => void): () => void {
|
||||
this.inputListeners.add(listener);
|
||||
return () => this.inputListeners.delete(listener);
|
||||
}
|
||||
|
||||
onConnection(listener: (connected: boolean) => void): () => void {
|
||||
return this.bridge.onDeviceStatusChanged((status) => {
|
||||
if (status.connectType === DeviceConnectType.Connected) listener(true);
|
||||
|
||||
@@ -27,4 +27,11 @@ export interface DevicePort {
|
||||
* land later, so `false` is "not confirmed", never "not written" and never "written".
|
||||
*/
|
||||
storageSet(key: string, value: string): Promise<boolean>;
|
||||
/**
|
||||
* Optional, for the phone's Diagnostics only: a one-line summary of what the glasses runtime
|
||||
* has delivered (counts and event types; never audio or any content).
|
||||
*/
|
||||
inputSummary?(): string;
|
||||
/** Optional: called whenever `inputSummary()` would change. */
|
||||
onInputActivity?(listener: () => void): () => void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user