Skip to content

feat(screenmap/channels): bridge ScreenMap and ChannelConfig via typed ArduinoPin (number | string) #3322

Open

Description

@zackees

Summary

Improve API fluidity between fl::ScreenMap (2D layout-per-strip) and fl::MultiChannelConfig / fl::ChannelConfig (per-strip hardware binding) by promoting the already-documented-but-unwired pin field on screen-map strip entries to a first-class typed value, and using it to bridge the two systems.

Cross-references: #3311 (the fl::Fled bundle format that carries BOTH fl::ScreenMap and fl::MultiChannelConfig as section payloads — the bridge defined here is what lets one bundle round-trip both halves coherently).


What is broken today

1. pin is documented in the screen-map JSON envelope but never read.

src/fl/math/screenmap.cpp.hpp documents the segment shape at two places:

// line 104
{ "id": "<unique>", "pin": <int|str>, "group": "<name>",
  "x": [...], "y": [...], "z": [...], ... }
// line 384
"segments": [ { "id": "<name>", "pin": "pin1", "group": "<name>",
                "x": [...], "y": [...], "diameter": ... } ]

But the only references in the parser to a "pin" key are the comments above and a hard-coded segmentObj.set("pin", fl::json(fl::string("pin1"))) in the V2 writer (line 428) — there is no read path, no field on ScreenMap to store it, and no public accessor. A user who writes "pin": "D0" in their JSON gets it silently dropped.

2. fl::ChannelConfig::pin is int, not a pin name.

src/fl/channels/config.h (lines 33, 103) types data pin and clock pin as plain int. Arduino sketches commonly write D0, A2, LED_BUILTIN — those are board-specific macros (mostly int on most platforms, but the resolution is non-trivial on a few cores). A typed pin that round-trips through JSON has to handle both forms.

3. ScreenMap and ChannelConfig have no shared key.

fl::Fled::screenMap() returns a fl::ScreenMap (coord LUT keyed by strip index). fl::Fled::channels() returns fl::MultiChannelConfig (vector of ChannelConfig keyed by add-order). They are two independent enumerations of "strips". A user who loads a .fled bundle has no canonical way to ask "which screen-map segment corresponds to the channel I just added at pin D5?" — they have to match by ordinal, and one re-order in either file silently shears the binding.

This is the seam that #3311 carves around but doesn't close. If the bundle is supposed to be "drop one file, sketch self-instantiates," the bridge between coord layout and hardware binding has to be implicit.


Proposal

A. Type pin as a small union variant

// src/fl/sys/arduino_pin.h (new)
namespace fl {
// A pin reference that accepts either a numeric GPIO number or an
// Arduino-style symbolic name ("D0", "A2", "LED_BUILTIN"). Resolves to
// an integer pin number on the active platform via a platform-provided
// resolveArduinoPin(string_view) -> optional<int>.
class ArduinoPin {
public:
    ArduinoPin() FL_NOEXCEPT = default;
    ArduinoPin(int gpio) FL_NOEXCEPT;          // numeric form
    ArduinoPin(string_view name) FL_NOEXCEPT;  // symbolic form
    ArduinoPin(const char* name) FL_NOEXCEPT;  //   convenience

    bool isSymbolic() const FL_NOEXCEPT;
    int gpio() const FL_NOEXCEPT;              // resolved (cached); -1 if unresolved
    string_view symbol() const FL_NOEXCEPT;    // raw form (for round-tripping)

    bool resolve() FL_NOEXCEPT;                // try platform resolver; idempotent

    // JSON round-trip: emits {"pin": 5} or {"pin": "D0"} depending on source.
    void toJson(fl::json* out) const FL_NOEXCEPT;
    static bool fromJson(const fl::json& v, ArduinoPin* out, string* err) FL_NOEXCEPT;
};
}

Notes:

  • Resolution is opt-in. A bundle parsed from disk holds "D0" until a sketch on a known platform calls .resolve() — which lets WASM / studio tooling keep the symbolic form.
  • The resolver lives in platforms/<arch>/pin_names.cpp (one table per board). Most platforms already have macros; this just exposes the inverse map.
  • Backwards compatible: integer literals deserialize as before; old code reading pin as int keeps compiling via implicit conversion.

B. Wire pin into both ScreenMap entries and ChannelConfig

