Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
Phone portrait: the video is pinned on top with its 16:9 box reserved (no layout shift), and one status strip sits under it #115
quill/arm:quill/112-phone-portrait-the-video-is-pinned-on-to → main 4 commits fork
7 files
changed +57
−6
Software/README.md +5 −1
| @@ -513,7 +513,11 @@ the app's own page. | ||
| 513 | 513 | **On a phone.** The page is laid out for one thumb, phone first. The view |
| 514 | 514 | (camera or 3D) sits on top at full width. Under it a status strip shows who |
| 515 | 515 | drives, your place in the line, the time left, the turn's one button, and |
| 516 | the red **Stop**. Stop is there whenever you drive, and for the owner. Below | |
| 516 | the red **Stop**. Stop is there whenever you drive, and for the owner. Held | |
| 517 | upright (up to 600 px wide), the view is pinned to the top in a 16:9 box kept | |
| 518 | free before the first frame arrives, so nothing jumps when the picture | |
| 519 | does. The strip under it is the one status line: the arm live or | |
| 520 | reconnecting moves there from over the picture (`src/ui/mobile.css`). Below | |
| 517 | 521 | that is a sheet with tabs at the bottom edge: **Chat**, **Queue**, |
| 518 | 522 | **Controls** (only on your turn, and it opens by itself when your turn |
| 519 | 523 | starts) and **Admin** (the owner: the room, the safe zone, the trims, |
Software/so101/src/relay.test.ts +3
| @@ -235,6 +235,9 @@ describe("relay", () => { | ||
| 235 | 235 | expect(s.status).toBe(503); |
| 236 | 236 | expect(await s.json()).toMatchObject({ reconnecting: true, source: expect.stringContaining(`reconnecting to the arm: 127.0.0.1:${port}`) }); |
| 237 | 237 | expect((await fetch(`${base}/move`, { method: "POST", body: '{"targets":{"1":2000}}' })).status).toBe(503); |
| 238 | // The forge's health check asks whether the app serves, not whether the arm answers: a fresh deploy with the Pi down is still up. | |
| 239 | const { health } = (await Bun.file(new URL("../../../forge.json", import.meta.url)).json()).app as { health: string }; | |
| 240 | expect((await fetch(`${base}${health}`)).status).toBe(200); | |
| 238 | 241 | await sleep(650); |
| 239 | 242 | expect((await link(base)).mode).toBe("offline"); |
| 240 | 243 | expect(await joints(base)).toBe(6); |
Software/so101/src/server.test.ts +17
| @@ -181,6 +181,23 @@ describe("viewer page", () => { | ||
| 181 | 181 | expect((await fetch(`${base}/ui/${version}/..%2Fserver.ts`)).status).toBe(404); |
| 182 | 182 | }); |
| 183 | 183 | |
| 184 | test("links the phone-portrait stylesheet and serves it as CSS: the video pinned in a reserved 16:9 box, one status strip", async () => { | |
| 185 | const page = await (await fetch(`${base}/`)).text(); | |
| 186 | const link = /<link rel="stylesheet" href="(\/ui\/[0-9a-f]{12}\/mobile\.css)" media="\(max-width: 600px\) and \(orientation: portrait\)">/.exec(page); | |
| 187 | expect(link).not.toBeNull(); | |
| 188 | const r = await fetch(`${base}${link![1]}`); | |
| 189 | expect(r.status).toBe(200); | |
| 190 | expect(r.headers.get("content-type")).toBe("text/css"); | |
| 191 | expect(r.headers.get("cache-control")).toContain("immutable"); | |
| 192 | const css = await r.text(); | |
| 193 | expect(css).toMatch(/#app \{[^}]*position: sticky; top: 0;[^}]*aspect-ratio: 16 \/ 9/); | |
| 194 | expect(css).toContain("env(safe-area-inset-top"); | |
| 195 | expect(css).toMatch(/#top \.info, #driverTag \{ display: none; \}/); // the overlay's status lines give way to the strip's | |
| 196 | expect(page).toContain("viewport-fit=cover"); | |
| 197 | expect(page).toMatch(/<section id="strip"[\s\S]*id="armLine"[\s\S]*<\/section>/); | |
| 198 | expect(page).toMatch(/#armLine \{ display: none;/); // the desktop keeps its overlay and never shows the strip's copy | |
| 199 | }); | |
| 200 | ||
| 184 | 201 | test("is laid out for a phone: tabs under the thumb, an E-stop beside the status, room for the forge pill", async () => { |
| 185 | 202 | const page = await (await fetch(`${base}/`)).text(); |
| 186 | 203 | for (const tab of ["chat", "queue", "controls", "admin"]) expect(page).toContain(`data-tab="${tab}"`); |
Software/so101/src/server.ts +4 −4
| @@ -154,8 +154,8 @@ const JAM_WINDOW = 6; | ||
| 154 | 154 | const RESUME_AFTER_DROPS = 20; |
| 155 | 155 | const VENDORED = new Set(["three", "urdf-loader"]); |
| 156 | 156 | /** A module the page loads from src/ui: plain JavaScript, never its tests. */ |
| 157 | const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.js$/.test(name); | |
| 158 | const MIME: Record<string, string> = { ".js": "text/javascript", ".mjs": "text/javascript", ".json": "application/json", ".urdf": "application/xml", ".stl": "model/stl", ".dae": "model/vnd.collada+xml", ".png": "image/png", ".jpg": "image/jpeg" }; | |
| 157 | const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.(?:js|css)$/.test(name); | |
| 158 | const MIME: Record<string, string> = { ".js": "text/javascript", ".css": "text/css", ".mjs": "text/javascript", ".json": "application/json", ".urdf": "application/xml", ".stl": "model/stl", ".dae": "model/vnd.collada+xml", ".png": "image/png", ".jpg": "image/jpeg" }; | |
| 159 | 159 | |
| 160 | 160 | export async function startServer(bus: FeetechBus, options: ServerOptions = {}): Promise<RunningServer> { |
| 161 | 161 | const ids = options.ids ?? [1, 2, 3, 4, 5, 6]; |
| @@ -642,7 +642,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}): | ||
| 642 | 642 | // ------------------------------------------------------------------ routes |
| 643 | 643 | const viewerPath = join(here, "viewer.html"); |
| 644 | 644 | const uiDir = join(here, "ui"); |
| 645 | /** The page's own modules, under a name that changes with their content: cached for good, and a deploy is seen at once. */ | |
| 645 | /** The page's own modules and its phone stylesheet, under a name that changes with their content: cached for good, and a deploy is seen at once. */ | |
| 646 | 646 | const uiVersion = () => { |
| 647 | 647 | const hash = createHash("sha256"); |
| 648 | 648 | for (const f of readdirSync(uiDir).filter(isUiModule).sort()) hash.update(f).update(readFileSync(join(uiDir, f))); |
| @@ -685,7 +685,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}): | ||
| 685 | 685 | if (!path || ![".js", ".mjs", ".json"].includes(extname(path).toLowerCase())) return json(res, 404, { error: "no such vendored file" }); |
| 686 | 686 | return file(res, path, "max-age=86400"); |
| 687 | 687 | } |
| 688 | const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.js)$/.exec(url.pathname); | |
| 688 | const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.(?:js|css))$/.exec(url.pathname); | |
| 689 | 689 | if (req.method === "GET" && ui) { |
| 690 | 690 | if (!isUiModule(ui[1]!) || !existsSync(join(uiDir, ui[1]!))) return json(res, 404, { error: "no such module" }); |
| 691 | 691 | return file(res, join(uiDir, ui[1]!), "public, max-age=31536000, immutable"); |
Software/so101/src/ui/mobile.css added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | /* A phone held upright: the video pinned on top, full-bleed, its 16:9 box reserved before the first frame arrives so | |
| 2 | nothing under it moves; directly under it one status strip (who drives and the time left, your place in line, the | |
| 3 | arm live or reconnecting); the sheet of tabs below. viewer.html links this only for this media query, so the | |
| 4 | desktop and landscape layouts never read it. */ | |
| 5 | @media (max-width: 600px) and (orientation: portrait) { | |
| 6 | #shell { grid-template-rows: auto auto minmax(0, 1fr); } | |
| 7 | /* The notch: a black band the height of the top inset, outside the 16:9 box (content-box keeps the ratio on the picture). */ | |
| 8 | #app { position: sticky; top: 0; box-sizing: content-box; aspect-ratio: 16 / 9; border-top: env(safe-area-inset-top, 0px) solid #000; } | |
| 9 | /* The keyboard is up: the view gives way to the chat, as it does on every layout. */ | |
| 10 | #shell.typing { grid-template-rows: minmax(0, var()) auto minmax(0, 1fr); } | |
| 11 | #shell.typing #app { aspect-ratio: auto; } | |
| 12 | /* One status line: the arm's state moves from over the video into the strip, and the driver's name over the video goes, | |
| 13 | since the strip already says who drives. */ | |
| 14 | #top .info, #driverTag { display: none; } | |
| 15 | #armLine { display: flex; } | |
| 16 | } |
Software/so101/src/viewer.html +11 −1
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | <link rel="modulepreload" href="/ui/__VERSION__/camera-plan.js"> |
| 21 | 21 | <link rel="modulepreload" href="/ui/__VERSION__/drive.js"> |
| 22 | 22 | <link rel="modulepreload" href="/ui/__VERSION__/frames.js"> |
| 23 | <link rel="stylesheet" href="/ui/__VERSION__/mobile.css" media="(max-width: 600px) and (orientation: portrait)"> | |
| 23 | 24 | <style> |
| 24 | 25 | /* Phone portrait first: the view on top, a status strip with the E-stop under it, a sheet of tabs below that. |
| 25 | 26 | Landscape on a phone: the view fills the screen and the strip and the sheet float over it. |
| @@ -86,6 +87,7 @@ | ||
| 86 | 87 | #driverLine { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #driverLine.none { color: var(); font-weight: 500; } |
| 87 | 88 | #clock { color: var(); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #clock.idle { color: var(); } |
| 88 | 89 | #capLine { color: var(); font-size: 12px; } #capLine:empty { display: none; } |
| 90 | #armLine { display: none; gap: 6px; align-items: center; color: var(); font-size: 12px; white-space: nowrap; } #armText { min-width: 0; overflow: hidden; text-overflow: ellipsis; } /* shown on a phone held upright (ui/mobile.css) */ | |
| 89 | 91 | #driverLine.paused { color: var(); } |
| 90 | 92 | #turnActions { display: flex; gap: 6px; } #turnActions:empty { display: none; } |
| 91 | 93 | .estop { flex: none; min-width: 72px; min-height: 52px; border: 0; border-radius: 12px; background: #d1242f; color: #fff; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; box-shadow: 0 0 0 3px rgba(209,36,47,.25), 0 2px 8px rgba(0,0,0,.35); } |
| @@ -318,7 +320,7 @@ | ||
| 318 | 320 | |
| 319 | 321 | <section id="strip" aria-label="Who drives" aria-live="polite"> |
| 320 | 322 | <div id="ring" hidden aria-hidden="true"><span id="ringN"></span></div> |
| 321 | <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock" aria-live="off"></div><div id="capLine"></div></div> | |
| 323 | <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock" aria-live="off"></div><div id="capLine"></div><div id="armLine" aria-live="off"><span class="dot" id="armDot"></span><span id="armText"></span></div></div> | |
| 322 | 324 | <div id="turnActions"></div> |
| 323 | 325 | <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button> |
| 324 | 326 | <button id="stop" class="estop" data-stop title="Stop (space or Esc): halt everything, hold with torque, until someone resumes" aria-label="Stop the arm">Stop</button> |
| @@ -1965,6 +1967,14 @@ | ||
| 1965 | 1967 | $("readout").innerHTML = `<span>lowest part <b>${Number.isFinite(d.lowestMm) ? d.lowestMm : "—"} mm</b> above the table</span><span>zone <b>${d.zone === "enforce" || d.zone === "warn" || d.zone === "off" ? d.zone : "—"}</b></span>`; |
| 1966 | 1968 | } |
| 1967 | 1969 | } |
| 1970 | /** On a phone held upright the strip says the arm's state, not the video (ui/mobile.css): the words the overlay holds, mirrored as they change. */ | |
| 1971 | const info = document.querySelector("#top .info"); | |
| 1972 | const mirrorArm = () => { | |
| 1973 | $("armDot").className = $("dot").className; | |
| 1974 | $("armText").textContent = [$("link").hidden ? "" : $("link").textContent, $("state").textContent, $("live").textContent && `camera ${$("live").textContent}`, $("lag").hidden ? "" : $("lag").textContent.replace(/^· /, "")].filter(Boolean).join(" · "); | |
| 1975 | }; | |
| 1976 | new MutationObserver(mirrorArm).observe(info, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ["class", "hidden"] }); | |
| 1977 | mirrorArm(); | |
| 1968 | 1978 | function noStatus() { |
| 1969 | 1979 | const reconnecting = linkNow === "reconnecting"; |
| 1970 | 1980 | $("dot").className = reconnecting ? "dot warn" : "dot"; $("state").textContent = reconnecting ? "reconnecting…" : "no arm"; |
forge.json +1
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | "100.89.95.68:8101" |
| 17 | 17 | ], |
| 18 | 18 | "check": { |
| 19 | "run": "cd Software/so101 && bun install --frozen-lockfile && bun x tsc --noEmit && bun test", | |
| 19 | 20 | "limits": { |
| 20 | 21 | "cpus": 6, |
| 21 | 22 | "memory": 6144 |
new above
offline