FastLED 3.9.15
Loading...
Searching...
No Matches

◆ ParseJson() [2/2]

bool fl::ScreenMap::ParseJson ( const char * jsonStrScreenMap,
FixedMap< Str, ScreenMap, 16 > * segmentMaps,
Str * err = nullptr )
static

Definition at line 37 of file screenmap.cpp.

38 {
39#if !FASTLED_ENABLE_JSON
40 if (err) {
41 *err = "JSON not enabled";
42 }
43 return false;
44#else
45 JsonDocument doc;
46 Str _err;
47 if (!err) {
48 err = &_err;
49 }
50
51 bool ok = parseJson(jsonStrScreenMap, &doc, err);
52 if (!ok) {
53 FASTLED_WARN("Failed to parse json: " << err->c_str());
54 return false;
55 }
56 auto map = doc["map"];
57 for (auto kv : map.as<FLArduinoJson::JsonObject>()) {
58 auto segment = kv.value();
59 auto x = segment["x"];
60 auto y = segment["y"];
61 auto obj = segment["diameter"];
62 float diameter = -1.0f;
63 if (obj.is<float>()) {
64 float d = obj.as<float>();
65 if (d > 0.0f) {
66 diameter = d;
67 }
68 }
69 auto n = x.size();
70 ScreenMap segment_map(n, diameter);
71 for (uint16_t j = 0; j < n; j++) {
72 segment_map.set(j, pair_xy_float{x[j], y[j]});
73 }
74 segmentMaps->insert(kv.key().c_str(), segment_map);
75 }
76 return true;
77#endif
78}
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
ScreenMap()=default
long map(long x, long in_min, long in_max, long out_min, long out_max)
bool parseJson(const char *json, fl::JsonDocument *doc, Str *_error)
Definition json.cpp:6
pair_xy< float > pair_xy_float
Definition lut.h:24
#define FASTLED_WARN
Definition warn.h:7

References ScreenMap(), fl::StrN< SIZE >::c_str(), FASTLED_WARN, fl::FixedMap< Key, Value, N >::insert(), fl::parseJson(), set(), x, and y.

Referenced by ParseJson(), fl::FileSystem::readScreenMap(), fl::FileSystem::readScreenMaps(), and setup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: