forked from Blendman974/faceclaw
Add long-press and mic buttons to preview form; fix canula-age display in Nightscout when outside 4-day window
This commit is contained in:
1 parent
93d98965de
commit
57d8d2fc79
4 files changed
+70
-11
No files matched your search
@@ -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<void> {
|
||||
async injectSyntheticRingInput(
|
||||
kind: "click" | "double-click" | "scroll-up" | "scroll-down" | "long-press" | "wakeword",
|
||||
): Promise<void> {
|
||||
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",
|
||||
|
||||
@@ -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<NightscoutEntryResponse[]>(
|
||||
@@ -210,7 +216,7 @@ export class NightscoutBridge {
|
||||
`${siteUrl}/api/v1/treatments.json?find%5Bcreated_at%5D%5B%24gte%5D=${encodeURIComponent(treatmentStartIso)}&${tokenQuery}`,
|
||||
),
|
||||
fetchJson<NightscoutTreatmentResponse[]>(
|
||||
`${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}`,
|
||||
),
|
||||
]);
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@
|
||||
<GridLayout rows="auto,auto,auto" columns="*,*,*" class="m-t-8">
|
||||
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
|
||||
<Button row="1" col="0" text="Double-click" tap="{{ onSyntheticLeftTap }}" />
|
||||
<Button row="1" col="1" text="Long press" tap="{{ onSyntheticLongPressTap }}" />
|
||||
<Button row="1" col="2" text="Click" tap="{{ onSyntheticRightTap }}" />
|
||||
<Button row="0" col="2" text="Microphone" tap="{{ onSyntheticMicTap }}" />
|
||||
<Button row="2" col="1" text="Swipe down" tap="{{ onSyntheticDownTap }}" />
|
||||
</GridLayout>
|
||||
<Button text="Save raw screenshot" tap="{{ onScreenshotTap }}" visibility="{{ screenshotButtonVisibility }}" />
|
||||
@@ -83,7 +85,9 @@
|
||||
<GridLayout rows="auto,auto,auto" columns="*,*,*">
|
||||
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
|
||||
<Button row="1" col="0" text="Double-click" tap="{{ onSyntheticLeftTap }}" />
|
||||
<Button row="1" col="1" text="Long press" tap="{{ onSyntheticLongPressTap }}" />
|
||||
<Button row="1" col="2" text="Click" tap="{{ onSyntheticRightTap }}" />
|
||||
<Button row="0" col="2" text="Microphone" tap="{{ onSyntheticMicTap }}" />
|
||||
<Button row="2" col="1" text="Swipe down" tap="{{ onSyntheticDownTap }}" />
|
||||
</GridLayout>
|
||||
<Button text="Save raw screenshot" tap="{{ onScreenshotTap }}" visibility="{{ screenshotButtonVisibility }}" />
|
||||
|
||||
@@ -437,6 +437,14 @@ export class MainViewModel extends Observable {
|
||||
await dashboardController.injectSyntheticRingInput("click");
|
||||
}
|
||||
|
||||
async onSyntheticLongPressTap(): Promise<void> {
|
||||
await dashboardController.injectSyntheticRingInput("long-press");
|
||||
}
|
||||
|
||||
async onSyntheticMicTap(): Promise<void> {
|
||||
await dashboardController.injectSyntheticRingInput("wakeword");
|
||||
}
|
||||
|
||||
private appendLog(line: string): void {
|
||||
const stamp = new Date().toISOString().slice(11, 19);
|
||||
this.log = this.log ? `${this.log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`;
|
||||
|
||||
Reference in new issue
Block a user