diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index c38b6f5d..b7bb3bdf 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -9,7 +9,7 @@ import { } from "./events"; import { loadDeviceAddresses } from "./device-addresses"; import { ensureBlePermissions, ensureFineLocationPermission, ensureVoicePermissions } from "./android-permissions"; -import { FaceclawCommunicatorBridge, type FrameMetrics, type RawInputEvent } from "../native/faceclaw-communicator"; +import { FaceclawCommunicatorBridge, type RawInputEvent } from "../native/faceclaw-communicator"; import * as frameTimings from "../native/frame-timings"; import { startForegroundNotification, stopForegroundNotification, updateForegroundNotification } from "../native/foreground-service"; import { mediaControllerBridge } from "../native/media-controller"; @@ -734,9 +734,9 @@ class DashboardController { this.appendLog(message); this.emit(); }); - this.offFrameMetrics = communicator.onFrameMetrics((metrics) => { + this.offFrameMetrics = communicator.onFrameMetrics(() => { if (this.phase === "connected") { - this.setStatus(`Connected. Last frame: ${this.formatFrameMetrics(metrics)}.`); + this.setStatus("Connected."); // A rendered frame means the session is warmed up (fixedLayoutCreated), // so the buzzer won't be dropped. Play the one-time welcome sound now. if (this.welcomeSoundArmed) { @@ -922,7 +922,16 @@ class DashboardController { } } - async injectSyntheticRingInput(kind: "click" | "double-click" | "scroll-up" | "scroll-down"): Promise { + async injectSyntheticRingInput( + kind: "click" | "double-click" | "scroll-up" | "scroll-down" | "long-press" | "wakeword", + ): Promise { + if (kind === "long-press") { + // Hardware delivers a press event and then a release when the finger + // lifts; emulate a short hold so the escape-menu countdown never fires. + await this.handleInputEvent(this.buildSyntheticRingInput("long-press")); + await this.handleInputEvent(this.buildSyntheticRingInput("long-press-release")); + return; + } const event = this.buildSyntheticRingInput(kind); await this.handleInputEvent(event); } @@ -1542,11 +1551,6 @@ class DashboardController { updateForegroundNotification("Connected"); } - private formatFrameMetrics(metrics: FrameMetrics): string { - return `paint=${Math.round(metrics.paintMs)}ms, transmit=${Math.round(metrics.transmitMs)}ms, tiles=${Math.round(metrics.tileCount)}`; - } - - private appendLog(line: string): void { const stamped = `[${formatTimestamp(new Date())}] ${line}`; //this.log = this.log ? `${this.log}\n${stamped}` : stamped; @@ -1589,9 +1593,46 @@ class DashboardController { return `${sanitized.slice(0, 237)}...`; } - private buildSyntheticRingInput(kind: "click" | "double-click" | "scroll-up" | "scroll-down"): RawInputEvent { + private buildSyntheticRingInput( + kind: + | "click" + | "double-click" + | "scroll-up" + | "scroll-down" + | "long-press" + | "long-press-release" + | "wakeword", + ): RawInputEvent { const frameId = frameTimings.startFrame(`input:synthetic:${kind}`); switch (kind) { + case "wakeword": + // Same event the glasses report for the spoken wakeword (sid 0x07). + return { + kind: "even-ai", + containerName: "", + eventType: EvenAIStatus.EVEN_AI_WAKE_UP, + eventSource: 0, + systemExitReasonCode: 0, + frameId, + }; + case "long-press": + return { + kind: "sys-event", + containerName: "", + eventType: OsEventTypeList.RING_LONG_PRESS_EVENT, + eventSource: EventSourceType.TOUCH_EVENT_FROM_RING, + systemExitReasonCode: 0, + frameId, + }; + case "long-press-release": + return { + kind: "sys-event", + containerName: "", + eventType: OsEventTypeList.RING_LONG_PRESS_RELEASE_EVENT, + eventSource: EventSourceType.TOUCH_EVENT_FROM_RING, + systemExitReasonCode: 0, + frameId, + }; case "click": return { kind: "sys-event", diff --git a/app/native/nightscout-bridge.ts b/app/native/nightscout-bridge.ts index ab38aa52..8be3f272 100644 --- a/app/native/nightscout-bridge.ts +++ b/app/native/nightscout-bridge.ts @@ -103,6 +103,11 @@ const NIGHTSCOUT_REFRESH_MS = 60_000; const NIGHTSCOUT_HISTORY_COUNT = 30; const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000; const NIGHTSCOUT_TREATMENT_LOOKBACK_MS = 3 * 60 * 60 * 1000; +// The v1 treatments API silently adds `created_at >= now - 4 days` to any +// query without an explicit date filter (lib/server/query.js enforceDateFilter), +// which is shorter than a typical cannula age. 62 days matches the window the +// Nightscout webapp uses for its own CAGE query. +const NIGHTSCOUT_SITE_CHANGE_LOOKBACK_MS = 62 * 24 * 60 * 60 * 1000; const DEFAULT_NIGHTSCOUT_STATE: NightscoutState = { available: false, @@ -195,6 +200,7 @@ export class NightscoutBridge { return; } const treatmentStartIso = new Date(nowMs - NIGHTSCOUT_TREATMENT_LOOKBACK_MS).toISOString(); + const siteChangeStartIso = new Date(nowMs - NIGHTSCOUT_SITE_CHANGE_LOOKBACK_MS).toISOString(); const tokenQuery = `token=${encodeURIComponent(apiToken)}`; const [entries, deviceStatus, status, treatments, siteChanges] = await Promise.all([ fetchJson( @@ -210,7 +216,7 @@ export class NightscoutBridge { `${siteUrl}/api/v1/treatments.json?find%5Bcreated_at%5D%5B%24gte%5D=${encodeURIComponent(treatmentStartIso)}&${tokenQuery}`, ), fetchJson( - `${siteUrl}/api/v1/treatments.json?find%5BeventType%5D=Site%20Change&count=1&${tokenQuery}`, + `${siteUrl}/api/v1/treatments.json?find%5BeventType%5D=Site%20Change&find%5Bcreated_at%5D%5B%24gte%5D=${encodeURIComponent(siteChangeStartIso)}&count=1&${tokenQuery}`, ), ]); diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index 1f89d87c..6d34beb6 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -37,7 +37,9 @@