Skip to content

Add layout placement, whole-wall shapes and panel chain patterns (Layouts plan step 3) - #285

Merged
ewowi merged 17 commits into
MoonModules:mainfrom
GK-Triumvirate:layout-composition
Dec 3, 2026
Merged

ewowi merged 17 commits into
MoonModules:mainfrom
GK-Triumvirate:layout-composition

Conversation

@GK-Triumvirate

@GK-Triumvirate GK-Triumvirate commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What it changes, and why

This builds steps 3 and 5 of "Layouts that describe panels". Today every layout starts at (0, 0), so two layouts overlap. With this change they sit side by side on one wall.

  • Place each layout. Expert mode offers position (x, y, z), 90° rotation and mirror on every layout, MoonLive scripts included. A layout turns around its own box.
  • Shape the whole wall. Layouts gets rotate, mirror and shape (rectangle, circle, ellipse). Lights outside the shape stay dark and keep their place on the wire, so HUB75 panel detection still works.
  • Pick a panel chain by name. PanelsLayout gets eight named row patterns plus custom. rotateP works with all of them.
  • No per-frame placement math. Positions are calculated when the mapping is built. A layout with no rotation or mirror needs one pass, others need two.

Masked and very large walls also need these safety fixes:

  • Masked frames: frames sent in wire order keep masked lights dark. When memory is short, the optional gap cache is freed before the picture shrinks.
  • Very large boxes: a box with more cells than the index type holds shrinks to fit. Size checks stop 32-bit byte counts from wrapping around.
  • Preview and held frames: the preview skips invalid light positions. A held frame repaints after an output-memory failure.

Custom C++ layouts need one edit: rename defineControls() to defineLayoutControls(). Saved settings and MoonLive scripts carry over. MIGRATING.md and the tutorial cover this.

Size

The diff is 42 files, +1733/−154, over the 400-line and ten-file guide. Of those, 273 changed lines are the generated docs/help/help.json. Composition is one pull request because the plan says to split by topic, not by size. It also includes the chain patterns from step 5.

What agents wrote and audited

  • Antigravity: wrote cc404c9, 49d2acf and 07bf68d. Rebased layout-composition onto 77481a8, reviewed the mask and cache fixes with Codex, and ran the host test and doc/prose checks.
  • OpenAI Codex: wrote 1a9275a, cba664b, 4867b02, 9e77fd7 and 6e74f44. Compared the Pi and ESP32 HUB75 output in the code this builds on (972 of 972 cases match) and audited the rebased branch, finding the 32-bit overflow fixed in 07bf68d.
  • Claude Code: audited the composition stack before the rebase and checked overlap with Controls read as words with units, one-click picker, LEDs before IR, FSEQ loops and crossfades #283 (cc404c9 and 49d2acf address its P1/P2/P3 findings). Drafted this PR description.
  • 6ffead0, 7387247, d1fc0b1: initial step 3 implementation and complexity/Vale fixes authored on GK-Triumvirate/MoonLight.

Tested

On a Linux host at 07bf68d, based on main at 77481a8:

Check Result
mm_tests 4,300 of 4,300 passed (875,051 assertions)
JavaScript tests 582 of 582 passed
mm_scenarios 18 of 18 passed; 19 live-only scenarios skipped
check_docgen, changed src/ files 0 errors, 0 warnings
check_prose, changed docs/ files 0 errors, 0 warnings
git diff --check clean

Hardware (tested on Adafruit MatrixPortal S3, esp32s3-qspi, ESP32-S3 rev v0.2, 8 MB QIO flash, 2 MB quad PSRAM, SDK v6.1.1):

  • Attached 2× 128×64 HUB75 panels stacked vertically (128×128, 16,384 lights) flashed via /firmware (7.1.0-dev.203, build 07bf68de).
  • Hub75 reported 256x64 (2x 128x64), 1/32 scan, 4-bit (LCD_CAM) at 592 Hz refresh on MatrixPortal S3 with no errors or warnings.
  • Verified Panels named chain (top-left serpentine hides custom per-axis controls, custom restores them), rotateP, whole-wall rotate / mirror / shape (circle darkens all 4 corners across both panels while keeping 256x64 (2x 128x64), 1/32 scan intact), and Expert-mode multi-layout composition (Panel at (0, 0) + Panel-2 at (0, 64), 4 µs / 2 µs).
  • Ran continuously for 23m 35s with no resets: 29 FPS, 75 KB free internal RAM (31 KB max block), 1.5 MB free PSRAM.

