FastLED 3.9.15
Loading...
Searching...
No Matches
screenmap.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stdint.h"
4
5#include "fl/force_inline.h"
6#include "fl/lut.h"
7#include "fl/memory.h"
8
9#include "fl/map.h"
10#include "fl/namespace.h"
11#include "fl/str.h"
12#include "fl/json.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 screen. Note that the strip can have arbitrary
16 * size. this was first motivated by the effort to port theChromancer project to
17 * FastLED for the browser.
18 */
19
20 // CONVERT JSON TO JSON2
21 // DON'T USE JSON
22
23namespace fl {
24
25class string;
26class Json;
27
28// Forward declaration for internal helper function
29fl::vector<float> jsonArrayToFloatVector(const fl::Json& jsonArray);
30
31// ScreenMap screen map maps strip indexes to x,y coordinates for a ui
32// canvas in float format.
33// This class is cheap to copy as it uses smart pointers for shared data.
34class ScreenMap {
35 public:
36 static ScreenMap Circle(int numLeds, float cm_between_leds = 1.5f,
37 float cm_led_diameter = 0.5f,
38 float completion = 1.0f);
39
40 static ScreenMap DefaultStrip(int numLeds, float cm_between_leds = 1.5f,
41 float cm_led_diameter = 0.2f,
42 float completion = .9f) {
43 return Circle(numLeds, cm_between_leds, cm_led_diameter, completion);
44 }
45
46 ScreenMap() = default;
47
48 // is_reverse is false by default for linear layout
49 ScreenMap(u32 length, float mDiameter = -1.0f);
50
51 ScreenMap(const vec2f *lut, u32 length, float diameter = -1.0);
52
53 template <u32 N>
54 ScreenMap(const vec2f (&lut)[N], float diameter = -1.0)
55 : ScreenMap(lut, N, diameter) {}
56
57 ScreenMap(const ScreenMap &other);
58 ScreenMap(ScreenMap&& other);
59
60 const vec2f &operator[](u32 x) const;
61
62 void set(u16 index, const vec2f &p);
63
64 void addOffset(const vec2f &p);
65 void addOffsetX(float x);
66 void addOffsetY(float y);
67
68 vec2f &operator[](u32 x);
69
70 // TODO: change this name to setDiameterLed. Default should be .5f
71 // for 5 mm ws lense.
72 void setDiameter(float diameter);
73
74 // define the assignment operator
75 ScreenMap &operator=(const ScreenMap &other);
77
78 vec2f mapToIndex(u32 x) const;
79
80 u32 getLength() const;
81 // The diameter each point represents.
82 float getDiameter() const;
83
84 // Get the bounding box of all points in the screen map
85 vec2f getBounds() const;
86
87 static bool ParseJson(const char *jsonStrScreenMap,
89 string *err = nullptr);
90
91 static bool ParseJson(const char *jsonStrScreenMap,
92 const char *screenMapName, ScreenMap *screenmap,
93 string *err = nullptr);
94
95 static void toJsonStr(const fl::fl_map<string, ScreenMap> &,
96 string *jsonBuffer);
97 static void toJson(const fl::fl_map<string, ScreenMap> &, fl::Json *doc);
98
99 private:
100 static const vec2f &empty();
101 u32 length = 0;
102 float mDiameter = -1.0f; // Only serialized if it's not > 0.0f.
103 LUTXYFLOATPtr mLookUpTable;
104};
105
106} // namespace fl
int y
Definition simple.h:93
int x
Definition simple.h:92
static void toJson(const fl::fl_map< string, ScreenMap > &, fl::Json *doc)
static bool ParseJson(const char *jsonStrScreenMap, fl::fl_map< string, ScreenMap > *segmentMaps, string *err=nullptr)
Definition screenmap.cpp:82
ScreenMap & operator=(const ScreenMap &other)
void setDiameter(float diameter)
float mDiameter
Definition screenmap.h:102
void addOffsetY(float y)
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f, float completion=1.0f)
Definition screenmap.cpp:52
void set(u16 index, const vec2f &p)
void addOffsetX(float x)
void addOffset(const vec2f &p)
const vec2f & operator[](u32 x) const
static ScreenMap DefaultStrip(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.2f, float completion=.9f)
Definition screenmap.h:40
static void toJsonStr(const fl::fl_map< string, ScreenMap > &, string *jsonBuffer)
ScreenMap()=default
static const vec2f & empty()
vec2f mapToIndex(u32 x) const
LUTXYFLOATPtr mLookUpTable
Definition screenmap.h:103
vec2f getBounds() const
u32 getLength() const
ScreenMap(const vec2f(&lut)[N], float diameter=-1.0)
Definition screenmap.h:54
float getDiameter() const
FastLED's Elegant JSON Library: fl::Json
Implements the FastLED namespace macros.
vec2< float > vec2f
Definition geometry.h:333
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > fl_map
Definition map.h:540
HeapVector< T, Allocator > vector
Definition vector.h:1214
fl::vector< float > jsonArrayToFloatVector(const fl::Json &jsonArray)
Definition screenmap.cpp:23
IMPORTANT!
Definition crgb.h:20