MCPcopy Create free account
hub / github.com/FastLED/FastLED / parseV2SegmentArray

Function parseV2SegmentArray

src/fl/math/screenmap.cpp.hpp:114–184  ·  view source on GitHub ↗

Helper: parse a v2 screenmap document into the flat segmentMaps. v2 shape (see ledmapper #92): { "version": 2, // optional, explicit "groups": { " ": { "color": "...", ... } }, // optional, ignored by firmware "segments": [ { "id": " ", "pin": , "group": " ", "x": [...], "y": [...], "z": [...], // z optional "parent": " ", "o

Source from the content-addressed store, hash-verified

112// flat_map; they're UI/wiring metadata the editor and video tools care about.
113// `z` is dropped (firmware-side ScreenMap is 2D today).
114static bool parseV2SegmentArray(const fl::json& segmentsArr,
115 fl::flat_map<string, ScreenMap> *segmentMaps,
116 string *err) FL_NOEXCEPT {
117 if (!segmentsArr.has_value() || !segmentsArr.is_array()) {
118 *err = "v2 'segments' is not an array";
119 return false;
120 }
121
122 auto arrPtr = segmentsArr.as_array();
123 if (!arrPtr) {
124 *err = "v2 'segments' array could not be read";
125 return false;
126 }
127
128 for (const auto& elem : *arrPtr) {
129 if (!elem) {
130 *err = "v2 segment is null";
131 return false;
132 }
133 fl::json segVal(elem);
134 if (!segVal.has_value() || !segVal.is_object()) {
135 *err = "v2 segment is not an object";
136 return false;
137 }
138
139 // Required: id
140 if (!segVal.contains("id") || !segVal["id"].has_value()) {
141 *err = "v2 segment missing 'id'";
142 return false;
143 }
144 auto idOpt = segVal["id"].as_string();
145 if (!idOpt) {
146 *err = "v2 segment 'id' is not a string";
147 return false;
148 }
149 string id = *idOpt;
150
151 // Required: x
152 if (!segVal.contains("x") || !segVal["x"].has_value() || !segVal["x"].is_array()) {
153 *err = "v2 segment '" + id + "' missing or invalid 'x' array";
154 return false;
155 }
156 fl::vector<float> x_array = jsonArrayToFloatVector(segVal["x"]);
157
158 // Required: y
159 if (!segVal.contains("y") || !segVal["y"].has_value() || !segVal["y"].is_array()) {
160 *err = "v2 segment '" + id + "' missing or invalid 'y' array";
161 return false;
162 }
163 fl::vector<float> y_array = jsonArrayToFloatVector(segVal["y"]);
164
165 // Optional: diameter (not in canonical v2 but accepted as a backward-compat
166 // hint when present; otherwise the per-group `diameter` could be wired here
167 // in a future iteration).
168 float diameter = -1.0f;
169 if (segVal.contains("diameter") && segVal["diameter"].has_value()) {
170 auto diameterOpt = segVal["diameter"].as_float();
171 if (diameterOpt) {

Callers 1

ParseJsonMethod · 0.85

Calls 10

jsonArrayToFloatVectorFunction · 0.85
has_valueMethod · 0.45
is_arrayMethod · 0.45
as_arrayMethod · 0.45
is_objectMethod · 0.45
containsMethod · 0.45
as_stringMethod · 0.45
as_floatMethod · 0.45
sizeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected