FastLED 3.9.7
Loading...
Searching...
No Matches
xmap.h
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:
30 enum Type { kLinear = 0, kReverse, kFunction, kLookUpTable };
31
32 static XMap constructWithUserFunction(uint16_t length, XFunction xFunction,
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
49 void convertToLookUpTable();
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;
62 Type type = kLinear;
63 XFunction xFunction = nullptr;
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
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16