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

+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);
}
}