// src/fl/math/screenmap.h — add the field
class ScreenMap {
  ...
  // Optional pin binding for the strip this map describes. Default: empty
  // (no binding — legacy / ordinal-matched bundles).
  fl::optional<ArduinoPin> pin() const FL_NOEXCEPT;
  void setPin(ArduinoPin p) FL_NOEXCEPT;
  ...
};
// src/fl/channels/config.h — promote pin
struct ClocklessChipset {
    ArduinoPin pin;          // was: int
    ...
};
struct SpiChipsetConfig {
    ArduinoPin dataPin;      // was: int
    ArduinoPin clockPin;     // was: int
    ...
};

C. Bridge ScreenMap and ChannelConfig by pin

// helper alongside MultiChannelConfig (config.h:366)
namespace fl {
// Match a ScreenMap to one of the channels by pin, returning nullptr
// when no channel binds the same pin (or when either side has no pin).
ChannelConfigPtr findChannelForScreenMap(
    const MultiChannelConfig& cfg, const ScreenMap& sm) FL_NOEXCEPT;
}

Once both sides carry the same ArduinoPin value, fl::Fled::load(...) can wire them up implicitly — FastLED.load(fled) walks MultiChannelConfig, calls addLeds<>(...) per channel, then matches the ScreenMap segment by pin and broadcasts via EngineEvents::onCanvasUiSet. No ordinal coupling.


Alternatives considered

  1. Match by "id" strings instead of pin. Cleaner separation (UI label vs hardware), but doubles the source of truth — users have to remember to keep id consistent across two files. pin is the natural primary key for "the same physical strip."
  2. A new binding field on each strip entry that names the channel by index. Brittle on reorder. Worse for .fled portability.
  3. Embed the channel config inside the screen map. Conflates two concerns; breaks the "passive layout / active hardware" split that feat(fl/fled): create new fl::Fled bundle subsystem (value + runner + section accessors) under src/fl/fled/ #3311 deliberately keeps.

pin-as-bridge is the lightest-weight option that maps onto FastLED's existing mental model (every strip has a pin) without inventing a new key.


Out of scope (track separately if pursued)

  • Multi-pin chipsets (SPI clock + data) — the bridge resolves by data pin only in the first pass; SPI strips that need clock-pin disambiguation use the id fallback.
  • Pin-name resolution on platforms FastLED doesn't currently know about — those land per-platform PRs against src/platforms/<arch>/pin_names.cpp.
  • WASM/studio side of ArduinoPin rendering (the UI keeps the symbolic form in the document; the resolver runs on-target only).

Acceptance

  • fl::ArduinoPin type lives at src/fl/sys/arduino_pin.h and round-trips through JSON (int <-> string).
  • fl::ScreenMap exposes pin() / setPin() and the parser reads "pin" (currently dropped silently).
  • fl::ClocklessChipset::pin and fl::SpiChipsetConfig::dataPin / clockPin are ArduinoPin (with implicit int ctor so existing call sites compile).
  • findChannelForScreenMap(MultiChannelConfig, ScreenMap) returns the right channel when pins match.
  • A .fled bundle round-trips: load -> FastLED.load(fled) -> channels addLeds-ed AND screen maps bound, no ordinal coupling.
  • Tests cover: numeric 5, symbolic "D0", missing pin (legacy ordinal fallback), pin present on screen-map side only (warning), pin present on channels side only (warning), mismatch (warning).

Why this is on the critical path for #3311

Without the bridge defined here, fl::Fled::load(fled) in #3311 either (a) silently matches channels and screen maps by index — which works only as long as the JSON author keeps the two arrays in lock-step — or (b) refuses to bind screen maps automatically, pushing the work back to the sketch (which defeats the "drop one file" promise). A typed pin on both sides closes that gap before the bundle format ships.

