Skip to content

feat(screenmap): emit v2 from ScreenMap::toJson + convert remaining v1 samples - #3100

Merged
zackees merged 1 commit into
masterfrom
feat/143-v2-fastled
Jun 15, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/143-v2-fastled

Conversation

@zackees

@zackees zackees commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Closes the FastLED side of ledmapper#143. (Ledmapper-side emitters + fixtures landed in zackees/ledmapper#144 just now.)

Summary

  • ScreenMap::toJson / toJsonStr now emit the v2 shape ({ version: 2, groups, segments: [...] }) instead of v1 { map: { name: {...} } }. ScreenMap::ParseJson already accepts both shapes (PR feat(video): FLED v1 container support + FxSdCard accepts both formats #3074), so this is a one-way emitter swap with no parser regression.
  • examples/Fx/FxSdCard/data/screenmap.json — the legacy sidecar fallback in FxSdCard.ino. The FLED happy-path was already embedding v2 (since PR feat(video): FLED v1 container support + FxSdCard accepts both formats #3074); this makes the .rgb fallback path also exercise v2.
  • examples/Chromancer/screenmap.json.h — 4-segment inline JSON literal that Chromancer.ino:191 feeds straight into ScreenMap::ParseJson at setup. Converted to v2.
  • examples/Chromancer/output.json — same 4 segments as the inline literal, converted to v2.

Out of scope

  • examples/Chromancer/gary_woos_wled_port/gary_woos_wled_ledmap.h uses {"map": [array of indices]} — that's the WLED ledmap format, not a v1 ScreenMap. Coincidentally shares the "map" key name but the value type is an array, not an object, so it isn't a screenmap at all. Left untouched.

Verification

  • bash test --cpp screenmap → 1/1 pass (round-trip toJson → ParseJson is bilingual and still works)
  • bash test --cpp fx_video → 1/1 pass
  • bash test --examples FxSdCard → compiles clean
  • bash test --examples Chromancer → compiles clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Updated screenmap data schema to version 2, introducing explicit group-to-color metadata, version tracking, and improved segment organization with unique identifiers and clearer group assignments.

…1 samples

Closes ledmapper#143 on the FastLED side. (Ledmapper-side emitter +
fixture migration shipped in zackees/ledmapper#144.)

ScreenMap::toJson / toJsonStr now emit the v2 shape (`{ version: 2,
groups, segments: [...] }`) instead of `{ map: { name: {...} } }`.
ScreenMap::ParseJson is already bilingual, so:

  - C++ → JS WASM bridge keeps working (ledmapper reads v2 natively).
  - Round-trip test (toJson → ParseJson same flat_map) still passes:
    the parser dispatches on shape, the JSON shape just changed.
  - Any existing on-disk v1 JSON continues to load via the v1 path —
    we are not breaking third-party files in the wild.

Sample data converted:

  - examples/Fx/FxSdCard/data/screenmap.json — the legacy sidecar
    fallback path. The FLED happy path was already embedding v2 since
    PR #3074; this just makes the .rgb fallback exercise v2 too.
  - examples/Chromancer/screenmap.json.h — 4-segment inline JSON
    literal that the sketch feeds to ScreenMap::ParseJson at setup.
  - examples/Chromancer/output.json — output blob, same 4 segments.

Out of scope:

  - examples/Chromancer/gary_woos_wled_port/gary_woos_wled_ledmap.h
    uses `{"map": [array of indices]}` which is the WLED ledmap
    format, not a v1 ScreenMap. Coincidentally shares the "map" key
    name but the value type is wrong for a screenmap — left untouched.

Verification:

  bash test --cpp screenmap          → 1/1 pass
  bash test --cpp fx_video           → 1/1 pass
  bash test --examples FxSdCard      → compiles clean
  bash test --examples Chromancer    → compiles clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 05ba64d5-4d7c-43f4-9a15-5d6d7020c198

📥 Commits

Reviewing files that changed from the base of the PR and between 8d7af6d and 0921b52.

📒 Files selected for processing (4)
  • examples/Chromancer/output.json
  • examples/Chromancer/screenmap.json.h
  • examples/Fx/FxSdCard/data/screenmap.json
  • src/fl/math/screenmap.cpp.hpp

📝 Walkthrough

Walkthrough

ScreenMap::toJson is updated to emit a v2 JSON schema (version: 2, groups color map, segments array with id/pin/group fields) instead of the prior v1 map-keyed object. All shipped example screenmaps (Chromancer/output.json, Chromancer/screenmap.json.h, Fx/FxSdCard/data/screenmap.json) are regenerated to match the new schema.

Changes

ScreenMap v2 JSON Schema Migration

Layer / File(s) Summary
ScreenMap::toJson v2 emitter
src/fl/math/screenmap.cpp.hpp
Replaces v1 "map"-keyed JSON construction with v2 output: sets "version": 2, builds a "groups" object with palette-assigned colors cycled by insertion order, and emits a "segments" array where each entry carries id, "pin1", group, x/y arrays, and diameter.
Regenerated example screenmaps
examples/Chromancer/output.json, examples/Chromancer/screenmap.json.h, examples/Fx/FxSdCard/data/screenmap.json
All three example artifacts are rewritten to the v2 schema: version: 2, groups with per-group colors, and segments array with explicit id/pin/group metadata alongside geometry arrays.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3051: Adds v2 screenmap JSON parsing (ScreenMap::ParseJson with auto-detection) that consumes the same v2 schema this PR's serializer now emits.

Poem

🐇 Hoppin' through the JSON fields,
Segments now have id and pin,
version: 2 the map reveals,
Groups with colors tucked within!
No more flat map—arrays win! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: migrating ScreenMap serialization from v1 to v2 format and converting sample files, which is the core objective of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/143-v2-fastled

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.

@zackees
zackees merged commit 6594bb7 into master Jun 15, 2026
8 of 9 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 15, 2026
@zackees
zackees deleted the feat/143-v2-fastled branch August 21, 2026 19:15
zackees added a commit that referenced this pull request Sep 10, 2026
…3322) (#4278)

#3322's first complaint is that `pin` is documented in the screen-map envelope
and never read. That is true, and deliberate -- the parser says so. What the
issue does not say, and what turns this from a missing feature into a defect,
is what the *emitter* does with it.

`ScreenMap::toJson` wrote the literal `"pin1"` into every segment. That string
is the example value from the shape comment directly above the emitter,
copied into the code as data; the commit that added it (#3100) does not
mention `pin` at all.

So the round trip did not drop the field, it rewrote it. Measured on a
three-segment file before touching anything:

    in    a -> "pin1"    b -> "pin2"    c -> 7
    out   a -> "pin1"    b -> "pin1"    c -> "pin1"

Two of three segments come back on the wrong pin, and a numeric pin comes back
as a string. `examples/hydropack/data/*.json` are exactly that shape --
pin1/pin2/pin3 -- so this is a file in the tree, not a hypothetical.

Nothing is emitted now. Wrong is worse than absent here: a consumer reading a
rewritten pin mis-wires a strip with no way to tell, while a consumer reading
a missing optional key can see that it is missing. The parser ignores the key
either way, so nothing on this side changes.

Carrying the value through is the real fix and is #3322 proper -- it needs
somewhere on `ScreenMap` to put it and a decision about the `<int|str>` union,
which is what that issue is for. This stops making it worse in the meantime.

The test counts `"pin"` occurrences rather than looking for `"pin1"`, so
re-introducing a different constant fails it too; both mutations do.

One thing left alone and worth recording: the emitter also writes
`"diameter":-1.000` for a map with no diameter set, while the field's own
comment says "Only serialized if it's not > 0.0f". Same shape of problem,
different field, and changing it moves what the parser reads back.


Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant