FastLED 3.9.15
Loading...
Searching...
No Matches
screenmap.h
Go to the documentation of this file.
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#include "fl/map.h"
10#include "fl/namespace.h"
11#include "fl/str.h"
12
13/* Screenmap maps strip indexes to x,y coordinates. This is used for FastLED Web
14 * to map the 1D strip to a 2D screen. Note that the strip can have arbitrary
15 * size. this was first motivated by the effort to port theChromancer project to
16 * FastLED for the browser.
17 */
18
19namespace fl {
20
21class Str;
22class JsonDocument;
23
24// ScreenMap screen map maps strip indexes to x,y coordinates for a ui
25// canvas in float format.
26// This class is cheap to copy as it uses smart pointers for shared data.
27class ScreenMap {
28 public:
29 static ScreenMap Circle(int numLeds, float cm_between_leds = 1.5f,
30 float cm_led_diameter = 0.5f,
31 float completion = 1.0f);
32
33 static ScreenMap DefaultStrip(int numLeds, float cm_between_leds = 1.5f,
34 float cm_led_diameter = 0.2f,
35 float completion = .9f) {
36 return Circle(numLeds, cm_between_leds, cm_led_diameter, completion);
37 }
38
39 ScreenMap() = default;
40
41 // is_reverse is false by default for linear layout
42 ScreenMap(uint32_t length, float mDiameter = -1.0f);
43
44 ScreenMap(const vec2f *lut, uint32_t length, float diameter = -1.0);
45
46 template <uint32_t N>
47 ScreenMap(const vec2f (&lut)[N], float diameter = -1.0)
48 : ScreenMap(lut, N, diameter) {}
49
50 ScreenMap(const ScreenMap &other);
51
52 const vec2f &operator[](uint32_t x) const;
53
54 void set(uint16_t index, const vec2f &p);
55
56 void addOffset(const vec2f &p);
57 void addOffsetX(float x);
58 void addOffsetY(float y);
59
60 vec2f &operator[](uint32_t x);
61
62 // TODO: change this name to setDiameterLed. Default should be .5f
63 // for 5 mm ws lense.
64 void setDiameter(float diameter);
65
66 // define the assignment operator
67 ScreenMap &operator=(const ScreenMap &other);
68
69 vec2f mapToIndex(uint32_t x) const;
70
71 uint32_t getLength() const;
72 // The diameter each point represents.
73 float getDiameter() const;
74
75 // Get the bounding box of all points in the screen map
76 vec2f getBounds() const;
77
78 static bool ParseJson(const char *jsonStrScreenMap,
80 Str *err = nullptr);
81
82 static bool ParseJson(const char *jsonStrScreenMap,
83 const char *screenMapName, ScreenMap *screenmap,
84 Str *err = nullptr);
85
86 static void toJsonStr(const FixedMap<Str, ScreenMap, 16> &,
87 Str *jsonBuffer);
88 static void toJson(const FixedMap<Str, ScreenMap, 16> &, JsonDocument *doc);
89
90 private:
91 static const vec2f &empty();
92 uint32_t length = 0;
93 float mDiameter = -1.0f; // Only serialized if it's not > 0.0f.
94 LUTXYFLOATPtr mLookUpTable;
95};
96
97} // namespace fl
int y
Definition Audio.ino:72
int x
Definition Audio.ino:71
static void toJsonStr(const FixedMap< Str, ScreenMap, 16 > &, Str *jsonBuffer)
ScreenMap & operator=(const ScreenMap &other)
void setDiameter(float diameter)
float mDiameter
Definition screenmap.h:93
void addOffsetY(float y)
void set(uint16_t index, const vec2f &p)
vec2f mapToIndex(uint32_t x) const
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f, float completion=1.0f)
Definition screenmap.cpp:21
uint32_t getLength() const
void addOffsetX(float x)
static void toJson(const FixedMap< Str, ScreenMap, 16 > &, JsonDocument *doc)
void addOffset(const vec2f &p)
static ScreenMap DefaultStrip(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.2f, float completion=.9f)
Definition screenmap.h:33
uint32_t length
Definition screenmap.h:92
ScreenMap()=default
static const vec2f & empty()
LUTXYFLOATPtr mLookUpTable
Definition screenmap.h:94
const vec2f & operator[](uint32_t x) const
static bool ParseJson(const char *jsonStrScreenMap, FixedMap< Str, ScreenMap, 16 > *segmentMaps, Str *err=nullptr)
Definition screenmap.cpp:51
vec2f getBounds() const
ScreenMap(const vec2f(&lut)[N], float diameter=-1.0)
Definition screenmap.h:47
float getDiameter() const
Definition str.h:388
Implements the FastLED namespace macros.
vec2< float > vec2f
Definition geometry.h:301
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
static FASTLED_NAMESPACE_BEGIN uint8_t const p[]
Definition noise.cpp:30