Rebase firmware on 2.3.0, fixing issue with lost ring input events

This commit is contained in:
James Babcock committed 2026-09-19 17:19:21 -07:00
1 parent 8ceecb6393
commit b972cd7682
21 files changed
+790 -156

No files matched your search

+5
View File
@@ -1,5 +1,10 @@
# Changelog
## 0.7.2 - Unreleased
* Rebase to firmware 2.3.0, fixing an issue with some R1 ring input events being lost
* Modify built in games to use ring-press rather than click
## 0.7.1 - 2026-09-19
### iOS Developer Beta
+13 -2
View File
@@ -1,5 +1,7 @@
import { MenuLayer, drawSubmenuIndicator, type MenuItem } from "../../ui/menu";
import { ScreenTestLayer } from "./screen-test";
import { InputEventsLayer } from "./input-events";
import { shell } from "../../ui/shell/shell";
import { BuzzerDemoLayer } from "./buzzer-demo";
import { AccelerometerDemoLayer } from "./accelerometer-demo";
import { BandwidthBenchmarkLayer } from "./bandwidth-benchmark";
@@ -48,10 +50,11 @@ function submenuItem(label: string, onSelect: MenuItem["onSelect"]): MenuItem {
}
/** The diagnostic demos, one level down from the root menu. */
function debugTestsMenu(): MenuLayer {
function debugTestsMenu(openInputEvents: (ctx: Parameters<MenuItem["onSelect"]>[0]) => void): MenuLayer {
return new MenuLayer(
"Debug tests",
[
{ label: "Input events", onSelect: openInputEvents },
{
label: "Dither test",
onSelect: (ctx) => {
@@ -103,6 +106,7 @@ function debugTestsMenu(): MenuLayer {
* under "Debug tests".
*/
export function createDeveloperAppWindow(appContext: AppContext, options: InProcessAppOptions): InProcessWindow {
let inputEvents: InputEventsLayer | null = null;
const menu = new MenuLayer(
"Developer",
[
@@ -131,7 +135,13 @@ export function createDeveloperAppWindow(appContext: AppContext, options: InProc
},
},
submenuItem("Debug tests", (ctx) => {
ctx.stack.push(debugTestsMenu());
ctx.stack.push(debugTestsMenu((inputCtx) => {
const page = new InputEventsLayer(inputCtx.actions.requestRender,
() => shell.isWindowVisible(DEVELOPER_WINDOW_ID),
() => { if (inputEvents === page) inputEvents = null; });
inputEvents = page;
inputCtx.stack.push(page);
}));
}),
],
MENU_LAYOUT,
@@ -145,6 +155,7 @@ export function createDeveloperAppWindow(appContext: AppContext, options: InProc
icon: "wrench",
closeable: true,
actions: options.actions,
menuItems: () => inputEvents?.menuItems() ?? [],
// Dictating a URL is the one thing worth speaking at in this app; the
// load pages take the text and every other page ignores it.
receiveTextInput: (text) => {
+91
View File
@@ -0,0 +1,91 @@
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { GrayImage } from "../../graphics/image";
import { truncateText } from "../../graphics/textwrap";
import type { InputEvent } from "../../ui/gestures";
import { addInputListener, InputEventLog, inputTimestamp } from "../../ui/input-monitor";
import type { Layer, LayerContext } from "../../ui/layers";
import { drawListScrollbar, type MenuItem } from "../../ui/menu";
/** Gestures are samples here; back/clear/pause live in the tap-then-hold menu. */
export class InputEventsLayer implements Layer {
readonly acceptsDirectional = true;
readonly log = new InputEventLog();
private scrollRow = 0;
private visibleRows = 1;
private readonly unsubscribe: () => void;
constructor(requestRender: () => void, isVisible: () => boolean,
private readonly removed: () => void = () => {}) {
this.unsubscribe = addInputListener((event) => {
if (!isVisible() || this.log.paused) return;
this.log.add(event);
this.scrollRow = 0;
requestRender();
});
}
onRemoved(): void { this.unsubscribe(); this.removed(); }
menuItems(): MenuItem[] {
return [
{ label: this.log.paused ? "Resume capture" : "Pause capture", onSelect: (ctx) => {
this.log.paused = !this.log.paused;
this.scrollRow = 0;
ctx.stack.pop();
} },
{ label: "Clear history", onSelect: (ctx) => {
this.log.clear();
this.scrollRow = 0;
ctx.stack.pop();
} },
{ label: "Back to Debug tests", onSelect: (ctx) => { ctx.stack.popThrough(this); } },
];
}
paint(ctx: LayerContext): GrayImage {
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const font = getDefaultSmallFont();
image.drawText(font, 12, 8, "Input events", 230);
const status = `${this.log.paused ? "Paused" : "Live"} ${this.log.count} events`;
image.drawText(font, width - 12 - font.measureText(status), 8, status, 180);
image.drawText(font, 12, 28, "Phone receive time | gap ms | source | event", 140);
const rowHeight = Math.max(18, font.lineHeight + 2);
this.visibleRows = Math.max(1, Math.floor((height - 76) / rowHeight));
this.scrollRow = Math.min(this.scrollRow, Math.max(0, this.log.entries.length - this.visibleRows));
const timeX = 12;
const gapX = timeX + font.measureText("00:00:00.000") + 12;
const sourceX = gapX + font.measureText("+99999") + 12;
const eventX = sourceX + font.measureText("right-arm") + 12;
if (!this.log.entries.length) {
image.drawText(font, 12, 62, "Touch, tap, double-tap, hold, or swipe the ring.", 210);
image.drawText(font, 12, 82, "Press arrives before an interpreted gesture.", 150);
}
for (const [index, entry] of this.log.entries.slice(this.scrollRow, this.scrollRow + this.visibleRows).entries()) {
const { event, gapMs } = entry;
const y = 50 + index * rowHeight;
const gap = gapMs === null ? "-" : `${gapMs >= 0 ? "+" : ""}${gapMs}`;
const source = "source" in event ? event.source ?? "-" : "-";
const label = event.type === "unknown" ? `${event.kind} ${event.eventSource}/${event.eventType}` : event.type;
image.drawText(font, timeX, y, inputTimestamp(event.timestampMs), 170);
image.drawText(font, gapX, y, truncateText(font, gap, sourceX - gapX - 4), 160);
image.drawText(font, sourceX, y, source, 180);
image.drawText(font, eventX, y, truncateText(font, label, width - eventX - 12), event.type === "ring-press" ? 255 : 200);
}
if (this.log.paused) drawListScrollbar(image, width - 5, 50, height - 78,
this.scrollRow, this.visibleRows, this.log.entries.length);
image.drawText(font, 12, height - 20,
this.log.paused ? "Scroll: history Tap-hold: controls" : "Newest first Tap-hold: pause / clear / back", 140);
return image;
}
handleInput(event: InputEvent): void {
// Live gestures, including double-click, must remain on this page.
if (!this.log.paused) return;
if (event.type === "scroll-up" || event.type === "swipe-up") {
this.scrollRow = Math.max(0, this.scrollRow - 1);
} else if (event.type === "scroll-down" || event.type === "swipe-down") {
this.scrollRow = Math.min(Math.max(0, this.log.entries.length - this.visibleRows), this.scrollRow + 1);
}
}
}
+10 -4
View File
@@ -18,7 +18,7 @@
* small and rare.
*
* Controls (a watch swipe in either direction is the primary flap):
* swipe-up, swipe-down, click, or scroll-up flaps; double-click pauses;
* ring-press flaps immediately; watch swipes/clicks also flap. Double-click pauses;
* tap-then-hold opens the window menu. Ready / paused / game over: click or
* a swipe starts or resumes, double-click yields focus. Losing input focus
* mid-flight (a shell overlay such as the system menu or a notification,
@@ -410,10 +410,16 @@ function handleFlightInput(window: FlappyWindow, event: InputEvent, frameId: num
// which way the thumb went shouldn't matter.
case "swipe-up":
case "swipe-down":
case "click":
case "scroll-up":
case "ring-press":
flap(window);
break;
case "click":
// The ring already flapped on down; its later click must not flap again.
if (event.source !== "ring") flap(window);
break;
case "scroll-up":
if (event.source === "watch") flap(window);
break;
case "double-click":
if (window.phase === "playing") {
window.phase = "paused";
@@ -696,7 +702,7 @@ function paintHud(image: GrayImage, window: FlappyWindow): void {
if (window.highScore > 0) {
drawCenteredIn(image, smallFont, 0, width, 44, `best ${window.highScore}`, 150);
}
drawCenteredIn(image, smallFont, 0, width, groundTop(window) - 26, `swipe / ${GESTURE_CLICK} flap`, 150);
drawCenteredIn(image, smallFont, 0, width, groundTop(window) - 26, "Touch ring / swipe to flap", 150);
break;
case "paused":
paintDialog(image, window, "PAUSED", [`${GESTURE_CLICK} resume`, `${GESTURE_DOUBLE_CLICK} leave`]);
+15 -23
View File
@@ -12,8 +12,8 @@
* keep the BLE payload down to the dirty region around the ball.
*
* Controls (ball ready): scroll sets launch power, click launches. In play:
* click flips both flippers, scroll-up/down flips left/right individually,
* double-click pauses. Watch swipes: left/right work the matching flipper,
* ring-press flips both flippers for 300 ms; click launches from the plunger,
* double-click pauses. Swipes no longer trigger individual flippers;
* up/down raise and lower launch power at the plunger.
* Paused/game over: click resumes or starts a new game, double-click yields
* focus, long-press opens the window menu. Losing input focus mid-game (a
@@ -92,8 +92,8 @@ const FLIPPER_REST_DEG = 32;
const FLIPPER_UP_DEG = -34;
const FLIPPER_RISE_DEG_PER_S = 950;
const FLIPPER_FALL_DEG_PER_S = 480;
/** Held at the top this long before falling, so early flips still connect. */
const FLIPPER_HOLD_MS = 140;
/** Activation duration from input to release, including the rise animation. */
const FLIPPER_HOLD_MS = 300;
const FLIPPER_E = 0.4;
type SegmentKind = "wall" | "gate" | "sling";
@@ -507,25 +507,14 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n
case "scroll-up":
if (ready) {
window.launchPower = clamp(window.launchPower + 1, 1, LAUNCH_SPEEDS.length);
} else {
flip(window, window.flippers[0]!);
}
break;
case "scroll-down":
if (ready) {
window.launchPower = clamp(window.launchPower - 1, 1, LAUNCH_SPEEDS.length);
} else {
flip(window, window.flippers[1]!);
}
break;
// Watch swipes: left/right work the matching flipper; up/down set the
// launch power at the plunger.
case "swipe-left":
if (!ready) flip(window, window.flippers[0]!);
break;
case "swipe-right":
if (!ready) flip(window, window.flippers[1]!);
break;
// Watch swipes up/down still set launch power at the plunger.
case "swipe-up":
if (ready) {
window.launchPower = clamp(window.launchPower + 1, 1, LAUNCH_SPEEDS.length);
@@ -536,10 +525,14 @@ function handlePlayingInput(window: PinballWindow, event: InputEvent, frameId: n
window.launchPower = clamp(window.launchPower - 1, 1, LAUNCH_SPEEDS.length);
}
break;
case "ring-press":
flip(window, window.flippers[0]!);
flip(window, window.flippers[1]!);
break;
case "click":
if (ready) {
launchBall(window);
} else {
} else if (event.source !== "ring") {
flip(window, window.flippers[0]!);
flip(window, window.flippers[1]!);
}
@@ -616,10 +609,9 @@ function launchBall(window: PinballWindow): void {
}
function flip(window: PinballWindow, flipper: Flipper): void {
if (flipper.state === "hold") {
flipper.holdUntilMs = Date.now() + FLIPPER_HOLD_MS;
return;
}
// Time the pulse from the input, including the rise animation.
flipper.holdUntilMs = Date.now() + FLIPPER_HOLD_MS;
if (flipper.state === "hold") return;
flipper.state = "rising";
playSfx(window, SFX_FLIPPER, true);
}
@@ -725,7 +717,7 @@ function stepFlippers(window: PinballWindow, dt: number): void {
if (flipper.angleDeg <= FLIPPER_UP_DEG) {
flipper.angleDeg = FLIPPER_UP_DEG;
flipper.state = "hold";
flipper.holdUntilMs = now + FLIPPER_HOLD_MS;
if (now >= flipper.holdUntilMs) flipper.state = "falling";
}
break;
case "hold":
@@ -1013,7 +1005,7 @@ function paintPanel(image: GrayImage, window: PinballWindow): void {
image.drawText(smallFont, PANEL_X, 216, `${GESTURE_SCROLL} power ${GESTURE_CLICK} launch`, 115);
image.drawText(smallFont, PANEL_X, 236, `${GESTURE_DOUBLE_CLICK} pause`, 115);
} else {
image.drawText(smallFont, PANEL_X, 216, `${GESTURE_CLICK} flip ${GESTURE_SCROLL} L/R flip`, 115);
image.drawText(smallFont, PANEL_X, 216, "Touch ring: both flippers", 115);
image.drawText(smallFont, PANEL_X, 236, `${GESTURE_DOUBLE_CLICK} pause`, 115);
}
}
+3
View File
@@ -77,6 +77,8 @@ export const OsEventTypeList = {
* this eventType; the glance host treats it as a press.
*/
HEAD_UP_EVENT: 12,
/** Faceclaw/18: R1 touch-down, before click/hold/slide recognition. */
RING_PRESS_EVENT: 14,
} as const;
export const OsEventTypeName: Record<number, string> = {
@@ -93,4 +95,5 @@ export const OsEventTypeName: Record<number, string> = {
10: "RING_LONG_PRESS_RELEASE_EVENT",
11: "SHORT_THEN_LONG_PRESS_EVENT",
12: "HEAD_UP_EVENT",
14: "RING_PRESS_EVENT",
};
+5 -5
View File
@@ -1,7 +1,7 @@
/**
* Builds the Faceclaw custom firmware on-device: downloads the stock Even
* Realities G2 image the patch set was built against (CFW_PATCH_SET.base,
* currently 2.2.9.22) from Even's CDN, verifies its SHA-256, applies
* currently 2.3.0.24) from Even's CDN, verifies its SHA-256, applies
* the committed byte-patch set (cfw-patches.ts), extracts the stock EvenHub
* fonts for phone-side rendering, verifies the patched SHA-256, and writes the
* result to app storage.
@@ -28,10 +28,10 @@ import { firmwareSha256, writeFirmwareFile } from "../native/firmware-files";
// The CDN names firmware files by MD5. This must be the image whose SHA-256 is
// CFW_PATCH_SET.baseSha256 — keep it in sync with FW_URL in g2flash/build_cfw.sh
// whenever cfw-patches.ts is regenerated against a new stock base.
// (2.2.9.22 = fc250b05…; the older 2.2.6.10 base was e2873843….)
const FIRMWARE_URL = "https://cdn.evenreal.co/firmware/fc250b05e98a9ff998b4b68f5f99f994.bin";
// Output names follow the patch set's base name (e.g. g2_2.2.9.22.bin →
// g2_2.2.9.22_cfw.bin) so a rebase can't leave stale version numbers here.
// (2.3.0.24 = 1dbdf37b…; the older 2.2.9.22 base was fc250b05….)
const FIRMWARE_URL = "https://cdn.evenreal.co/firmware/1dbdf37b03a1169c384945e94d671371.bin";
// Output names follow the patch set's base name (e.g. g2_2.3.0.24.bin →
// g2_2.3.0.24_cfw.bin) so a rebase can't leave stale version numbers here.
const STOCK_OUTPUT_FILENAME = CFW_PATCH_SET.base;
const CFW_OUTPUT_FILENAME = CFW_PATCH_SET.base.replace(/\.bin$/, "") + "_cfw.bin";
+2 -2
View File
@@ -26,7 +26,7 @@ export type FirmwareInfo = {
};
/** The Faceclaw firmware revision this build of the app needs. */
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 13;
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 18;
const FACECLAW_PREFIX = "Faceclaw/";
const LEGACY_PREFIX = "EVENCFW";
@@ -34,7 +34,7 @@ const LEGACY_PREFIX = "EVENCFW";
// The stock firmware release Faceclaw's custom image is built from. Stock at or
// below this can be flashed with our patched image; a newer stock version is
// unrecognized (its layout may differ from what our patch set targets).
export const BASE_STOCK_VERSION = [2, 2, 9, 22];
export const BASE_STOCK_VERSION = [2, 3, 0, 24];
export const BASE_STOCK_VERSION_TEXT = BASE_STOCK_VERSION.join(".");
export const VALIDATED_STOCK_VERSION = [2, 3, 0, 24];
export const VALIDATED_STOCK_VERSION_TEXT = VALIDATED_STOCK_VERSION.join(".");
+4 -3
View File
@@ -25,12 +25,13 @@ type FontSpec = {
// is built against (CFW_PATCH_SET.base), so they move on every firmware
// rebase: run scripts/find-firmware-fonts.py against the new stock .bin and
// match rows by cmap count / code-point count (12/8081, 9/9566, 4/11590).
// 2.3.0.24: 0x007b699c, 0x007b69b0, 0x007b68c0
// 2.2.9.22: 0x007a8954, 0x007a8968, 0x007a8878
// 2.2.6.10: 0x0077f414, 0x0077f428, 0x0077f374
const FONT_SPECS: FontSpec[] = [
{ descriptor: 0x007a8954, lineHeight: 27, baseLine: 5 },
{ descriptor: 0x007a8968, lineHeight: 26, baseLine: 5 },
{ descriptor: 0x007a8878, lineHeight: 20, baseLine: 2 },
{ descriptor: 0x007b699c, lineHeight: 27, baseLine: 5 },
{ descriptor: 0x007b69b0, lineHeight: 26, baseLine: 5 },
{ descriptor: 0x007b68c0, lineHeight: 20, baseLine: 2 },
];
type ExtractedGlyph = {
+107 -107
View File
@@ -1,6 +1,6 @@
// AUTO-GENERATED from g2flash/patches/cfw_patches.json — do not edit by hand.
// Regenerate with scripts/update_deltas.sh.
// Turns the stock G2 2.2.9.22 image into the Faceclaw custom firmware.
// Turns the stock G2 2.3.0.24 image into the Faceclaw custom firmware.
export type FirmwarePatchOp = {
offset: number;
@@ -17,230 +17,230 @@ export type FirmwarePatchSet = {
};
export const CFW_PATCH_SET: FirmwarePatchSet = {
"base": "g2_2.2.9.22.bin",
"baseSha256": "a03fbea9f68a9de6bc271daabb9f3a41c59053d1086622c76a4e990f829cc561",
"outputSha256": "b856094899d7da6e2e4446a2c11fb3f026cecfa9f8e1a4f05e61f607a63994ad",
"base": "g2_2.3.0.24.bin",
"baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979",
"outputSha256": "71e02f9f184951080efe1b4baea3f3d23bde4b7132025535e9cd14c7d74b15fc",
"patches": [
{
"offset": 1422112,
"offset": 1437929,
"old": "15e0",
"new": "fae7",
"desc": "route ANCS write completions through relay event hook"
},
{
"offset": 1422106,
"old": "fff7cefa",
"new": "f0f246fb",
"offset": 1437923,
"old": "fef788ff",
"new": "fbf23afc",
"desc": "cfw_ancs_event"
},
{
"offset": 1422134,
"old": "fef770ff",
"new": "f0f286f8",
"offset": 1437951,
"old": "fef7e8fb",
"new": "fbf274f9",
"desc": "cfw_ancs_open"
},
{
"offset": 1422152,
"old": "fef76fff",
"new": "f0f29df8",
"offset": 1437969,
"old": "fef7e7fb",
"new": "fbf28bf9",
"desc": "cfw_ancs_close"
},
{
"offset": 1376122,
"old": "51334d00",
"new": "c1507c00",
"offset": 1388387,
"old": "39694d00",
"new": "5d407d00",
"desc": "connection-bound ANCS EUS write callback"
},
{
"offset": 935280,
"offset": 971497,
"old": "fff717f8",
"new": "64f37dfd",
"new": "6af3bdfe",
"desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)"
},
{
"offset": 935628,
"offset": 971845,
"old": "fef769ff",
"new": "64f3cffc",
"new": "6af30ffe",
"desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)"
},
{
"offset": 943818,
"old": "fcf76aff",
"new": "62f3d0fc",
"offset": 979579,
"old": "fdf74ef8",
"new": "68f3f4fe",
"desc": "bl cfw_message_bridge_received (ordered private bridge delivery before worker pool)"
},
{
"offset": 1415004,
"old": "fcf745f8",
"new": "eef2d5fc",
"offset": 1428895,
"old": "f8f76cfd",
"new": "faf2b0f9",
"desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)"
},
{
"offset": 1363762,
"offset": 1376071,
"old": "7c20",
"new": "7d20",
"desc": "Set Local Feature: enable LE 2M bit 8"
},
{
"offset": 4410298,
"offset": 4468651,
"old": "0c001800",
"new": "06000600",
"desc": "fast connection interval min=max=7.5 ms; latency remains 0"
},
{
"offset": 1053266,
"offset": 1057215,
"old": "0500",
"new": "a325",
"desc": "_connectParamReq_impl: force requested mode to fast (0xa3); disables idle slow requests"
},
{
"offset": 1124178,
"offset": 1130227,
"old": "5ff43432",
"new": "5ff43332",
"desc": "reserve final 1 KiB of primary TLSF arena for CFW context anchor"
},
{
"offset": 1242342,
"old": "d4f790fb",
"new": "1af380fe",
"offset": 1248487,
"old": "d4f712fb",
"new": "28f368fa",
"desc": "bl settings_send_wrapper (append caps field 100)"
},
{
"offset": 1240038,
"old": "f5f710f9",
"new": "1bf304f8",
"offset": 1246183,
"old": "f5f7e2f8",
"new": "28f3ecfb",
"desc": "bl settings_decode_wrapper (Faceclaw lease field 101)"
},
{
"offset": 939336,
"old": "0bf02af9",
"new": "64f37bfa",
"desc": "bl faceclaw_display_start @ 0x45f146 (fail-open wake takeover)"
"offset": 975219,
"old": "02f083fc",
"new": "6af34efc",
"desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)"
},
{
"offset": 939528,
"old": "0bf0caf8",
"new": "64f3e9fa",
"desc": "bl faceclaw_display_start_headup @ 0x45f206 (fail-open wake takeover)"
"offset": 975411,
"old": "02f023fc",
"new": "6af3bcfc",
"desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)"
},
{
"offset": 939016,
"old": "10f096f8",
"new": "66f311f8",
"offset": 975103,
"old": "07f085fb",
"new": "6cf368f9",
"desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)"
},
{
"offset": 939036,
"old": "fff765fb",
"new": "64f3ebf9",
"desc": "bl faceclaw_idle_input_gate (idle tap/long/release -> field-102 events 2/3/4)"
"offset": 830549,
"old": "19f03efb",
"new": "8ff317fb",
"desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)"
},
{
"offset": 831036,
"old": "1df057fc",
"new": "80f3edf9",
"desc": "bl gesture_press (Faceclaw lease gates event 9 vs stock UI event 8)"
"offset": 830795,
"old": "1ff071ff",
"new": "8ff3d0fa",
"desc": "bl gesture_press (owned event 9 before stock menu gate)"
},
{
"offset": 831042,
"old": "24f023f9",
"new": "80f38efa",
"offset": 830887,
"old": "1ff043ff",
"new": "8ff3cafa",
"desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)"
},
{
"offset": 831800,
"old": "1df0d9fa",
"new": "80f373f8",
"desc": "bl gesture_release (source-qualified event 10 vs stock UI event 0x4a)"
"offset": 831763,
"old": "1ff08dfd",
"new": "8ff300f9",
"desc": "bl gesture_release (owned event 10 before stock menu gate)"
},
{
"offset": 1553752,
"offset": 1570209,
"old": "7fb50600",
"new": "cef235be",
"new": "d9f2f9bd",
"desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline"
},
{
"offset": 1047796,
"old": "f6f7edff",
"new": "45f377fe",
"desc": "bl display_copy_hook @ 0x4798f2 (640x480 direct framebuffer)"
"offset": 1051545,
"old": "f6f787f9",
"new": "53f327ff",
"desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)"
},
{
"offset": 1048112,
"old": "f6f74fff",
"new": "45f3d9fd",
"desc": "bl display_copy_hook @ 0x479a2e (640x480 direct framebuffer)"
"offset": 1051861,
"old": "f6f7e9f8",
"new": "53f389fe",
"desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)"
},
{
"offset": 1255404,
"old": "d9f758ff",
"new": "17f307f8",
"desc": "bl faceclaw_send_wear_event @ 0x4ac3ea (outside onboarding)"
"offset": 1262237,
"old": "d9f7d0fd",
"new": "24f397fa",
"desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)"
},
{
"offset": 1255504,
"old": "d9f726ff",
"new": "16f3d5ff",
"desc": "bl faceclaw_send_wear_event @ 0x4ac44e (outside onboarding)"
"offset": 1262337,
"old": "d9f79efd",
"new": "24f365fa",
"desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)"
},
{
"offset": 1297700,
"old": "65f0affd",
"new": "0cf35ffa",
"offset": 1309405,
"old": "67f02dff",
"new": "18f37ffb",
"desc": "bl compass_decode_capture (sample-matched GAF diagnostics)"
},
{
"offset": 1296176,
"old": "fff759fc",
"new": "0cf3d5fd",
"offset": 1307865,
"old": "fff7c9fb",
"new": "18f3fdfe",
"desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)"
},
{
"offset": 1290360,
"offset": 1300937,
"old": "00210170",
"new": "0ef38ff8",
"new": "1af3e3fb",
"desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)"
},
{
"offset": 4476518,
"offset": 4537963,
"old": "",
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fa5b04ef66c6b4ff2a84416460d46ccf2ff0bc2f229044ff6ff7900274ff00108019006e048f2c731c0f24501bff32f8f8847d4f800a0bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0d7804ff4397005f07dfa002800f0f3824ff61c51cff6ff7142184a3182f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d737ff468afc0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001f51457ff41bafbff35f8f00bf44e8000121b154e8001f5145f8d00fe7aa4645ea064100260127c0f8701206e048f2c731c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0d6804ff4397005f086f9002800f0fc814ff61c51cff6ff7100bf42184a3182f8e46282f8e56282f8e66282f8e76282f8e86282f8e96282f8ea6282f8eb6282f8ec6282f8ed6282f8ee6282f8ef6282f8f06282f8f16282f8f26282f8f36282f8f46282f8f56282f8f66282f8f76282f8f86282f8f96282f8fa6282f8fb6282f8fc6282f8fd6282f8fe6282f8ff6282f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382f8196382f81a6382f81b6382f81c6382f81d6382f81e6382f81f6382f8206382f8216382f8226382f8236382f8246382f8256382f8266382f8276382f8286382f8296382f82a6382f82b6382f82c6382f82d637ff468afc0f800b08772a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff41cafbff35f8f44e8000121b154e8001fa942f8d011e7d0f8746242f6f767c0f24407002ebff35f8f00f0078107f19a0230464ff0ff314ff0ff379047002840f05d8143f67750c0f24f00804700274ff001080397adf8107006e048f2c731c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0fd804ff4397005f076f8002800f0f5804ff61c51cff6ff7100bf42184a3182f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d737ff468afc0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff41bafbff35f8f00bf44e8000149b354e8001fa942f8d00fe705460020b847b0b105f51d7151e8006f4eb9bff35f8f00bf41e8000292b151e8006f002ef8d00021bff32f8fbff35f8f21b10646dde64ff0ff3742e007f5a9718847d6e60121f1e70020019d42f6f764002d4ff0010bc0f2440418bfbaf1000f33d10df108098046484602f08ffa03ab28465146012206f097fa9df8111007464846002918bf4ff0ff3702f0cffbbbf1000f044608d19df8100028b949f28340c0f247004c308047b8f1000f18bfc8f80c4042f6f764c0f2440404f5807130468847384625b0bde8f08f2a7802f07f01a1f1150313f1030f0bd802f07b030b2b07d002f07e02082a03d0032901d00629b7d140b149f28341c0f247010746884797f8641111b14ff0ff37d6e738464ff0000ba6e72de9f04f81b04ef66c6b4ff2a8454ff61c5848f2c73accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0c6804ff4397004f0e7fe002800f0be80414600bf42184a3182f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f801738Line truncated
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf2de9f04fa5b04ef66c6b4ff29c5416460d46ccf2ff0bc2f229044ff6ff7900274ff00108019006e048f2a351c0f24501bff32f8f8847d4f800a0bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0d7804ff4397005f063fa002800f0f3824ff61c51cff6ff7142184a3182f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d737ff468afc0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001f51457ff41bafbff35f8f00bf44e8000121b154e8001f5145f8d00fe7aa4645ea064100260127c0f8701206e048f2a351c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0d6804ff4397005f06cf9002800f0fc814ff61c51cff6ff7100bf42184a3182f8e46282f8e56282f8e66282f8e76282f8e86282f8e96282f8ea6282f8eb6282f8ec6282f8ed6282f8ee6282f8ef6282f8f06282f8f16282f8f26282f8f36282f8f46282f8f56282f8f66282f8f76282f8f86282f8f96282f8fa6282f8fb6282f8fc6282f8fd6282f8fe6282f8ff6282f8006382f8016382f8026382f8036382f8046382f8056382f8066382f8076382f8086382f8096382f80a6382f80b6382f80c6382f80d6382f80e6382f80f6382f8106382f8116382f8126382f8136382f8146382f8156382f8166382f8176382f8186382f8196382f81a6382f81b6382f81c6382f81d6382f81e6382f81f6382f8206382f8216382f8226382f8236382f8246382f8256382f8266382f8276382f8286382f8296382f82a6382f82b6382f82c6382f82d637ff468afc0f800b08772a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff41cafbff35f8f44e8000121b154e8001fa942f8d011e7d0f8746242f6f767c0f24407002ebff35f8f00f0078107f19a0230464ff0ff314ff0ff379047002840f05d8147f6df40c0f24f00804700274ff001080397adf8107006e048f2a351c0f24501bff32f8f88472568bff35f8f20680321cff680710140b1f1005fbff35f8f03d10168594500f0fd804ff4397005f05cf8002800f0f5804ff61c51cff6ff7100bf42184a3182f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f8017382f8027382f8037382f8047382f8057382f8067382f8077382f8087382f8097382f80a7382f80b7382f80c7382f80d7382f80e7382f80f7382f8107382f8117382f8127382f8137382f8147382f8157382f8167382f8177382f8187382f8197382f81a7382f81b7382f81c7382f81d7382f81e7382f81f7382f8207382f8217382f8227382f8237382f8247382f8257382f8267382f8277382f8287382f8297382f82a7382f82b7382f82c7382f82d737ff468afc0f800b080f80a80a0f81c90a0f81e90a0f82090a0f82290a0f82490a0f82690a0f82890a0f82a90a0f82c90a0f82e90a0f83090a0f83290a0f83490a0f83690a0f83890a0f83a9054e8001fa9427ff41bafbff35f8f00bf44e8000149b354e8001fa942f8d00fe705460020b847b0b105f51d7151e8006f4eb9bff35f8f00bf41e8000292b151e8006f002ef8d00021bff32f8fbff35f8f21b10646dde64ff0ff3742e007f5a9718847d6e60121f1e70020019d42f6f764002d4ff0010bc0f2440418bfbaf1000f33d10df108098046484602f089fa03ab28465146012206f06bfa9df8111007464846002918bf4ff0ff3702f0c9fbbbf1000f044608d19df8100028b94af21f30c0f247004c308047b8f1000f18bfc8f80c4042f6f764c0f2440404f5807130468847384625b0bde8f08f2a7802f07f01a1f1150313f1030f0bd802f07b030b2b07d002f07e02082a03d0032901d00629b7d140b14af21f31c0f247010746884797f8641111b14ff0ff37d6e738464ff0000ba6e72de9f04f81b04ef66c6b4ff29c554ff61c5848f2a35accf2ff0bc2f229054ff6ff76cff6ff7800274ff00109c0f2450a03e000bfbff32f8fd0472c68bff35f8f2868bff35f8f01466ff39601b1f1005f03d10168594500f0c6804ff4397004f0cdfe002800f0be80414600bf42184a3182f8e47282f8e57282f8e67282f8e77282f8e87282f8e97282f8ea7282f8eb7282f8ec7282f8ed7282f8ee7282f8ef7282f8f07282f8f17282f8f27282f8f37282f8f47282f8f57282f8f67282f8f77282f8f87282f8f97282f8fa7282f8fb7282f8fc7282f8fd7282f8fe7282f8ff7282f8007382f801738Line truncated
"desc": "append injected blobs to main-app payload"
},
{
"offset": 779114,
"old": "846a3800",
"new": "d8293900",
"offset": 779123,
"old": "805a3900",
"new": "80193a00",
"desc": "main-app subheader payload size (ps)"
},
{
"offset": 152,
"old": "046b3800",
"new": "582a3900",
"old": "005b3900",
"new": "001a3a00",
"desc": "main-app TOC entry size (ps + 128)"
},
{
"offset": 779234,
"old": "846a3804",
"new": "d8293904",
"offset": 779243,
"old": "805a3904",
"new": "80193a04",
"desc": "main-app preamble length (low 24 bits)"
},
{
"offset": 779238,
"old": "85c355a2",
"new": "c485abc8",
"offset": 779247,
"old": "effdbcea",
"new": "30750afb",
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
},
{
"offset": 156,
"old": "ed292ee4",
"new": "c48d32fe",
"old": "c0c6322a",
"new": "067916a3",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
},
{
"offset": 779118,
"old": "ed292ee4",
"new": "c48d32fe",
"offset": 779127,
"old": "c0c6322a",
"new": "067916a3",
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
}
]
+2
View File
@@ -18,6 +18,8 @@ export type BaseInputEvent = {
/** The per-type part of InputEvent; makeInputEvent adds the BaseInputEvent fields. */
export type InputEventPayload =
/** Raw ring touch-down; a later interpreted gesture may follow. */
| { type: "ring-press"; source: "ring" }
| { type: "click"; source: InputSource }
| { type: "double-click"; source: InputSource }
/** Ring scroll (or a watch crown turn, then tagged source "watch"). */
+55
View File
@@ -0,0 +1,55 @@
import type { InputEvent } from "./gestures";
type InputListener = (event: Readonly<InputEvent>) => void;
const listeners = new Set<InputListener>();
/** Observe input before shell routing consumes menu, hold, or back gestures. */
export function addInputListener(listener: InputListener): () => void {
listeners.add(listener);
return () => { listeners.delete(listener); };
}
export function notifyInputListeners(event: InputEvent): void {
if (!listeners.size) return;
const snapshot = Object.freeze({ ...event });
for (const listener of listeners) {
try { listener(snapshot); }
catch (error) { console.warn("Input observer failed", error); }
}
}
export type InputLogEntry = {
event: Readonly<InputEvent>;
gapMs: number | null;
};
/** A bounded arrival-ordered history; equal timestamps must keep both events. */
export class InputEventLog {
readonly entries: InputLogEntry[] = [];
paused = false;
count = 0;
private previousMs: number | null = null;
add(event: Readonly<InputEvent>): void {
if (this.paused) return;
this.entries.unshift({
event: { ...event },
gapMs: this.previousMs === null ? null : event.timestampMs - this.previousMs,
});
this.previousMs = event.timestampMs;
this.count++;
if (this.entries.length > 200) this.entries.length = 200;
}
clear(): void {
this.entries.length = 0;
this.previousMs = null;
this.count = 0;
}
}
export function inputTimestamp(timestampMs: number): string {
const date = new Date(timestampMs);
const two = (n: number) => String(n).padStart(2, "0");
return `${two(date.getHours())}:${two(date.getMinutes())}:${two(date.getSeconds())}.${String(date.getMilliseconds()).padStart(3, "0")}`;
}
+21 -1
View File
@@ -2,6 +2,7 @@ import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { singlePlane, type Plane } from "../../graphics/plane";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { EvenAIStatus, EventSourceType, OsEventTypeList, WatchGestureType } from "../../g2/events";
import { notifyInputListeners } from "../input-monitor";
import type { RawInputEvent } from "../../native/faceclaw-communicator";
import {
directionalFallback,
@@ -708,6 +709,7 @@ class Shell {
}
async receiveInput(event: InputEvent, frameId = 0): Promise<ShellInputOutcome> {
notifyInputListeners(event);
try {
return await this.routeInput(event, frameId);
} finally {
@@ -718,6 +720,16 @@ class Shell {
}
private async routeInput(event: InputEvent, frameId: number): Promise<ShellInputOutcome> {
// Touch-down supplements gestures. It must not wake the screen, operate
// menus, or cancel the hold-to-escape timer. Apps can opt into it later.
if (event.type === "ring-press") {
const window = this.foregroundWindow();
if (this.screenOn && this.focus === "window" && this.stack.isAtBase() && window) {
await window.handleInput(event, frameId);
return { shell: false, window: true };
}
return { shell: false, window: false };
}
const previous = this.lastInput;
this.lastInput = event;
// A visible window may paint a source-dependent indicator (see
@@ -1545,7 +1557,13 @@ export function rawInputEventToInputEvent(event: RawInputEvent): InputEvent {
function rawInputEventToPayload(event: RawInputEvent): InputEventPayload {
if (event.kind === "sys-event") {
if (event.eventType === OsEventTypeList.CLICK_EVENT) {
if (event.eventType === OsEventTypeList.RING_PRESS_EVENT &&
(event.eventSource === EventSourceType.TOUCH_EVENT_FORM_DUMMY_NULL ||
event.eventSource === EventSourceType.TOUCH_EVENT_FROM_RING)) {
// The firmware emits this dedicated ID only for full raw source 4.
// Its stock sender leaves the source unspecified for extension 14.
return { type: "ring-press", source: "ring" };
} else if (event.eventType === OsEventTypeList.CLICK_EVENT) {
return {
type: "click",
source: eventSourceToString(event.eventSource),
@@ -1627,6 +1645,8 @@ function eventSourceToString(eventSource: number): InputSource {
export function inputEventToString(event: InputEvent): string {
switch (event.type) {
case "ring-press":
return "Ring press";
case "click":
return `Click from ${event.source}`;
case "double-click":
+1
View File
@@ -250,6 +250,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
const { shell, rawInputEventToInputEvent } = load('app/ui/shell/shell.ts', {
'../../graphics/image': images, '../../graphics/plane': {}, '../../graphics/ui-fonts': {}, '../../g2/events': load('app/g2/events.ts', {}),
'../gestures': gestures, '../layers': layers, '../menu': { MenuLayer: Menu },
'../input-monitor': load('app/ui/input-monitor.ts', {}),
'./voice-input': { VoiceInputLayer: class {
constructor(options) { this.options = options; voiceDialogs.push(options); }
startCapture() {}
+3 -3
View File
@@ -62,9 +62,9 @@ test("stock firmware classifies by base version and warns on the main screen", (
assert.equal(compat.classifyOnboardingFirmware(info("", "", "")).kind, "unknown");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.2.9.22", "2.2.9.22")).kind, "flashable-stock");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.2.4.34", "")).kind, "flashable-stock");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.2.10.10", "2.2.10.10")).kind, "newer-stock-validated");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.3.0.1", "2.3.0.1")).kind, "newer-stock-validated");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.3.0.24", "2.3.0.24")).kind, "newer-stock-validated");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.2.10.10", "2.2.10.10")).kind, "flashable-stock");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.3.0.1", "2.3.0.1")).kind, "flashable-stock");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.3.0.24", "2.3.0.24")).kind, "flashable-stock");
assert.equal(compat.classifyOnboardingFirmware(info("", "2.3.0.24", "2.3.0.25")).kind, "newer-stock-unvalidated");
// Faceclaw firmware on a newer base is still judged by its revision, not the base.
assert.equal(compat.classifyOnboardingFirmware(info(`Faceclaw/${REQUIRED}`, "2.3.0.1", "2.3.0.1")).kind, "custom");
+188
View File
@@ -0,0 +1,188 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const root = path.join(__dirname, '..');
function load(file, modules = {}, globals = {}, extra = '') {
const context = { exports: {}, console, ...globals, require(name) {
assert.ok(name in modules, `Unexpected dependency ${name}`); return modules[name];
} };
vm.runInNewContext(ts.transpileModule(fs.readFileSync(path.join(root, file), 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText + extra, context);
return context.exports;
}
const gestures = load('app/ui/gestures.ts');
const textwrap = load('app/graphics/textwrap.ts');
const graphics = load('app/graphics/image.ts', { './textwrap': textwrap });
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const font = size => BdfFont.parse(fs.readFileSync(path.join(root, `app/fonts/terminus/ter-u${size}n.bdf`), 'utf8'));
const fonts = { terminus24: font(24), terminus32: font(32) }, small = font(18);
function worker(game) {
let now = 10000, id = 0, renders = 0;
const timers = new Map(), posts = [];
const schedule = (fn, delay, repeat) => { timers.set(++id, { fn, at: now + delay, repeat }); return id; };
const cancel = id => timers.delete(id);
const global = { postMessage: m => posts.push(m) };
class Menu {
constructor(options) { this.options = options; this.opened = false; }
isOpen() { return this.opened; }
open() { this.opened = true; }
async handleInput(e) {
if (e.type === 'click') this.options.items()[0].onSelect({ stack: { pop: () => { this.opened = false; } } });
if (e.type === 'double-click' || e.type === 'system-menu-opened') this.opened = false;
}
}
const modules = {
'@nativescript/core/globals': {}, '../../graphics/image': graphics,
'../../graphics/plane': {}, '../../graphics/glyph-wire': {},
'../../graphics/bdffont': { getFont: name => fonts[name] },
'../../graphics/ui-fonts': { getDefaultSmallFont: () => small },
'../../native/frame-timings': { finishFrame() {}, logFrame() {} },
'../../native/active-display': {}, '../../native/worker-buzzer': {},
'../../native/settings-store': { getStringSetting: () => '0', setStringSetting() {} },
'../../ui/sound-effects': {}, '../../ui/sound-setting': { loadSoundEnabled: () => false, saveSoundEnabled() {} },
'../../ui/window-menu': { WindowMenu: Menu }, '../../ui/gestures': gestures,
'../../util/numeric-util': { clamp: (v, a, b) => Math.max(a, Math.min(b, v)) },
'./flappy-sprites': load('app/apps/flappy/flappy-sprites.ts', { '../../graphics/image': graphics }),
};
const extra = game === 'blocks' ? 'tick, hardDrop, idleDelayMs, dropIntervalMs, spawnPiece, windowMenu' :
game === 'pinball' ? 'stepFlippers, flip, launchBall, windowMenu' : 'flap, windowMenu';
const api = load(`app/apps/${game}/${game}-app.worker.ts`, modules, {
global, Date: { now: () => now },
setTimeout: (f, d) => schedule(f, d, 0), clearTimeout: cancel,
setInterval: (f, d) => schedule(f, d, d), clearInterval: cancel,
recordRender: () => renders++,
}, `\nrenderAndSubmit = () => recordRender(); playSfx = () => {};
exports.api = { windows, resetGame, paintContent, ${extra} };`).api;
const message = data => global.onmessage({ data });
message({ type: 'open-window', windowId: 'test', surfaceId: 'test', title: game, viewport: { width: 576, height: 288 } });
message({ type: 'foreground', windowId: 'test', foreground: true, focused: true });
const w = api.windows.get('test');
if (game === 'blocks') { w.pieceIndex = 2; w.pieceRotation = 0; w.pieceY = 0; w.pieceX = 3; }
function advance(ms) {
const end = now + ms;
for (;;) {
const next = [...timers].filter(([, t]) => t.at <= end).sort((a, b) => a[1].at - b[1].at || a[0] - b[0])[0];
if (!next) break;
const [key, t] = next; now = t.at;
if (t.repeat) t.at += t.repeat; else timers.delete(key);
t.fn();
}
now = end;
}
return { ...api, w, message, advance, posts, timers, now: () => now, renders: () => renders,
elapse: ms => { now += ms; }, input: (type, source = 'ring') => message({
type: 'input', windowId: 'test', focused: true, frameId: 1, event: { type, source, timestampMs: now },
}) };
}
for (const [sequence, rotations, x] of [
[['ring-press','click'],1,3], [['ring-press',300],1,3],
[['ring-press',300,'click'],1,3], [['ring-press','ring-press','double-click'],2,3],
[['ring-press','ring-press','ring-press','double-click'],3,3],
[['ring-press','scroll-up'],0,2], [['ring-press','scroll-down'],0,4],
[['ring-press','ring-press','ring-press','scroll-up'],2,2],
[['ring-press','scroll-up','click'],0,2], [['click','double-click'],0,3],
]) test(`Blocks: ${sequence.join(', ')} gives ${rotations} rotations`, () => {
const h = worker('blocks');
for (const step of sequence) typeof step === 'number' ? h.advance(step) : h.input(step);
h.advance(350);
assert.equal(h.w.pieceRotation, rotations); assert.equal(h.w.pieceX, x);
assert.equal(h.w.phase, 'playing'); assert.equal(h.w.pendingRotationTimer, null);
});
test('Blocks replaces only the last buffered press and expires at 300 ms', () => {
const h = worker('blocks'); h.input('ring-press'); h.advance(200); h.input('ring-press');
assert.equal(h.w.pieceRotation, 1); h.advance(299); assert.equal(h.w.pieceRotation, 1);
h.advance(1); assert.equal(h.w.pieceRotation, 2); h.input('double-click'); assert.equal(h.w.pieceRotation, 2);
});
test('Blocks a click from another source commits the pending rotation without duplicating it', () => {
const h = worker('blocks'); h.input('ring-press'); h.input('click', 'left-arm');
h.advance(300); assert.equal(h.w.pieceRotation, 1);
h.input('click', 'watch'); assert.equal(h.w.pieceRotation, 2);
});
test('Blocks idle acceleration starts at the deadline, runs at 5x, and ends on input', () => {
const h = worker('blocks'); h.advance(1000);
assert.equal(h.w.pieceY, 0);
const before = h.w.gravityProgress; h.advance(300);
assert.ok(Math.abs((h.w.pieceY + h.w.gravityProgress) - before - 1) < 1e-9);
h.input('scroll-down'); const afterInput = h.w.pieceY + h.w.gravityProgress;
h.advance(300);
assert.ok(Math.abs((h.w.pieceY + h.w.gravityProgress) - afterInput - 0.2) < 1e-9);
for (const [lines, expected] of [[0,1000],[10,950],[50,750],[100,500],[200,500]]) {
h.w.lines = lines; assert.equal(h.idleDelayMs(h.w), expected);
}
});
test('Blocks continuous input cannot reset gravity progress; timeout rotation is not fresh input', () => {
const h = worker('blocks');
for (let i = 0; i < 20; i++) { h.input(i % 2 ? 'scroll-up' : 'scroll-down'); h.advance(100); }
assert.equal(h.w.pieceY, 1);
h.input('ring-press'); const when = h.w.lastInputAtMs; h.advance(300);
assert.equal(h.w.lastInputAtMs, when);
});
test('Blocks landing resets acceleration and prevents a pending rotation from reaching the next piece', () => {
const h = worker('blocks'); h.advance(1100); h.input('ring-press');
h.hardDrop(h.w);
assert.equal(h.w.gravityProgress, 0); assert.equal(h.w.lastInputAtMs, h.now());
h.advance(300); assert.equal(h.w.pieceRotation, 0);
assert.equal(h.w.gravityProgress.toFixed(3), '0.200');
// Let a naturally falling piece land while accelerated, then inspect its successor.
h.w.pieceY = 17; h.w.board.fill(0);
while (h.w.pieceY >= 17) h.advance(20);
assert.equal(h.w.gravityProgress, 0); assert.equal(h.w.lastInputAtMs, h.now());
});
test('Blocks hold pauses without dropping, opens a menu, and resumes with a fresh idle delay', async () => {
const h = worker('blocks'); h.input('ring-press'); h.advance(100); h.input('long-press');
assert.equal(h.w.phase, 'paused'); assert.equal(h.w.pieceY, 0);
assert.ok(h.w.menu.isOpen()); assert.equal(h.w.menu.options.claimsLongPress(), false);
h.advance(5000); assert.equal(h.w.pieceRotation, 0); assert.equal(h.w.pieceY, 0);
h.input('click'); await Promise.resolve();
assert.equal(h.w.phase, 'playing'); assert.equal(h.w.lastInputAtMs, h.now());
assert.equal(h.w.menu.options.claimsLongPress(), true);
h.advance(500); assert.equal(h.w.pieceY, 0);
});
for (const event of [
{ type: 'input-focus', windowId: 'test', focused: false },
{ type: 'foreground', windowId: 'test', foreground: false, focused: false },
{ type: 'screen', on: false }, { type: 'close-window', windowId: 'test' },
]) test(`Blocks cancels buffered input and timers on ${event.type}`, () => {
const h = worker('blocks'); h.input('ring-press'); h.message(event); h.advance(2000);
assert.equal(h.w.pieceRotation, 0); assert.equal(h.timers.size, 0);
});
test('Flappy acts on down and ignores subsequent ring click/scroll; watch still flaps', () => {
const h = worker('flappy'); h.input('ring-press');
assert.equal(h.w.phase, 'playing'); assert.ok(h.w.birdVy < 0);
h.w.birdVy = 20; h.input('click'); h.input('scroll-up'); assert.equal(h.w.birdVy, 20);
h.input('swipe-up', 'watch'); assert.ok(h.w.birdVy < 0);
h.w.birdVy = 20; h.input('click', 'watch'); assert.ok(h.w.birdVy < 0);
});
test('Pinball pulses both flippers for 300 ms, extends on another press, and ignores click in play', () => {
const h = worker('pinball'); h.w.ballState = 'live'; h.input('ring-press');
assert.ok(h.w.flippers.every(f => f.state === 'rising' && f.holdUntilMs === h.now() + 300));
h.stepFlippers(h.w, 0.2); assert.ok(h.w.flippers.every(f => f.state === 'hold'));
h.elapse(200); h.input('click'); assert.ok(h.w.flippers.every(f => f.holdUntilMs === h.now() + 100));
h.input('ring-press'); h.elapse(299); h.stepFlippers(h.w, 0);
assert.ok(h.w.flippers.every(f => f.state === 'hold'));
h.elapse(1); h.stepFlippers(h.w, 0); assert.ok(h.w.flippers.every(f => f.state === 'falling'));
});
test('Pinball swipes no longer flip; plunger power and click launch remain', () => {
const h = worker('pinball'); h.w.ballState = 'live';
for (const type of ['scroll-up','scroll-down','swipe-left','swipe-right']) h.input(type);
assert.ok(h.w.flippers.every(f => f.state === 'rest'));
h.w.ballState = 'ready'; h.w.launchPower = 2;
h.input('scroll-up'); assert.equal(h.w.launchPower, 3);
h.input('scroll-down'); assert.equal(h.w.launchPower, 2);
h.input('click'); assert.equal(h.w.ballState, 'live');
});
+126
View File
@@ -0,0 +1,126 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const ts = require('typescript');
const read = (file) => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const js = (source) => ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
function load(file, modules = {}) {
const context = { exports: {}, console, require(name) {
assert.ok(name in modules, name); return modules[name];
} };
vm.runInNewContext(js(read(file)), context);
return context.exports;
}
const monitor = load('app/ui/input-monitor.ts');
const event = (type, timestampMs = 1000) => ({ type, source: 'ring', timestampMs });
function shellDeclarations() {
const source = ts.createSourceFile('shell.ts', read('app/ui/shell/shell.ts'), ts.ScriptTarget.Latest, true);
const names = new Set(['rawInputEventToPayload', 'eventSourceToString', 'scrollEvent']);
const declarations = source.statements.filter((s) => ts.isFunctionDeclaration(s) && names.has(s.name?.text));
assert.equal(declarations.length, names.size);
const shell = source.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === 'Shell');
const methods = shell.members.filter((s) => ['receiveInput', 'routeInput'].includes(s.name?.getText(source)));
const context = { exports: {}, notifyInputListeners: monitor.notifyInputListeners,
...load('app/g2/events.ts') };
vm.createContext(context);
vm.runInContext(js(declarations.map((s) => s.getText(source)).join('\n') +
'\nexport class Shell {\n' + methods.map((s) => s.getText(source)).join('\n') + '\n}'), context);
return context;
}
test('new SysEvent decodes independently of click, double-tap, hold and release', () => {
const d = shellDeclarations();
for (const source of [0, 2]) {
const decoded = d.rawInputEventToPayload({ kind: 'sys-event', eventType: 14, eventSource: source });
assert.equal(decoded.type, 'ring-press'); assert.equal(decoded.source, 'ring');
}
for (const source of [1, 3, 99, undefined]) {
assert.equal(d.rawInputEventToPayload({ kind: 'sys-event', eventType: 14, eventSource: source }).type, 'unknown');
}
for (const [id, type] of [[0,'click'],[3,'double-click'],[9,'long-press'],[10,'long-press-release'],[11,'short-then-long-press']]) {
assert.equal(d.rawInputEventToPayload({ kind: 'sys-event', eventType: id, eventSource: 2 }).type, type);
}
});
test('press is observed before routing and does not wake, operate shell menus or replace hold state', async () => {
const { exports: { Shell } } = shellDeclarations();
for (const screenOn of [true, false]) for (const focus of ['window', 'sidebar']) for (const atBase of [true, false]) {
const s = new Shell(), seen = [], delivered = [];
const unsubscribe = monitor.addInputListener((e) => seen.push(e));
Object.assign(s, { screenOn, focus, stack: { isAtBase: () => atBase },
foregroundWindow: () => ({ handleInput(e) { assert.equal(seen.length, 1); delivered.push(e); } }),
syncInputFocus() {}, lastInput: event('long-press'), lastInputAtMs: 123 });
try {
const result = await s.receiveInput(event('ring-press'));
assert.equal(result.shell, false);
assert.equal(delivered.length, Number(screenOn && focus === 'window' && atBase));
assert.equal(seen.length, 1);
assert.equal(s.lastInput.type, 'long-press'); assert.equal(s.lastInputAtMs, 123);
} finally { unsubscribe(); }
}
});
test('bounded history preserves equal-time events, snapshots and arrival gaps; pause and clear work', () => {
const log = new monitor.InputEventLog();
const first = event('ring-press'); log.add(first); first.type = 'unknown';
log.add(event('click')); log.add(event('double-click', 1250));
assert.equal(log.entries[2].event.type, 'ring-press');
assert.equal(log.entries[2].gapMs, null); assert.equal(log.entries[1].gapMs, 0);
assert.equal(log.entries[0].gapMs, 250);
log.paused = true; log.add(event('click')); assert.equal(log.count, 3);
log.paused = false;
for (let i = 0; i < 210; i++) log.add(event('click', 2000 + i));
assert.equal(log.entries.length, 200); assert.equal(log.count, 213);
log.clear(); log.add(event('ring-press')); assert.equal(log.count, 1); assert.equal(log.entries[0].gapMs, null);
assert.equal(monitor.inputTimestamp(new Date(2026, 0, 2, 3, 4, 5, 6).getTime()), '03:04:05.006');
});
test('Input events captures while visible, pauses for history, and unsubscribes on removal', () => {
const textwrap = load('app/graphics/textwrap.ts');
const graphics = load('app/graphics/image.ts', { './textwrap': textwrap });
const { BdfFont } = load('app/graphics/bdffont.ts', { '@nativescript/core': {} });
const font = BdfFont.parse(read('app/fonts/terminus/ter-u18n.bdf'));
class RecordingImage extends graphics.GrayImage {
texts = [];
drawText(font, x, y, text, value) {
this.texts.push({ x, y, text, width: font.measureText(text), height: font.lineHeight });
super.drawText(font, x, y, text, value);
}
}
const { InputEventsLayer } = load('app/apps/developer/input-events.ts', {
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font },
'../../graphics/image': { GrayImage: RecordingImage }, '../../graphics/textwrap': textwrap,
'../../ui/input-monitor': monitor, '../../ui/menu': { drawListScrollbar() {} },
});
let visible = true, renders = 0, removed = 0, pops = 0;
const layer = new InputEventsLayer(() => renders++, () => visible, () => removed++);
const ctx = { stack: { getBaseSize: () => ({ width: 576, height: 260 }),
pop: () => pops++, popThrough: (page) => { assert.equal(page, layer); page.onRemoved(); } } };
try {
for (const type of ['ring-press','click','ring-press','ring-press','double-click','long-press','long-press-release','short-then-long-press']) {
const e = event(type, 1000 + renders * 75); monitor.notifyInputListeners(e); layer.handleInput(e);
}
assert.equal(renders, 8); assert.equal(layer.log.count, 8); assert.equal(pops, 0);
visible = false; monitor.notifyInputListeners(event('click')); assert.equal(renders, 8); visible = true;
const image = layer.paint(ctx);
for (const text of image.texts) {
assert.ok(text.x >= 0 && text.x + text.width <= image.width, text.text);
assert.ok(text.y >= 0 && text.y + text.height <= image.height, text.text);
}
if (process.env.INPUT_EVENTS_PREVIEW) fs.writeFileSync(process.env.INPUT_EVENTS_PREVIEW, Buffer.concat([
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
]));
layer.menuItems()[0].onSelect(ctx); monitor.notifyInputListeners(event('click'));
assert.equal(layer.log.count, 8); assert.equal(layer.menuItems()[0].label, 'Resume capture');
layer.menuItems()[1].onSelect(ctx); assert.equal(layer.log.count, 0);
layer.menuItems()[0].onSelect(ctx); monitor.notifyInputListeners(event('ring-press'));
assert.equal(layer.log.count, 1);
layer.menuItems()[2].onSelect(ctx); monitor.notifyInputListeners(event('click'));
assert.equal(removed, 1); assert.equal(layer.log.count, 1);
} finally { layer.onRemoved(); }
});
+10 -3
View File
@@ -92,6 +92,12 @@ test('ring and arm input decoders preserve gesture and source', () => {
assert.equal(wake.kind, 'display-wake');
assert.equal(wake.eventType, 12);
assert.equal(wake.eventSource, 1);
// The stock G2 sender omits source for dedicated Faceclaw event 14.
const press = p.decodeGlassesInput({ sid: 224, flag: 1,
payload: p.bytes(13, p.bytes(3, p.integer(1, 14))) });
assert.equal(press.kind, 'sys-event');
assert.equal(press.eventType, 14);
assert.equal(press.eventSource, 0);
});
class FakeTransport {
@@ -605,7 +611,7 @@ test('wear notifications validate the event and peer and work during initial con
test('ANCS packets are scoped to the right link and cleared on disconnect and authorization revocation', async t => {
const transport = new FakeTransport(); transport.firmware = 16;
const transport = new FakeTransport(); transport.firmware = REQUIRED_FACECLAW_FIRMWARE_VERSION;
const h = harness(t, transport); await h.session.start(addresses);
await until(() => transport.ancs?.length);
const token = Array.from(transport.ancs[0].frame.subarray(4,8));
@@ -624,12 +630,13 @@ test('firmware 15 requires an upgrade before starting notification relay', async
const transport = new FakeTransport(); transport.firmware = 15;
const h = harness(t, transport); await h.session.start(addresses);
assert.equal(h.session.notifications.state, 'disconnected');
assert.match(h.session.notifications.statusMessage, /firmware 16 or newer/);
assert.equal(h.session.state.phase, 'error');
assert.match(h.session.state.status, new RegExp(`requires revision ${REQUIRED_FACECLAW_FIRMWARE_VERSION}`));
assert.equal(transport.ancs?.length ?? 0, 0);
});
test('ANCS app-name lookup uses the right-link write limit, including after reauthorization', async t => {
const transport = new FakeTransport(); transport.firmware = 16;
const transport = new FakeTransport(); transport.firmware = REQUIRED_FACECLAW_FIRMWARE_VERSION;
const h = harness(t, transport); await h.session.start(addresses);
await until(() => transport.ancs?.length);
const id = 'net.superblock.Pushover';
+5 -1
View File
@@ -109,7 +109,11 @@ test('pinned stock firmware reproduces the custom image, extracts fonts, and pas
'@nativescript/core': { File: { exists: fs.existsSync, fromPath: file => ({ readTextSync: () => fs.readFileSync(file, 'utf8') }) },
knownFolders: { documents: () => ({ path: temp, getFile: name => ({ writeTextSync: text => fs.writeFileSync(path.join(temp, name), text) }) }) } },
'./firmware/cfw-patches': patches, './firmware-fonts': fonts,
'../util/http': { fetchWithUserAgent: async () => ({ ok: true, arrayBuffer: async () => Uint8Array.from(base).buffer }) },
'../util/http': { fetchWithUserAgent: async (url) => {
const md5 = crypto.createHash('md5').update(base).digest('hex');
assert.equal(url, `https://cdn.evenreal.co/firmware/${md5}.bin`);
return { ok: true, arrayBuffer: async () => Uint8Array.from(base).buffer };
} },
'../util/hex-util': require('../.test-build/app/util/hex-util.js'), '../graphics/evenhub-font': { EvenHubFont: { invalidate() {} } },
'../native/firmware-files': { firmwareSha256: hash, writeFirmwareFile: (file, buffer) => fs.writeFileSync(file, new Uint8Array(buffer)) },
});
+122
View File
@@ -0,0 +1,122 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { loader } = require('./helpers/load-typescript.cjs');
function fixture({ ios = false, connected = true } = {}) {
const messages = [], frames = [], sounds = [], errors = [], timers = new Set(), settings = new Map();
const global = { isIOS: ios, isAndroid: !ios, postMessage: message => messages.push(message) };
const timings = {
startFrame: () => 1, finishFrame() {}, logFrame() {},
span: (_id, _name, fn) => fn(), runWithFrame: (_id, fn) => fn(), spanCurrent: (_name, fn) => fn(),
};
const mocks = {
'@nativescript/core': {}, '@nativescript/core/globals': {},
'../../native/frame-timings': timings, '../native/frame-timings': timings,
'../../native/settings-store': {
getBooleanSetting: (key, fallback) => settings.get(key) ?? fallback,
setBooleanSetting: (key, value) => settings.set(key, value),
},
};
mocks['../native/settings-store'] = mocks['../../native/settings-store'];
const display = { submitSurfaceFrame: (...args) => frames.push(args) };
let active = connected;
const load = loader({
global, setInterval: fn => { timers.add(fn); return fn; }, clearInterval: fn => timers.delete(fn),
console: { log() {}, warn: error => errors.push(error), error: error => errors.push(error) },
com: { faceclaw: { app: {
FaceclawBleCommunicator: { getActive: () => active ? {
...display, playBuzzerSequence: payload => sounds.push(payload),
} : null },
FaceclawPreviewCompositor: { getActive: () => display },
} } },
NSData: { dataWithBytesLength: buffer => ({ base64EncodedStringWithOptions: () => Buffer.from(buffer).toString('base64') }) },
interop: { handleof: buffer => buffer },
}, mocks);
const { BdfFont } = load('app/graphics/bdffont.ts');
const font = size => BdfFont.parse(fs.readFileSync(path.join(__dirname, `../app/fonts/terminus/ter-u${size}n.bdf`), 'utf8'));
const small = font(12), medium = font(24);
mocks['../../graphics/bdffont'] = { getFont: () => medium };
mocks['../../graphics/ui-fonts'] = mocks['../graphics/ui-fonts'] = { getDefaultSmallFont: () => small };
// Exercise the real iOS transport and Android preview selection. The atlas
// boundary is stubbed; text baking and plane composition remain production code.
mocks['../../graphics/glyph-wire'] = { prepareFrameDraws: () => null };
if (ios) mocks['../../native/active-display'] = load('app/native/active-display.ios.ts');
load('app/apps/paperclips/paperclips-app.worker.ts');
const send = data => global.onmessage({ data });
const input = type => send({ type: 'input', windowId: 'paperclips:main', focused: true, frameId: 1,
event: { type, source: 'ring', timestampMs: 1 } });
const open = () => {
send({ type: 'open-window', windowId: 'paperclips:main', surfaceId: 'window:paperclips:main',
title: 'Paperclips', viewport: { width: 576, height: 260 } });
send({ type: 'foreground', windowId: 'paperclips:main', foreground: true, focused: true });
};
const pixels = () => ios ? Buffer.from(messages.filter(m => m.type === 'surface-frame').at(-1).pixels, 'base64')
: Buffer.from(frames.at(-1)[0]);
return { messages, frames, sounds, errors, timers, settings, send, input, open, pixels,
disconnect: () => { active = false; } };
}
const flush = () => new Promise(resolve => setImmediate(resolve));
for (const ios of [false, true]) {
test(`Paperclips starts, renders text and plays sound through the ${ios ? 'iOS' : 'Android'} bridge`, () => {
const h = fixture({ ios });
assert.equal(h.messages[0].type, 'worker-ready');
h.open();
assert.equal(h.timers.size, 1);
assert.equal(h.pixels().length, 576 * 260);
assert.ok(h.pixels().some(value => value > 0));
const first = h.pixels();
h.input('click');
assert.notDeepEqual(h.pixels(), first);
h.input('long-press');
assert.equal(h.timers.size, 0);
assert.ok(ios ? h.messages.some(m => m.type === 'buzzer-sequence' && m.payload.length) : h.sounds.length);
const gestures = h.messages.filter(m => m.type === 'set-window-gestures');
assert.equal(gestures[0].claimsLongPress, true);
assert.equal(gestures.at(-1).claimsLongPress, false);
// The gap between the pause title and hints must occlude the deferred
// game labels below, rather than letting them draw over the modal.
const pixels = h.pixels();
for (let y = 124; y < 136; y++) {
assert.ok(pixels.subarray(y * 576 + 132, y * 576 + 444).every(value => value === 0));
}
h.input('click');
assert.equal(h.timers.size, 1);
h.send({ type: 'close-window', windowId: 'paperclips:main' });
assert.equal(h.timers.size, 0);
assert.deepEqual(h.errors, []);
});
}
test('Paperclips uses the disconnected preview and suppresses duplicate frames', () => {
const h = fixture({ connected: false });
h.open();
assert.equal(h.frames.length, 1);
h.send({ type: 'render', windowId: 'paperclips:main', focused: true });
assert.equal(h.frames.length, 1);
h.input('click');
assert.equal(h.frames.length, 2);
assert.deepEqual(h.errors, []);
});
test('Paperclips pauses for focus loss and its current context menu resumes and saves sound settings', async () => {
const h = fixture(); h.open();
h.send({ type: 'input-focus', windowId: 'paperclips:main', focused: false });
assert.equal(h.timers.size, 0);
h.input('short-then-long-press');
h.input('click'); await flush(); // Resume
assert.equal(h.timers.size, 1);
h.input('short-then-long-press');
assert.equal(h.timers.size, 0);
for (let i = 0; i < 3; i++) { h.input('scroll-down'); await flush(); }
h.input('click'); await flush(); // Sound: off
assert.equal(h.settings.get('paperclips.soundOn'), false);
const sounds = h.sounds.length;
h.input('click'); // Resume without sound
assert.equal(h.sounds.length, sounds);
h.send({ type: 'screen', on: false });
assert.equal(h.timers.size, 0);
assert.deepEqual(h.errors, []);
});
+2 -2
View File
@@ -96,7 +96,7 @@ test('pinball responds on contact, holds independently, and releases before tap'
assert.equal(h.w.flippers[1].state, 'falling');
});
test('pinball retains old firmware/ring controls and plunger click launch', () => {
test('pinball uses ring press for flippers and retains plunger click launch', () => {
const h = worker();
h.input('click');
assert.ok(h.w.flippers.every((f) => f.state === 'rising'));
@@ -106,7 +106,7 @@ test('pinball retains old firmware/ring controls and plunger click launch', () =
assert.equal(h.w.ballState, 'ready');
h.input('click');
assert.equal(h.w.ballState, 'live');
h.input('click', 'ring');
h.input('ring-press', 'ring');
assert.ok(h.w.flippers.every((f) => f.state === 'rising'));
});