forked from Blendman974/faceclaw
EvenHub compativility fixes: Z-order changes, different text color distribution, text containers scroll
This commit is contained in:
1 parent
c713815694
commit
10a9c85f27
22 files changed
+1545
-610
No files matched your search
@@ -2,50 +2,24 @@
|
||||
* Debug-log descriptions of EvenHub page layouts and container updates.
|
||||
* session.ts sends them to logcat at debug level (tag FaceclawEvenHubLayout).
|
||||
*
|
||||
* Lines starting "stock:" flag places where our emulation may draw something
|
||||
* stock would not, or the reverse. The stock rules come from the
|
||||
* evenRealities-openCFW reconstruction of firmware 2.2.6.10
|
||||
* (evenhub_ui_containers.c, evenhub_ui_page.c, common_image_container.c) and
|
||||
* the community simulator's hardware notes. Nobody has checked them against
|
||||
* captures of our own, so they are leads, not established facts. They also
|
||||
* describe the glasses firmware only: the Even phone app sits between the SDK
|
||||
* and the firmware and may validate or convert payloads first.
|
||||
* "note:" lines point out page quirks that change what stock (and so we) do
|
||||
* with it: shared ids, missing or extra capture containers, a wrong
|
||||
* containerTotalNum.
|
||||
*/
|
||||
import {
|
||||
paintOrder,
|
||||
readOptionalNumber,
|
||||
type EvenHubContainer,
|
||||
type EvenHubImageContainer,
|
||||
type EvenHubListContainer,
|
||||
type EvenHubPage,
|
||||
type EvenHubTextContainer,
|
||||
} from "./containers";
|
||||
|
||||
/** Stock image-container size limits; outside them the container, and so the whole page, fails to create. */
|
||||
const STOCK_IMAGE_MIN_SIZE = 20;
|
||||
const STOCK_IMAGE_MAX_WIDTH = 288;
|
||||
const STOCK_IMAGE_MAX_HEIGHT = 144;
|
||||
import type { PreparedImage } from "./image-pipeline";
|
||||
|
||||
const CONTENT_PREVIEW_CHARS = 40;
|
||||
const RAW_STRING_CHARS = 120;
|
||||
const RAW_ARRAY_ITEMS = 32;
|
||||
|
||||
/**
|
||||
* Stock's bottom-to-top container order: lists, then texts, then images (each
|
||||
* in declaration order). The firmware sorts by zOrderIndex (stably) only when
|
||||
* every container has one and there are at least two.
|
||||
*/
|
||||
export function stockPaintOrder(containers: readonly EvenHubContainer[]): EvenHubContainer[] {
|
||||
const legacy = [
|
||||
...containers.filter((c) => c.kind === "list"),
|
||||
...containers.filter((c) => c.kind === "text"),
|
||||
...containers.filter((c) => c.kind === "image"),
|
||||
];
|
||||
const allHaveZ = legacy.every((c) => c.zOrderIndex !== undefined);
|
||||
if (!allHaveZ || legacy.length < 2) return legacy;
|
||||
return legacy.sort((a, b) => (a.zOrderIndex ?? 0) - (b.zOrderIndex ?? 0));
|
||||
}
|
||||
|
||||
function label(c: EvenHubContainer): string {
|
||||
return `${c.kind}#${c.id} ${JSON.stringify(c.name)}`;
|
||||
}
|
||||
@@ -56,7 +30,7 @@ function preview(text: string): string {
|
||||
|
||||
function decoration(c: EvenHubTextContainer | EvenHubListContainer): string {
|
||||
let out = "";
|
||||
if (c.borderWidth > 0) out += ` border=${c.borderWidth}${c.borderRadius > 0 ? `r${c.borderRadius}` : ""}`;
|
||||
if (c.borderWidth > 0) out += ` border=${c.borderWidth}c${c.borderColor}${c.borderRadius > 0 ? `r${c.borderRadius}` : ""}`;
|
||||
if (c.paddingLength > 0) out += ` pad=${c.paddingLength}`;
|
||||
if (c.isEventCapture) out += " capture";
|
||||
if (c.font) out += " font";
|
||||
@@ -78,66 +52,22 @@ function describeContainer(c: EvenHubContainer): string {
|
||||
}
|
||||
}
|
||||
|
||||
function overlaps(a: EvenHubContainer, b: EvenHubContainer): boolean {
|
||||
if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) return false;
|
||||
return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
|
||||
}
|
||||
|
||||
/** Ways a page would lay out or behave differently on stock firmware. */
|
||||
export function stockDifferences(page: EvenHubPage, declaredTotal?: number): string[] {
|
||||
/** Quirks of a page that change how stock treats it. */
|
||||
export function pageNotes(page: EvenHubPage, declaredTotal?: number): string[] {
|
||||
const notes: string[] = [];
|
||||
const containers = page.containers;
|
||||
const ours = paintOrder(containers);
|
||||
const stock = stockPaintOrder(containers);
|
||||
|
||||
const withZ = containers.filter((c) => c.zOrderIndex !== undefined).length;
|
||||
if (withZ > 0 && withZ < containers.length) {
|
||||
notes.push(`zOrderIndex is set on ${withZ} of ${containers.length} containers: we sort by it (missing = 0), stock ignores it`);
|
||||
}
|
||||
if (ours.some((c, i) => c !== stock[i])) {
|
||||
notes.push(`paint order differs; stock bottom to top is ${stock.map(label).join(", ")}`);
|
||||
for (let i = 0; i < ours.length; i++) {
|
||||
for (let j = i + 1; j < ours.length; j++) {
|
||||
const below = ours[i]!;
|
||||
const above = ours[j]!;
|
||||
if (overlaps(below, above) && stock.indexOf(below) > stock.indexOf(above)) {
|
||||
notes.push(`${label(below)} overlaps ${label(above)}: we draw ${label(above)} on top, stock draws ${label(below)} on top`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const c of containers) {
|
||||
if (c.kind !== "image") continue;
|
||||
if (c.width < STOCK_IMAGE_MIN_SIZE || c.height < STOCK_IMAGE_MIN_SIZE || c.width > STOCK_IMAGE_MAX_WIDTH || c.height > STOCK_IMAGE_MAX_HEIGHT) {
|
||||
notes.push(
|
||||
`${label(c)} is ${c.width}x${c.height}; stock fails the whole page for an image container outside ` +
|
||||
`${STOCK_IMAGE_MIN_SIZE}-${STOCK_IMAGE_MAX_WIDTH} x ${STOCK_IMAGE_MIN_SIZE}-${STOCK_IMAGE_MAX_HEIGHT}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// The firmware finds a container by id with a first-match walk of its
|
||||
// (stock-ordered) list, for image updates and events alike.
|
||||
const ordered = paintOrder(page.containers);
|
||||
const byId = new Map<number, EvenHubContainer[]>();
|
||||
for (const c of stock) byId.set(c.id, [...(byId.get(c.id) ?? []), c]);
|
||||
for (const c of ordered) byId.set(c.id, [...(byId.get(c.id) ?? []), c]);
|
||||
byId.forEach((shared, id) => {
|
||||
if (shared.length > 1) {
|
||||
notes.push(`id ${id} is shared by ${shared.map(label).join(", ")}; stock resolves it to ${label(shared[0]!)} only`);
|
||||
notes.push(`id ${id} is shared by ${shared.map(label).join(", ")}; updates and events resolve to ${label(shared[0]!)} only`);
|
||||
}
|
||||
});
|
||||
|
||||
const captures = stock.filter((c) => c.kind !== "image" && c.isEventCapture);
|
||||
if (captures.length !== 1) {
|
||||
notes.push(
|
||||
captures.length === 0
|
||||
? "no event-capture container (stock requires exactly one)"
|
||||
: `${captures.length} event-capture containers; stock binds only the first, ${label(captures[0]!)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (declaredTotal !== undefined && declaredTotal !== containers.length) {
|
||||
notes.push(`containerTotalNum is ${declaredTotal} but ${containers.length} containers were sent`);
|
||||
const captures = ordered.filter((c) => c.kind !== "image" && c.isEventCapture);
|
||||
if (captures.length === 0) notes.push("no event-capture container, so the app gets no input");
|
||||
else if (captures.length > 1) notes.push(`${captures.length} event-capture containers; only the first, ${label(captures[0]!)}, gets input`);
|
||||
if (declaredTotal !== undefined && declaredTotal !== page.containers.length) {
|
||||
notes.push(`containerTotalNum is ${declaredTotal} but ${page.containers.length} containers were sent (nothing checks it)`);
|
||||
}
|
||||
return notes;
|
||||
}
|
||||
@@ -159,7 +89,7 @@ function rawJson(data: Record<string, unknown>): string {
|
||||
}
|
||||
}
|
||||
|
||||
/** A create/rebuild/extension layout: one line per container in our paint order, then stock differences, then the raw payload. */
|
||||
/** A create/rebuild/extension layout: one line per container in paint order, then notes, then the raw payload. */
|
||||
export function describePage(method: string, page: EvenHubPage, data: Record<string, unknown>): string[] {
|
||||
const containers = page.containers;
|
||||
const count = (kind: EvenHubContainer["kind"]) => containers.filter((c) => c.kind === kind).length;
|
||||
@@ -168,10 +98,10 @@ export function describePage(method: string, page: EvenHubPage, data: Record<str
|
||||
const menu = page.menuItems.length > 0 ? `, ${page.menuItems.length} menu items` : "";
|
||||
const lines = [
|
||||
`${method}: ${containers.length} containers (${count("list")} list, ${count("text")} text, ${count("image")} image)` +
|
||||
`${total}${menu}; we paint bottom to top:`,
|
||||
`${total}${menu}; painted bottom to top:`,
|
||||
];
|
||||
paintOrder(containers).forEach((c, i) => lines.push(` ${i}: ${describeContainer(c)}`));
|
||||
for (const note of stockDifferences(page, declaredTotal)) lines.push(` stock: ${note}`);
|
||||
for (const note of pageNotes(page, declaredTotal)) lines.push(` note: ${note}`);
|
||||
lines.push(` raw: ${rawJson(data)}`);
|
||||
return lines;
|
||||
}
|
||||
@@ -184,75 +114,55 @@ function payloadKind(raw: unknown): string {
|
||||
return typeof raw;
|
||||
}
|
||||
|
||||
function imageFormat(bytes: Uint8Array, container: EvenHubImageContainer): string {
|
||||
if (bytes.length > 4 && bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) return "PNG";
|
||||
// BITMAPINFOHEADER biBitCount: 14-byte file header + 14.
|
||||
if (bytes.length > 30 && bytes[0] === 0x42 && bytes[1] === 0x4d) return `BMP ${bytes[28]! | (bytes[29]! << 8)}bpp`;
|
||||
const area = container.width * container.height;
|
||||
if (bytes.length === area) return "raw8";
|
||||
if (bytes.length === Math.ceil(area / 2)) return "raw4";
|
||||
const head = Array.from(bytes.subarray(0, 4), (b) => b.toString(16).padStart(2, "0")).join(" ");
|
||||
return `unrecognized (${bytes.length} bytes, starts ${head})`;
|
||||
}
|
||||
|
||||
/** Lit-pixel count and bounding box, so a blank "hide this" image is recognizable. */
|
||||
function litSummary(decoded: { pixels: Uint8Array; width: number; height: number }): string {
|
||||
/** Lit-pixel count and bounding box of 4-bit levels, so a blank "hide this" image is recognizable. */
|
||||
function litSummary(levels: Uint8Array, width: number): string {
|
||||
let lit = 0;
|
||||
let max = 0;
|
||||
let x0 = decoded.width;
|
||||
let y0 = decoded.height;
|
||||
let x0 = width;
|
||||
let y0 = Infinity;
|
||||
let x1 = -1;
|
||||
let y1 = -1;
|
||||
for (let i = 0; i < decoded.pixels.length; i++) {
|
||||
const value = decoded.pixels[i]!;
|
||||
if (value === 0) continue;
|
||||
for (let i = 0; i < levels.length; i++) {
|
||||
const level = levels[i]!;
|
||||
if (level === 0) continue;
|
||||
lit++;
|
||||
if (value > max) max = value;
|
||||
const x = i % decoded.width;
|
||||
const y = Math.floor(i / decoded.width);
|
||||
if (level > max) max = level;
|
||||
const x = i % width;
|
||||
const y = Math.floor(i / width);
|
||||
if (x < x0) x0 = x;
|
||||
if (x > x1) x1 = x;
|
||||
if (y < y0) y0 = y;
|
||||
if (y > y1) y1 = y;
|
||||
}
|
||||
return lit === 0 ? "blank" : `lit=${lit}px max=${max} bbox=${x0},${y0}-${x1},${y1}`;
|
||||
return lit === 0 ? "blank" : `lit=${lit}px max=${max}/15 bbox=${x0},${y0}-${x1},${y1}`;
|
||||
}
|
||||
|
||||
export type ImageUpdateDebug = {
|
||||
page: EvenHubPage | null;
|
||||
sentId: number;
|
||||
sentName: string;
|
||||
container: EvenHubImageContainer | null;
|
||||
raw: unknown;
|
||||
bytes: Uint8Array | null;
|
||||
decoded: { pixels: Uint8Array; width: number; height: number } | null;
|
||||
/** BleEhSendImageResult: 0 success, 1 imageException, 2 sizeInvalid, 3 sendFailed. */
|
||||
/** The container the id resolves to. */
|
||||
target: EvenHubContainer | undefined;
|
||||
prepared: PreparedImage;
|
||||
/** Whether the container now shows the update. */
|
||||
shown: boolean;
|
||||
/** EhImageUpdateResult returned to the app. */
|
||||
result: number;
|
||||
};
|
||||
|
||||
export function describeImageUpdate(u: ImageUpdateDebug): string[] {
|
||||
const parts = [`updateImageRawData ${u.container ? label(u.container) : `id=${u.sentId} ${JSON.stringify(u.sentName)}`}`];
|
||||
if (u.container && u.sentName !== "" && u.sentName !== u.container.name) parts.push(`(sent name ${JSON.stringify(u.sentName)})`);
|
||||
const parts = [`updateImageRawData id=${u.sentId} ${JSON.stringify(u.sentName)}`];
|
||||
parts.push(`-> ${u.target ? label(u.target) : "no container"}`);
|
||||
parts.push(`payload=${payloadKind(u.raw)}`);
|
||||
if (u.bytes && u.container) parts.push(`format=${imageFormat(u.bytes, u.container)}`);
|
||||
if (u.decoded) parts.push(`decoded=${u.decoded.width}x${u.decoded.height} ${litSummary(u.decoded)}`);
|
||||
parts.push(`result=${u.result}`);
|
||||
if (u.prepared.format) parts.push(`format=${u.prepared.format}`);
|
||||
if (u.prepared.levels) parts.push(`${u.prepared.width}x${u.prepared.height} ${litSummary(u.prepared.levels, u.prepared.width)}`);
|
||||
parts.push(`result=${u.result}`, u.shown ? "shown" : "not shown");
|
||||
const lines = [parts.join(" ")];
|
||||
|
||||
if (!u.container) lines.push(` no image container with id ${u.sentId} on this page`);
|
||||
else if (u.result !== 0) lines.push(" rejected; the container keeps its previous pixels");
|
||||
if (typeof u.raw === "string") {
|
||||
lines.push(" stock: real hardware reportedly ignores a base64-string imageData (it needs bytes); we decode and draw it");
|
||||
}
|
||||
if (u.container && u.decoded && (u.decoded.width !== u.container.width || u.decoded.height !== u.container.height)) {
|
||||
lines.push(
|
||||
` stock: the firmware only accepts a bitmap exactly the container's size (${u.container.width}x${u.container.height}); ` +
|
||||
"we tile or crop it to fit",
|
||||
);
|
||||
}
|
||||
const stockTarget = u.page ? stockPaintOrder(u.page.containers).find((c) => c.id === u.sentId) : undefined;
|
||||
if (stockTarget && stockTarget.kind !== "image") {
|
||||
lines.push(` stock: id ${u.sentId} resolves to ${label(stockTarget)} first, so stock drops this update`);
|
||||
if (u.prepared.reason) lines.push(` ${u.prepared.reason}`);
|
||||
if (u.prepared.result === 0 && u.target?.kind !== "image") {
|
||||
lines.push(` the id ${u.target ? `resolves to ${label(u.target)}` : "matches no container"}, so the glasses refuse the transfer`);
|
||||
} else if (u.prepared.result === 0 && !u.shown && u.target) {
|
||||
lines.push(` ${u.prepared.width}x${u.prepared.height} isn't the container's ${u.target.width}x${u.target.height}, so the glasses drop it`);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
@@ -264,7 +174,7 @@ export function describeTextUpgrade(
|
||||
offset: number | undefined,
|
||||
sentLength: number,
|
||||
): string {
|
||||
if (!container) return `textContainerUpgrade id=${sentId} ${JSON.stringify(sentName)}: no matching text container`;
|
||||
if (!container) return `textContainerUpgrade id=${sentId} ${JSON.stringify(sentName)}: no container with that id`;
|
||||
const at = offset === undefined ? "" : ` offset=${offset}`;
|
||||
const color = container.textColor === undefined ? "" : ` color=${container.textColor}`;
|
||||
return `textContainerUpgrade ${label(container)}${at} sent=${sentLength} chars -> len=${container.content.length}${color} ${preview(container.content)}`;
|
||||
|
||||
Reference in new issue
Block a user