FastLED 3.9.7
Loading...
Searching...
No Matches
screenmap.h
1#pragma once
2
3#include <stdint.h>
4
5#include "fl/force_inline.h"
6#include "fl/lut.h"
7#include "fl/ptr.h"
8
9
10#include "fl/map.h"
11#include "fl/str.h"
12#include "fl/namespace.h"
13
14/* Screenmap maps strip indexes to x,y coordinates. This is used for FastLED Web
15 * to map the 1D strip to a 2D grid. Note that the strip can have arbitrary
16 * size. this was first motivated during the (attempted? Oct. 19th 2024) port of
17 * the Chromancer project to FastLED Web.
18 */
19
20namespace fl {
21
22class Str;
23class JsonDocument;
24
25// ScreenMap screen map maps strip indexes to x,y coordinates for a ui
26// canvas in float format.
27// This class is cheap to copy as it uses smart pointers for shared data.
28class ScreenMap {
29 public:
30 static ScreenMap Circle(int numLeds, float cm_between_leds = 1.5f,
31 float cm_led_diameter = 0.5f);
32
33 ScreenMap() = default;
34
35 // is_reverse is false by default for linear layout
36 ScreenMap(uint32_t length, float mDiameter = -1.0f);
37
38 ScreenMap(const pair_xy_float *lut, uint32_t length,
39 float diameter = -1.0);
40
41 template <uint32_t N>
42 ScreenMap(const pair_xy_float (&lut)[N], float diameter = -1.0)
43 : ScreenMap(lut, N, diameter) {}
44
45 ScreenMap(const ScreenMap &other);
46
47 const pair_xy_float &operator[](uint32_t x) const;
48
49 void set(uint16_t index, const pair_xy_float &p);
50
51 pair_xy_float &operator[](uint32_t x);
52
53 // TODO: change this name to setDiameterLed. Default should be .5f
54 // for 5 mm ws lense.
55 void setDiameter(float diameter);
56
57 // define the assignment operator
58 ScreenMap &operator=(const ScreenMap &other);
59
60 pair_xy_float mapToIndex(uint32_t x) const;
61
62 uint32_t getLength() const;
63 // The diameter each point represents.
64 float getDiameter() const;
65
66 static bool ParseJson(const char *jsonStrScreenMap,
68 Str *err = nullptr);
69
70 static bool ParseJson(const char *jsonStrScreenMap,
71 const char *screenMapName, ScreenMap *screenmap,
72 Str *err = nullptr);
73
74 static void toJsonStr(const FixedMap<Str, ScreenMap, 16> &,
75 Str *jsonBuffer);
76 static void toJson(const FixedMap<Str, ScreenMap, 16> &,
77 JsonDocument *doc);
78
79 private:
80 static const pair_xy_float &empty();
81 uint32_t length = 0;
82 float mDiameter = -1.0f; // Only serialized if it's not > 0.0f.
83 LUTXYFLOATPtr mLookUpTable;
84};
85
86} // namespace fl
Definition str.h:336
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16