Activity

  1. zackees commented on Jun 20, 2026

    @zackees
    MemberAuthor

    Scope update — bridge lives behind FastLED.load(fled) only, free functions, opt-in resolver

    What changes vs the original proposal

    1. No type promotion of ChannelConfig::pin. int pin stays int pin on fl::ClocklessChipset / fl::SpiChipsetConfig. No source-level change to the channels API, no implicit-conversion ctor needed, no widening of MultiChannelConfig's footprint.
    2. No new field on fl::ScreenMap. The screen-map parser stays as it is. The "pin" JSON key gets read by the bundle loader, not by ScreenMap::ParseJson.
    3. The bridge is a private detail of FastLED.load(fled). Free functions in src/fl/fled/detail/pin_bridge.cpp.hpp (or similar) do the work. They take the parsed fl::Fled, walk the screen-map segments + channel configs, match by pin, and dispatch the setScreenMap broadcast. Nothing on the public ScreenMap / ChannelConfig surface area moves.

    Why this shape

    • Channels API is stable surface — the type change cascades through every addLeds<...>(int, ...) call site, every chipset header, every test. Not worth it for a feature that today lives only inside the .fled loader.
    • The screen map is value-typed and serialised by other paths (web UI, manual JSON authoring). Keeping its public schema unchanged means existing consumers keep working.
    • A self-contained loader module is easy to unit test with no globals.

    Free-function shape

    // src/fl/fled/detail/pin_bridge.h
    namespace fl::detail {
    
    // Resolves an Arduino pin token from the screen-map segment.
    //
    // Accepts either a numeric JSON value (returns it directly) or a symbolic
    // string like "D0" / "A2" / "LED_BUILTIN". Resolution uses Arduino.h's
    // platform pin macros (included via FL_HAS_INCLUDE — see below).
    //
    // On missing or unknown symbol returns 0 and FL_WARNs the user. Returning
    // 0 is the documented fallback so a misconfigured bundle never crashes
    // the sketch — it just lights the wrong strip or no strip.
    struct PinResolveResult {
        int pin;             // resolved GPIO number; 0 on fallback
        bool resolved;       // true when input was numeric or a known macro
    };
    
    PinResolveResult resolvePinToken(const fl::json& token) FL_NOEXCEPT;
    PinResolveResult resolvePinName(fl::string_view name) FL_NOEXCEPT;
    
    // Walk a parsed bundle and return per-segment resolved pins (or none).
    // Output is ordered to match `bundle.screenMap()` segment order.
    fl::vector<fl::optional<int>>
    extractScreenMapPins(const fl::Fled& bundle) FL_NOEXCEPT;
    
    // Given resolved screen-map pins and a MultiChannelConfig, return the
    // channel index that binds each screen-map segment. fl::nullopt entries
    // mean "no matching channel" (warning, not error).
    fl::vector<fl::optional<fl::size>>
    matchScreenMapsToChannels(
        fl::span<const fl::optional<int>> screen_map_pins,
        const fl::MultiChannelConfig& channels) FL_NOEXCEPT;
    
    }  // namespace fl::detail

    FastLED.load(fled) is the only caller. It walks channels first (calls FastLED.add(*cfg)), then runs extractScreenMapPins + matchScreenMapsToChannels to dispatch controller.setScreenMap(...) for the matched pairs. Unmatched segments warn and fall back to ordinal binding for backwards compat with bundles that lack "pin".

    Arduino.h include safety

    // pin_bridge.cpp.hpp
    #if defined(FL_HAS_INCLUDE) && FL_HAS_INCLUDE(<Arduino.h>)
      #include <Arduino.h>
    #endif
    
    namespace {
    
    constexpr int kFallbackPin = 0;  // documented fallback when a symbolic
                                     // pin name resolves to nothing.
    
    int macro_D0() FL_NOEXCEPT {
    #ifdef D0
        return D0;
    #else
        FL_WARN("ArduinoPin: macro D0 is not defined on this platform; "
                "defaulting to GPIO 0. Author bundles with numeric pins on "
                "this target to silence this warning.");
        return kFallbackPin;
    #endif
    }
    
    int macro_A0() FL_NOEXCEPT {
    #ifdef A0
        return A0;
    #else
        FL_WARN("ArduinoPin: macro A0 is not defined on this platform; "
                "defaulting to GPIO 0. ...");
        return kFallbackPin;
    #endif
    }
    
    // ... same shape for the rest of the well-known names.
    
    }  // namespace

    Rules:

    • FL_HAS_INCLUDE(<Arduino.h>) guards the include — keeps the loader buildable on stub / host-test targets where Arduino.h isn't on the include path.
    • Each pin macro has its own #ifdef … #else FL_WARN … return 0 #endif block, so a platform that defines D0 but not A0 works partially without breaking other names.
    • The warning fires once per missing macro per process (use a static bool warned inside each helper) to avoid log spam when a bundle references the same unknown pin many times.
    • 0 is the documented fallback, not -1. Returning -1 triggered subtle bugs in callers that did if (pin >= 0); 0 is a valid (if often wrong) GPIO and lights the failure mode early.

    Unit testability

    All three free functions take parsed values (no Arduino runtime, no global state). Tests live at tests/fl/fled/pin_bridge.cpp and exercise:

    • resolvePinToken(json(5)) → {pin: 5, resolved: true}
    • resolvePinToken(json("D0")) → on a host build where D0 is undefined, {pin: 0, resolved: false} + a single FL_WARN
    • resolvePinName("LED_BUILTIN") → same fallback semantics
    • matchScreenMapsToChannels({5, 6, fl::nullopt}, channels_with_pins{5, 6, 7}) → {0, 1, fl::nullopt}
    • matchScreenMapsToChannels with a pin that matches two channels → matches the first and warns
    • extractScreenMapPins on a bundle with mixed numeric + symbolic + missing pins — returns the expected vector<optional<int>>

    No Arduino mock, no platform faking. The fallback-to-0 path is exactly what test coverage validates, since the host build is by definition a platform where D0 etc. are undefined.

    Updated acceptance

    • fl/fled/detail/pin_bridge.{h,cpp.hpp} exists with the three free functions above.
    • Arduino.h include is guarded by FL_HAS_INCLUDE(<Arduino.h>).
    • Every Arduino pin macro reference (D0, D1, ..., A0, A1, ..., LED_BUILTIN) is wrapped in #ifdef … #else FL_WARN + return 0 #endif.
    • FL_WARN for an unknown macro fires once per macro per process, not per call.
    • FastLED.load(fled) (in feat(fl/fled): create new fl::Fled bundle subsystem (value + runner + section accessors) under src/fl/fled/ #3311) calls into pin_bridge only — no public ScreenMap / ChannelConfig API changes land in this issue.
    • Unit tests under tests/fl/fled/pin_bridge.cpp cover the matrix above; host builds (which lack Arduino.h) exercise the fallback path.
    • Round-trip test: bundle with {"pin": "D5"} segments + ChannelConfig{pin=5, ...} channels → FastLED.load(fled) binds the matched pair, no ordinal coupling.

    Out of scope (still)

    • Promoting ChannelConfig::pin to a typed ArduinoPin — explicitly dropped. If/when a future caller outside the .fled loader needs the typed form, we revisit.
    • Adding pin() accessor to ScreenMap — explicitly dropped. The bundle loader is the only caller that needs the value, and it reads it directly from the fl::json segment view.
    • Per-platform pin-name tables beyond what Arduino.h's macros already expose — out of scope for the first cut. If a board doesn't define a name, we warn and fall back to 0; users author bundles with numeric pins for that target.
  2. zackees commented on Jun 20, 2026

    @zackees
    MemberAuthor

    Scope update 2 — also auto-bind when screenmap / channels are loaded separately (WASM-only)

    The previous scope-update assumed the only path was FastLED.load(fled) (bundle-driven). Add a second path: separate FastLED.load(screenmap) / FastLED.load(channelconfig) calls also have to auto-bind their counterpart once both halves arrive. Driven by an event listener — and WASM-only, so embedded / native builds don't carry the matchmaker code.

    Why WASM-only

    • Embedded sketches that call FastLED.addLeds<...>(pin, leds) already have the controller in hand and can call .setScreenMap(...) directly. They never need the matchmaker.
    • The studio / web UI is the one that streams screenmap and channels in independent loads (often out of order, often in response to user edits). That's WASM.
    • Gating behind FL_PLATFORM_WASM (or whatever the active guard is — verify the macro name before landing) keeps the matchmaker out of every other binary so the esp32dev / lpc845brk / teensy size budgets don't move at all.

    Event-driven matchmaker shape

    fl::EngineEvents already exposes the right hook surface:

    • EngineEvents::Listener::onCanvasUiSet(strip, screenmap) — fires when a controller has a screenmap bound (already exists; controller.setScreenMap(...) broadcasts it).

    What's missing is the symmetric "a controller was just added" and "a free-standing screenmap was just loaded but not bound yet" signals. Two new listener callbacks (or one new event each) — names tentative, finalise during implementation:

    • onControllerAdded(strip) — fired from FastLED.add(channel_cfg) after the controller is registered, before any auto-binding.
    • onScreenMapLoaded(screenmap) — fired from FastLED.load(screenmap) when no .fled bundle wrapped it. Carries the segment-level "pin" token along with the value (since fl::ScreenMap itself stays pin-less per the previous scope update — the loader pulls the pin off the JSON and carries it on the event).
    // WASM-only — gated at translation-unit level
    #if FL_PLATFORM_WASM
    
    namespace fl::detail {
    
    class AutoBindPinMatchmaker : public EngineEvents::Listener {
    public:
        AutoBindPinMatchmaker() FL_NOEXCEPT {
            EngineEvents::addListener(this);
        }
    
        // New event hook: a free-standing screenmap arrived. Stash it
        // keyed by pin; if a matching controller already exists, bind now.
        void onScreenMapLoaded(int pin, ScreenMap sm) FL_NOEXCEPT override {
            if (auto* strip = findControllerForPin(pin)) {
                strip->setScreenMap(sm);   // broadcasts onCanvasUiSet
                return;
            }
            mPending.emplace(pin, fl::move(sm));
        }
    
        // New event hook: a controller was just registered. If a pending
        // screenmap was waiting for this pin, drain it.
        void onControllerAdded(CLEDController* strip, int pin) FL_NOEXCEPT override {
            auto it = mPending.find(pin);
            if (it == mPending.end()) return;
            strip->setScreenMap(it->second);
            mPending.erase(it);
        }
    
    private:
        fl::flat_map<int, ScreenMap> mPending;
    };
    
    inline AutoBindPinMatchmaker* installMatchmaker() FL_NOEXCEPT {
        static AutoBindPinMatchmaker s;   // constructed once, registers in ctor
        return &s;
    }
    
    }  // namespace fl::detail
    
    #endif  // FL_PLATFORM_WASM

    The matchmaker is one singleton that lives in fl/fled/detail/ (WASM build only). Its construction registers it on the EngineEvents bus. From there it's pure event-driven; no globals beyond the listener pointer.

    What changes in the public API

    Almost nothing. FastLED.load(screenmap) and FastLED.load(channelconfig) already need to exist for #3311's "passive value → mutation nexus" split. They just gain WASM-only side effects:

    • FastLED.load(screenmap) on WASM emits onScreenMapLoaded(pin, screenmap) (pulling the pin off the JSON that produced the value — see the previous scope update's extractScreenMapPins).
    • FastLED.load(channelconfig) on WASM calls addLeds<...>(...) as before, then emits onControllerAdded(strip, pin).

    Embedded builds get neither emission. Same code path, different translation-unit gate.

    What changes in FastLED.load(fled)

    The bundle path becomes a thin layer over the matchmaker:

    // Conceptual — WASM and embedded share this skeleton
    void CFastLED::load(const fl::Fled& fled) {
        if (auto chs = fled.channels())  for (auto& cfg : chs->mChannels) load(*cfg);
        if (auto sm  = fled.screenMap())                                  load(*sm);
    }

    On WASM the matchmaker observes the two streams and binds. On embedded the bundle path keeps its current explicit-ordinal binding (since the matchmaker isn't compiled in). Same one-call ergonomics either way, no #ifs leaking into user code.

    Test plan

    Host tests already exercise the WASM matchmaker because the gate is one macro:

    • WASM build: load screenmap-then-channels — binds.
    • WASM build: load channels-then-screenmap — binds.
    • WASM build: load three screenmaps and two channels — binds two, the third stays pending (no error).
    • WASM build: load a screenmap whose pin doesn't match any channel — stays pending until a channel with that pin shows up, or never (no error, no log spam).
    • Embedded build (#if FL_PLATFORM_WASM false): the matchmaker symbol must not appear in the linked binary. Add a nm | grep AutoBindPinMatchmaker assertion to the size-check workflow so this can't regress silently.

    Updated acceptance (delta on top of the previous comment)

    • Matchmaker lives in fl/fled/detail/pin_matchmaker.{h,cpp.hpp} (or similar), behind #if FL_PLATFORM_WASM.
    • Two new EngineEvents::Listener callbacks (or two new event broadcasts): onScreenMapLoaded(pin, screenmap) and onControllerAdded(strip, pin). The exact signatures are an implementation detail; finalise during PR review.
    • FastLED.load(screenmap) on WASM emits onScreenMapLoaded(...); embedded builds don't.
    • FastLED.load(channelconfig) on WASM emits onControllerAdded(...); embedded builds don't.
    • Host / WASM tests cover both load orders and the "no match" case.
    • Embedded binary-size workflows (check_esp32_size, check_teensy*_size, etc.) stay flat — the matchmaker compiles out cleanly.

    Out of scope (still / new)

    • A unified "deferred bind registry" across both halves on embedded — explicitly dropped. Embedded sketches that need this can call controller.setScreenMap(...) themselves; the bundle loader already serves the common path.
    • Sub-screenmap bindings (one screenmap segment mapping to one channel inside a multi-strip channel) — out of scope for v1; the matchmaker keys on the data pin and treats each ChannelConfig as one binding target.
  3. zackees commented on Jun 20, 2026

    @zackees
    MemberAuthor

    Correction: the macro is FL_IS_WASM (defined at src/platforms/wasm/is_wasm.h:20), not FL_PLATFORM_WASM (doesn't exist). Matches the codebase's broader FL_IS_* platform-detection convention.

    The matchmaker gate in the previous comment should read:

    #if FL_IS_WASM
    // AutoBindPinMatchmaker + the two new EngineEvents emissions live here
    #endif

    Same in every other gating block referenced earlier in this issue.

  4. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Deferred under the active bug-burn-down policy after validating the latest scope against current master.

    Current evidence:

    The current issue has three incompatible designs in one thread (public typed pin, private Fled bridge, and WASM event-driven matchmaker), and its required caller no longer exists. Implementing any one without an authoritative scope choice would manufacture a new public architecture.

    Restart criteria:

    1. Choose one authoritative design and rewrite the issue acceptance to remove the superseded alternatives.
    2. Decide whether the post-refactor(fl/fled): focus on header/json/blob/objects + FledBuilder + full FLED_FORMAT.md spec coverage (#3311) #3334 Fled API will regain any CFastLED::load* mutation surface; if not, close this issue as obsolete.
    3. If the WASM matchmaker is retained, split the engine-event additions, pin-token parser, and matchmaker/load-order integration into bounded child issues.
    4. Define safe unknown-symbol behavior; the proposed fallback to valid GPIO 0 should be reconsidered because it can drive unintended hardware.
    5. Remove deferred only when the chosen caller and integration contract exist.

    The issue remains open as the design record and is excluded from the actionable queue while labeled deferred.

  5. added
    deferred
    on Aug 20, 2026
  6. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Your defect 1 has teeth: the emitter was rewriting pins, not dropping them (#4278)

    1. pin is documented in the screen-map JSON envelope but never read.

    A user who writes "pin": "D0" in their JSON gets it silently dropped.

    True, and the parser says so deliberately. What is worse is the other half you noted in passing — the hard-coded segmentObj.set("pin", fl::json(fl::string("pin1"))) at line 474.

    That string is the example value from the shape comment directly above the emitter, copied into the code as data. The commit that introduced it (#3100) does not mention pin anywhere in its message; it came in as part of matching the v2 shape.

    So the round trip does not drop the field, it rewrites it. Measured before touching anything:

    segment in out
    a "pin1" "pin1"
    b "pin2" "pin1"
    c 7 "pin1"

    Two of three segments come back on the wrong pin, and a numeric pin comes back as a string. examples/hydropack/data/el-shapes-triangles-wire.json is exactly that shape — pin1/pin2/pin3 — so a file in this tree loses its wiring on a round trip today.

    #4278 stops the fabrication, and deliberately does not do more

    Nothing is emitted now. Wrong is worse than absent: a consumer reading a rewritten pin mis-wires a strip with no way to tell, while a missing optional key is visible. FastLED's parser ignores the key either way.

    Carrying the value through is this issue, not that PR. It needs somewhere on ScreenMap to store it and a decision about the <int|str> union — and screenmap.h currently forward-declares fl::string rather than including it (the include is annotated at 129.4 ms), so even the storage question has a cost attached. That is a design call, and it is yours.

    One aside from the same emitter, recorded rather than fixed: it 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.

  7. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    The second sentinel in the same emitter is gone too (#4282)

    #4278 recorded this and left it: alongside the fabricated pin, ScreenMap::toJson writes "diameter":-1.000 for a map with no diameter, while the field's own comment asks for it to be skipped.

    float mDiameter = -1.0f; // Only serialized if it's not > 0.0f.

    -1 is the "unset" sentinel. Writing it out publishes an impossible physical size and makes every consumer responsible for knowing FastLED's sentinel. One step milder than the pin — that one was wrong (pin2 came back as pin1), this is the real internal value that simply should not leave the process.

    Omitting round-trips identically, which is what makes it safe rather than a judgement call: both parser paths already default an absent key to -1 (screenmap.cpp.hpp:206 for v2, :364 for v1). The test walks one segment with a diameter and one without through toJsonStr → ParseJson and checks both survive.

    The comment had its sense inverted — "Only serialized if it's not > 0.0f" — which is presumably how the writer came to do the opposite.

    That is both emitter defects this issue's first section led to. What remains for #3322 proper is unchanged: carrying pin through needs somewhere on ScreenMap to store it and a decision about the <int|str> union, and screenmap.h forward-declares fl::string rather than including it (annotated at 129.4 ms), so even the storage question has a cost attached.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    deferred

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions