FastLED 3.9.15
Loading...
Searching...
No Matches
xmap.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <string.h>
5
6#include "fl/force_inline.h"
7#include "fl/lut.h"
8#include "fl/ptr.h"
9
10#include "fl/namespace.h"
11
12namespace fl {
13
14FASTLED_FORCE_INLINE uint16_t x_linear(uint16_t x, uint16_t length) {
15 (void)length;
16 return x;
17}
18
19FASTLED_FORCE_INLINE uint16_t x_reverse(uint16_t x, uint16_t length) {
20 return length - 1 - x;
21}
22
23// typedef for xMap function type
24typedef uint16_t (*XFunction)(uint16_t x, uint16_t 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 uint16_t 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.
37 static XMap constructWithLookUpTable(uint16_t length,
38 const uint16_t *lookUpTable,
39 uint16_t offset = 0);
40
41 // is_reverse is false by default for linear layout
42 XMap(uint16_t length, bool is_reverse = false, uint16_t offset = 0);
43
44 XMap(const XMap &other);
45
46 // define the assignment operator
47 XMap &operator=(const XMap &other) ;
48
50
51 uint16_t mapToIndex(uint16_t x) const;
52
53 uint16_t operator()(uint16_t x) const { return mapToIndex(x); }
54
55 uint16_t getLength() const;
56
57 Type getType() const;
58
59 private:
60 XMap(uint16_t length, Type type);
61 uint16_t length = 0;
64 const uint16_t *mData = nullptr;
65 fl::LUT16Ptr mLookUpTable;
66 uint16_t mOffset = 0; // offset to be added to the output
67};
68
69} // namespace fl
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint16_t mOffset
Definition xmap.h:66
void convertToLookUpTable()
Definition xmap.cpp:47
Type type
Definition xmap.h:62
uint16_t mapToIndex(uint16_t x) const
Definition xmap.cpp:64
const uint16_t * mData
Definition xmap.h:64
Type getType() const
Definition xmap.cpp:94
uint16_t length
Definition xmap.h:61
XMap(uint16_t length, bool is_reverse=false, uint16_t offset=0)
Definition xmap.cpp:28
fl::LUT16Ptr mLookUpTable
Definition xmap.h:65
static XMap constructWithUserFunction(uint16_t length, XFunction xFunction, uint16_t offset=0)
Definition xmap.cpp:10
uint16_t getLength() const
Definition xmap.cpp:88
uint16_t operator()(uint16_t x) const
Definition xmap.h:53
static XMap constructWithLookUpTable(uint16_t length, const uint16_t *lookUpTable, uint16_t offset=0)
Definition xmap.cpp:19
@ kFunction
Definition xmap.h:30
@ kLookUpTable
Definition xmap.h:30
@ kLinear
Definition xmap.h:30
@ kReverse
Definition xmap.h:30
XFunction xFunction
Definition xmap.h:63
XMap & operator=(const XMap &other)
Definition xmap.cpp:106
#define FASTLED_FORCE_INLINE
Definition force_inline.h:7
Implements the FastLED namespace macros.
uint16_t(* XFunction)(uint16_t x, uint16_t length)
Definition xmap.h:24
FASTLED_FORCE_INLINE uint16_t x_linear(uint16_t x, uint16_t length)
Definition xmap.h:14
FASTLED_FORCE_INLINE uint16_t x_reverse(uint16_t x, uint16_t length)
Definition xmap.h:19
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16