13#include "fixed_vector.h"
14#include "math_macros.h"
17FASTLED_NAMESPACE_BEGIN
19ScreenMap ScreenMap::Circle(
int numLeds,
float cm_between_leds,
float cm_led_diameter) {
21 float circumference = numLeds * cm_between_leds;
22 float radius = circumference / (2 * PI);
24 for (
int i = 0; i < numLeds; i++) {
25 float angle = i * 2 * PI / numLeds;
26 float x = radius * cos(angle) * 2;
27 float y = radius * sin(angle) * 2;
28 screenMap[i] = {x, y};
30 screenMap.setDiameter(cm_led_diameter);
35void ScreenMap::ParseJson(
const char *jsonStrScreenMap,
37 FLArduinoJson::JsonDocument doc;
38 FLArduinoJson::deserializeJson(doc, jsonStrScreenMap);
39 auto map = doc[
"map"];
40 for (
auto kv : map.as<FLArduinoJson::JsonObject>()) {
41 auto segment = kv.value();
42 auto x = segment[
"x"];
43 auto y = segment[
"y"];
44 auto obj = segment[
"diameter"];
45 float diameter = -1.0f;
46 if (obj.is<
float>()) {
47 float d = obj.as<
float>();
54 for (uint16_t j = 0; j < n; j++) {
57 segmentMaps->insert(kv.key().c_str(), segment_map);
63 auto map = doc[
"map"].to<FLArduinoJson::JsonObject>();
64 for (
auto kv : segmentMaps) {
65 auto segment = map[kv.first].to<FLArduinoJson::JsonObject>();
66 auto x_array = segment[
"x"].to<FLArduinoJson::JsonArray>();
67 auto y_array = segment[
"y"].to<FLArduinoJson::JsonArray>();
68 for (uint16_t i = 0; i < kv.second.getLength(); i++) {
73 float diameter = kv.second.getDiameter();
74 if (diameter < 0.0f) {
77 if (diameter > 0.0f) {
78 segment[
"diameter"] = diameter;
84 FLArduinoJson::JsonDocument doc;
85 toJson(segmentMaps, &doc);
86 FLArduinoJson::serializeJson(doc, *jsonBuffer);