FastLED 3.9.15
Loading...
Searching...
No Matches
xmap.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stdint.h"
4#include <string.h>
5
6#include "fl/force_inline.h"
7#include "fl/lut.h"
8#include "fl/memory.h"
9
10#include "fl/namespace.h"
11
12namespace fl {
13
15 (void)length;
16 return x;
17}
18
20 return length - 1 - x;
21}
22
23// typedef for xMap function type
24typedef u16 (*XFunction)(u16 x, u16 length);
25
26// XMap holds either a function or a look up table to map x coordinates to a 1D
27// index.
28class XMap {
29 public:
31
33 u16 offset = 0);
34
35 // When a pointer to a lookup table is passed in then we assume it's
36 // owned by someone else and will not be deleted.
38 const u16 *lookUpTable,
39 u16 offset = 0);
40
41 // is_reverse is false by default for linear layout
42 XMap(u16 length, bool is_reverse = false, u16 offset = 0);
43
44 XMap(const XMap &other);
45
46 // define the assignment operator
47 XMap &operator=(const XMap &other);
48
50
51 u16 mapToIndex(u16 x) const;
52
53 u16 operator()(u16 x) const { return mapToIndex(x); }
54
55 u16 getLength() const;
56
57 Type getType() const;
58
59 private:
60 XMap(u16 length, Type type);
61 u16 length = 0;
64 const u16 *mData = nullptr;
65 fl::LUT16Ptr mLookUpTable;
66 u16 mOffset = 0; // offset to be added to the output
67};
68
69} // namespace fl
int x
Definition simple.h:92
void convertToLookUpTable()
Definition xmap.cpp:39
Type type
Definition xmap.h:62
u16 length
Definition xmap.h:61
u16 mOffset
Definition xmap.h:66
u16 getLength() const
Definition xmap.cpp:76
Type getType() const
Definition xmap.cpp:78
u16 mapToIndex(u16 x) const
Definition xmap.cpp:54
static XMap constructWithLookUpTable(u16 length, const u16 *lookUpTable, u16 offset=0)
Definition xmap.cpp:15
fl::LUT16Ptr mLookUpTable
Definition xmap.h:65
u16 operator()(u16 x) const
Definition xmap.h:53
const u16 * mData
Definition xmap.h:64
@ kFunction
Definition xmap.h:30
@ kLookUpTable
Definition xmap.h:30
@ kLinear
Definition xmap.h:30
@ kReverse
Definition xmap.h:30
XMap(u16 length, bool is_reverse=false, u16 offset=0)
Definition xmap.cpp:24
XFunction xFunction
Definition xmap.h:63
static XMap constructWithUserFunction(u16 length, XFunction xFunction, u16 offset=0)
Definition xmap.cpp:7
XMap & operator=(const XMap &other)
Definition xmap.cpp:83
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
#define FASTLED_FORCE_INLINE
Definition force_inline.h:6
Implements the FastLED namespace macros.
FASTLED_FORCE_INLINE u16 x_linear(u16 x, u16 length)
Definition xmap.h:14
FASTLED_FORCE_INLINE u16 x_reverse(u16 x, u16 length)
Definition xmap.h:19
u16(* XFunction)(u16 x, u16 length)
Definition xmap.h:24
IMPORTANT!
Definition crgb.h:20