Skip to content

feat(screenmap): add v2 schema parser alongside v1, auto-detect by shape - #3051

Merged
zackees merged 1 commit into
masterfrom
feat/screenmap-v2-parser
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/screenmap-v2-parser

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Closes #3050.

Adds support for the screenmap v2 format (zackees/ledmapper#92) inside the existing ScreenMap::ParseJson(const char*, flat_map<string, ScreenMap>*).

Dispatch (top to bottom)

  1. Explicit `"version": 2` → v2 parser
  2. Explicit `"version": 1` → v1 parser
  3. Has top-level `segments` array (and no `map`) → v2 parser (auto-detect)
  4. Falls through to the existing `map` path

Flatten policy (Proposal A from #3050)

Each v2 segment becomes one `ScreenMap` entry keyed by the segment's `id`. Fork twins each get their own entry (e.g. `a`, `b` where `b` has `parent: "a"`). UI/wiring metadata (`pin`, `group`, `parent`, `offset`, `z`, `groups[]`) is intentionally ignored — firmware just needs per-LED positions. A future `ScreenMapV2` type (Proposal B from #3050) can preserve the richer structure for editor / video tool consumers; this PR is the minimal flatten path.

Backward compat

  • All existing v1 fixtures and the existing `"ScreenMap JSON parsing"` test case stay green.
  • Public API unchanged. No new signatures, no breaking renames.

Tests added

  • `v2 basic segments parsing` — two segments, full extraction
  • `v2 auto-detect without explicit version` — root has `segments` but no `version`
  • `v2 forks produce separate entries` — parent + child both materialize with own coords
  • `v1 file with explicit "version": 1 still works` — explicit v1 doesn't trip v2 dispatch
  • `v2 malformed segments errors cleanly` — missing `x` returns false + non-empty err

Verified

`uv run test.py --cpp screenmap --no-pch` → all tests pass.

Summary by CodeRabbit

  • New Features

    • Added support for an enhanced data format version with improved structure validation and error handling
  • Tests

    • Comprehensive test coverage for new format support, validation errors, and backward compatibility with legacy formats

Adds support for the screenmap v2 format (zackees/ledmapper#92) inside the
existing ScreenMap::ParseJson(const char*, flat_map<string, ScreenMap>*).
Auto-detect rules (top to bottom):

  1. Explicit "version": 2  -> v2 parser
  2. Explicit "version": 1  -> v1 parser
  3. Has top-level "segments" array (and no "map") -> v2 parser
  4. Falls through to the existing "map" path

The v2 parser flattens each segment into one ScreenMap entry keyed by the
segment's `id`. UI/wiring metadata (pin, group, parent, offset, z, groups[])
is intentionally ignored at this layer — firmware just needs the per-LED
positions. A future ScreenMapV2 type can preserve the richer structure for
editor / video-tool consumers; this PR is the minimal flatten path.

Backward compat: all existing v1 fixtures and the existing test case
"ScreenMap JSON parsing" stay green. The public API is unchanged.

Tests added:
- v2 basic segments parsing
- v2 auto-detect without explicit "version"
- v2 with a fork (parent + offset) — both entries materialize independently
- v1 file with explicit "version": 1 still routes through the v1 path
- v2 malformed segment surfaces a clean error string and returns false

Closes the FastLED-side scope of #3050.
@zackees
zackees merged commit 128c7b3 into master Jun 15, 2026
7 of 8 checks passed
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8cb8f07d-0882-485c-b9c7-edca30bb9ca8

📥 Commits

Reviewing files that changed from the base of the PR and between 8c489f2 and ff78851.

📒 Files selected for processing (2)
  • src/fl/math/screenmap.cpp.hpp
  • tests/fl/math/screenmap.cpp

📝 Walkthrough

Walkthrough

Adds v2 JSON segment-array parsing support to ScreenMap::ParseJson. A new internal parseV2SegmentArray helper extracts per-segment id, x/y float arrays, and optional diameter, building one ScreenMap per segment keyed by id. ParseJson gains root-object validation and a v2/v1 dispatch based on the version field and presence of segments vs. map. Five new unit tests cover the added paths.

Changes

ScreenMap v2 JSON parsing

Layer / File(s) Summary
parseV2SegmentArray helper and ParseJson dispatch
src/fl/math/screenmap.cpp.hpp
Adds the parseV2SegmentArray internal function that validates segment objects, parses x/y float arrays, reads optional diameter, and stores one ScreenMap per segment id. Updates ParseJson with a root-object guard and a three-way v2/v1 dispatch (explicit version: 2, auto-detected segments-without-map, or legacy map path).
v2 parsing tests
tests/fl/math/screenmap.cpp
Adds five test cases: basic v2 segment parsing with coordinate verification, auto-detection when version is absent, fork segments producing separate keyed entries, explicit version: 1 still routing to the legacy path, and malformed v2 input returning false with a non-empty error string and empty output map.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A new JSON shape has arrived on the scene,
Segments and forks, parsed neat and clean.
Version two spotted? Off to the helper we go,
Each id keyed snugly in its ScreenMap row.
Old v1 still hops along, nothing is broken —
The rabbit has parsed every pixel unspoken! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/screenmap-v2-parser

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add screenmap v2 schema parser alongside ScreenMap::ParseJson (forks, groups, optional z, branch offset)

1 participant