22 float cm_led_diameter) {
24 float circumference = numLeds * cm_between_leds;
25 float radius = circumference / (2 *
PI);
27 for (
int i = 0; i < numLeds; i++) {
28 float angle = i * 2 *
PI / numLeds;
29 float x = radius * cos(angle) * 2;
30 float y = radius * sin(angle) * 2;
39#if !FASTLED_ENABLE_JSON
41 *err =
"JSON not enabled";
51 bool ok =
parseJson(jsonStrScreenMap, &doc, err);
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>();
71 for (uint16_t j = 0; j < n; j++) {
74 segmentMaps->
insert(kv.key().c_str(), segment_map);
81 const char *screenMapName,
ScreenMap *screenmap,
83#if !FASTLED_ENABLE_JSON
85 *err =
"JSON not enabled";
90 bool ok =
ParseJson(jsonStrScreenMap, &segmentMaps, err);
94 if (segmentMaps.
size() == 0) {
97 if (segmentMaps.
has(screenMapName)) {
98 *screenmap = segmentMaps[screenMapName];
101 Str _err =
"ScreenMap not found: ";
102 _err.
append(screenMapName);
114#if !FASTLED_ENABLE_JSON
118 auto map = doc[
"map"].to<FLArduinoJson::JsonObject>();
119 for (
auto kv : segmentMaps) {
120 auto segment = map[kv.first].to<FLArduinoJson::JsonObject>();
121 auto x_array = segment[
"x"].to<FLArduinoJson::JsonArray>();
122 auto y_array = segment[
"y"].to<FLArduinoJson::JsonArray>();
123 for (uint16_t i = 0; i < kv.second.getLength(); i++) {
128 float diameter = kv.second.getDiameter();
129 if (diameter < 0.0f) {
132 if (diameter > 0.0f) {
133 segment[
"diameter"] = diameter;
141#if !FASTLED_ENABLE_JSON
145 toJson(segmentMaps, &doc);
192 return screen_coords;
222 if (
this != &other) {
unsigned int xy(unsigned int x, unsigned int y)
Pair< bool, iterator > insert(const Key &key, const Value &value, InsertResult *result=nullptr)
bool has(const Key &it) const
constexpr size_t size() const
static void toJsonStr(const FixedMap< Str, ScreenMap, 16 > &, Str *jsonBuffer)
ScreenMap & operator=(const ScreenMap &other)
void setDiameter(float diameter)
uint32_t getLength() const
static void toJson(const FixedMap< Str, ScreenMap, 16 > &, JsonDocument *doc)
static const pair_xy_float & empty()
const pair_xy_float & operator[](uint32_t x) const
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f)
LUTXYFLOATPtr mLookUpTable
static bool ParseJson(const char *jsonStrScreenMap, FixedMap< Str, ScreenMap, 16 > *segmentMaps, Str *err=nullptr)
void set(uint16_t index, const pair_xy_float &p)
pair_xy_float mapToIndex(uint32_t x) const
float getDiameter() const
Str & append(const char *str)
const char * c_str() const
Implements the FastLED namespace macros.
bool parseJson(const char *json, fl::JsonDocument *doc, Str *_error)
pair_xy< float > pair_xy_float
LUT< pair_xy_float > LUTXYFLOAT
void toJson(const fl::JsonDocument &doc, Str *jsonBuffer)
Implements a simple red square effect for 2D LED grids.
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]