run_gates.py: not yet run.

Follow-up commit: 7bc488b is a check_code cleanup (simplifies layout/sink helpers and deduplicates masked-frame tests). CI passes on it: 16 checks passed, 9 skipped.

Known limits

Codex noted two FSEQ issues that also exist on main at 77481a8:

  • With the gap cache freed, overlapping lights that share a cell all show the first light's data.
  • A shorter FSEQ track leaves the previous track's extra channels lit.

… patterns

Implements Steps 3 and 5 of 'Plan: Layouts that describe panels' (stacked cleanly on panel-geometry-hub75):

- Step 3 (Per-layout placement & Layouts container transform/shape):
  - Add LayoutTransform.h with shared 90-degree clockwise rotation, X/Y/XY
    mirror, 2D bounding-box measurement, and exact integer inscribed
    rectangle/circle/ellipse containment helpers.
  - Add expert-mode placement controls (positionX, positionY, positionZ,
    rotate, mirror) to LayoutBase via defineControls() final +
    defineLayoutControls(), automatically covering every built-in layout
    and MoonLiveLayout without name collisions (e.g. RingLayout's rotation).
  - Implement LightEmitter::placePlaced(): untransformed children pay one
    pass only; rotated or mirrored children measure their own box in pass 1
    and emit transformed lights, gaps, and nextPanel() markers in pass 2.
  - Add whole-wall rotate, mirror, and shape (rectangle/circle/ellipse)
    controls in normal mode on Layouts (with affectsPrepare() and hasGaps()),
    baking lights outside circle/ellipse as real-coordinate gaps so
    PanelRecorder and HUB75 geometry inference keep working intact.

- Step 5 (PanelsLayout chain patterns & rotateP):
  - Add named row chain patterns (top-left/top-right/bottom-left/bottom-right
    serpentine and rows) alongside custom on PanelsLayout, hiding the custom
    outer controls when a named chain is picked and keeping rotateP in normal
    mode while forwarding nextPanel() on rotated passes.

- Regenerate docs/help/help.json and add unit tests covering placement,
  single-pass vs two-pass emission, whole-wall rotate/mirror/shape,
  MoonLiveLayout placement, all 8 named chain patterns + rotateP, and
  end-to-end Hub75Driver chain derivation.

Gate note: zero new check_code.py regressions from this commit (1426 total
findings, 786 duplicated blocks; only the inherited name spread 23 -> 24
from panel-geometry-hub75's Hub75Driver migration entries); check_docgen.py
passes with 0 errors and 1066 warnings.
Hub75BusOutput::checkPins() previously validated all five address lines (A-E) even when the resolved scan rate only drives A-B (1/4), A-C (1/8), or A-D (1/16), refusing panels on boards where unused upper address lines sit on reserved or input-only pins even though buildPinOrder() parks them at GPIO_NUM_NC.

Bound Hub75BusOutput::lines() by hub75AddressBits(geo_.scanRate) during checkPins() while keeping fixedPins() reporting all 14 soldered board lines, and add host unit tests covering 1/4, 1/8, 1/16, and explicit folded 1/4 scans.
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ewowi

ewowi commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks @GK-Triumvirate, this is a big step: placement on every layout, the whole-wall rotate, mirror and shape, and the masked walls, with the plan's tests and a run on two stacked panels. The placement core is exactly what the plan asked for: fields on LayoutBase applied when the mapping is built, nothing per frame, and defineLayoutControls() follows the Template Method DriverBase already uses. Nothing blocks.

What we checked. Because this touches the walk every layout goes through, we compared it against main:

  • A dump of every light, gap, panel record and mapping table over 39 setups (all 16 built-in layouts, combinations, Panels variants, all 13 shipped MoonLive layouts): byte for byte identical.
  • On an ESP32-C3 cube (no PSRAM, so the 16-bit light index): per-module tick, fps, free heap and largest block match main. The image grows 7.2 KB.

One change to our own plan. Step 5 asked for the chain patterns as one select, and that was our mistake, not yours. The per-axis controls (wiringOrderP, X++P, Y++P, snakeP) are the same system as Panel and Cube (X++, Y++, Z++, snakeX/Y/Z), which extends to 3D, and all eight of your patterns are already reachable with them. A named select would be a second way to do the same thing, stopping at 2D. So chain goes; your eight pattern tests stay, rewritten with the per-axis settings, proving every wall in mrcodetastic's list works on Panels, and the panels docs teach the per-axis controls with a picture of each, so a beginner reads the settings off their own wall. One path also ends the disagreement between the named and custom chains on a wall wired from the bottom.

We finish it in a maintainer commit:

  • The container's rotate, mirror and shape stay in normal mode, as you have them: a wall mounted upside down or a round mask is a beginner's fix. Per-layout placement stays expert.
  • The masked-frame fix stays, in its smallest form: a layout with gaps takes no wiring-order shortcut, so the frame goes through placeByLayout, which already drops gaps. The gap-run cache, the eviction ladder, setTestAllocRefusedOnce and the extra sink flags go.
  • The empty-run guard goes back to PanelRecorder alone, as step 1 defines a marker: a Grid followed by a script that starts with nextPanel() records two panels again, not one.
  • One control-name set: a MoonLive layout gets positionX, rotate and mirror like any layout, and a script that declares a host control name gets a script error.
  • placePlaced() pads the index to lightCount() as place() does, so a child that emits fewer lights than it counts doesn't shift the next one.
  • Docs: placement in moonlight.md's Layouts section and its mapping types, adding-a-stream-source.md, and the plan's step 5; a test for a zero channels-per-light.
  • Four commits are authored Codex codex@openai.com; we move them to your account, as on MoonLive layouts: add addGap(x, y, z) builtin #271.
  • The ESP32 (both PSRAM modes) and Teensy builds, which CI skips for a fork.

Both Known limits are real on main; we take them separately. Looking forward to the 8-panel wall on this!

ewowi and others added 14 commits December 3, 2026 12:15
…uses

The pin check reads the address lines by name rather than by table
index, and the MatrixPortal pin test's rig owns the layout and layer its
driver points at, so the driver never outlives them.

KPI: 256lights | Host:2988KB | tick:8/8/8/8/1/8/268/8/8/8us(FPS:125000/125000/125000/125000/1000000/125000/3731/125000/125000/125000) | ESP32:2474KB | src:523(123969) | test:347(90247) | functions-over:313
Commit: src +5/-3 lines | test +35/-34 lines | duplicated lines 3413 -> 3413 (+0)

- **Light domain**: `Hub75BusOutput::lines()` skips the unused address lines by `kFirstAddrLine` and `kAddrLines`, not the indexes 6 and 10.
- **Tests**: `MatrixPortalRig` holds layouts, grid, layer and driver together, declared so the driver dies first; the helpers that left the driver pointing at a dead Layer go.
- **Docs/CI**: prose and repo-health metrics regenerated.
- **Reviews**: the maintainer review's two nits (named range, test lifetime) done; the Reviewer at commit time found nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A masked wall keeps its gaps dark through the layer's own positions, one
rule in place of a gap cache; Panels keeps one way to walk its panels,
which counts passes from where the data enters; MoonLive layouts take the
same placement controls as every layout. Mappings of today's setups stay
byte for byte as on main (41 setups compared) and a C3 cube's tick,
heap and fps match main.

KPI: 256lights | Host:2990KB | tick:8/8/8/8/1/8/271/8/8/8us(FPS:125000/125000/125000/125000/1000000/125000/3690/125000/125000/125000) | ESP32:2477KB | src:524(124314) | test:347(90838) | functions-over:313
Commit: src +138/-382 lines | test +146/-229 lines | duplicated lines 3413 -> 3412 (-1)

- **Light domain**: `Layer::wiringSource()` gives no one-copy path on a layout with gaps, so a sender-mapped frame takes `placeByLayout`, which drops them; the gap-run cache, the eviction ladder, the empty-LUT fallback, `MappingLUT::setEmpty`/`firstDestination` and the ChannelDataSink flags go, and ChannelDataSink and Drivers are main's again. The overflow and oversized-box guards stay.
- **Light domain**: `chain` goes; PanelsLayout walks its panels with `wiringOrderP`, `X++P`, `Y++P` and `snakeP`, the system Panel and Cube use. Serpentine (`PanelLayout::forEachCell`) and `rotateP` count passes from the start corner, so the first pass follows its increment and stays upright on any row count, as Cube already did.
- **Light domain**: the empty-run guard lives in `PanelRecorder` alone; `LightEmitter` and the relay forward every marker.
- **Light domain**: `LightEmitter::placePlaced()` takes a child's whole counted range, as `place()` does.
- **Light domain**: `LayoutBase::kPlacementControls` names the placement controls; a MoonLive layout declaring one is refused with an error status, in place of a second set of names.
- **Core**: the host test seam `setTestAllocRefusedOnce` goes.
- **Tests**: the eight wall patterns with per-axis settings, plus an even-row wall from the bottom-left, a columns-first wall from the right and an even-height serpentine panel; one masked-frame test for the ladder's four; two panels for a Grid before a script's leading marker; a short layout keeping the next one's index; a refused MoonLive layout; zero channels per light.
- **Docs/CI**: placement in moonlight.md and the one-copy wording there and in adding-a-stream-source.md; reading the panel order off a wall in panel-cards.md and the Panels guide; MIGRATING for the pass-counted serpentine and the refused placement names; the plan's steps 3 and 5 done, its index regenerated; help and metrics regenerated.
- **Reviews**: the maintainer review: second topic (masked frames, kept in its smallest form), two control-name sets, `chain` beside the `…P` controls, three empty-run guards, `placePlaced` padding, stale docs, untested guards, done; Codex authorship moved to the contributor. The Reviewer at commit time: serpentine and `rotateP` keyed on row parity (fixed by counting passes, the product owner's call A), the static_assert pinning nothing, the MoonLive card, the clash test's reach, the `placePlaced` doc, MIGRATING's reach and YX wording, the `rotateP` guide line, the YX far-start test, a negative card sentence, done.
- **Docs/CI**: the KPI's ESP32 +3 KB is placement; a C3 build grows 3.2 KB against main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…SP32 pin check

GK-Triumvirate's fix, finished by the maintainer commit 6370f76, merged
here so main's CI runs once for MoonModules#284 and MoonModules#285.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/reference/metrics/prose.json
#	docs/reference/metrics/repo-health.json
#	docs/reference/metrics/repo-health.md
@ewowi
ewowi merged commit a13170a into MoonModules:main Dec 3, 2026
26 checks passed
@ewowi

ewowi commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Merged, thanks @GK-Triumvirate! Placement on every layout and the whole-wall rotate, mirror and shape are in, and #284 rode along.

What our maintainer commit changed, and why:

  • Masked frames: one rule instead of the gap cache: a layout with gaps takes no one-copy path, so the frame goes through the layer's positions and the gaps stay dark.
  • Panel order: chain went, as the review said; the per-axis controls stay the one way. Reviewing it turned up an older wrinkle: serpentine and rotateP counted rows from the top, so a wall with an even number of rows entered at the bottom started on the wrong side. They now count passes from where the data enters, as the Cube already did; your eight pattern tests became per-axis tests plus even-row ones, and the panel-cards page teaches reading the order off your wall.
  • One empty-run guard again (the recorder), placePlaced padding a child's whole range, and one set of placement names: a MoonLive script that declares one is refused.
  • Your four Codex-authored commits now carry your name.

Before merging we checked it against main: every light, gap, panel record and mapping table over 41 setups came out byte for byte the same, and on an ESP32-C3 cube the tick, heap and fps matched.

Looking forward to the 8-panel wall on this, and to the HTTPS idea when you get to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants