FastLED 3.9.7
Loading...
Searching...
No Matches
xymap.h
1#pragma once
2
3#include <stdint.h>
4#include <string.h>
5
6#include "crgb.h"
7#include "fl/force_inline.h"
8#include "fl/lut.h"
9#include "fl/ptr.h"
10#include "fl/xmap.h" // Include xmap.h for LUT16
11#include "fl/namespace.h"
12
13namespace fl {
14class ScreenMap;
15
16FASTLED_FORCE_INLINE uint16_t xy_serpentine(uint16_t x, uint16_t y,
17 uint16_t width, uint16_t height) {
18 (void)height;
19 if (y & 1) // Even or odd row?
20 // reverse every second line for a serpentine lled layout
21 return (y + 1) * width - 1 - x;
22 else
23 return y * width + x;
24}
25
26FASTLED_FORCE_INLINE uint16_t xy_line_by_line(uint16_t x, uint16_t y,
27 uint16_t width, uint16_t height) {
28 (void)height;
29 return y * width + x;
30}
31
32// typedef for xyMap function type
33typedef uint16_t (*XYFunction)(uint16_t x, uint16_t y, uint16_t width,
34 uint16_t height);
35
36// XYMap holds either a function or a look up table to map x, y coordinates to a
37// 1D index.
38class XYMap {
39 public:
40 enum XyMapType { kSerpentine = 0, kLineByLine, kFunction, kLookUpTable };
41
42 static XYMap constructWithUserFunction(uint16_t width, uint16_t height,
43 XYFunction xyFunction,
44 uint16_t offset = 0);
45
46 static XYMap constructRectangularGrid(uint16_t width, uint16_t height,
47 uint16_t offset = 0);
48
49 static XYMap constructWithLookUpTable(uint16_t width, uint16_t height,
50 const uint16_t *lookUpTable,
51 uint16_t offset = 0);
52
53 // is_serpentine is true by default. You probably want this unless you are
54 // using a different layout
55 XYMap(uint16_t width, uint16_t height, bool is_serpentine = true,
56 uint16_t offset = 0);
57
58 XYMap(const XYMap &other) = default;
59
60 fl::ScreenMap toScreenMap() const;
61
62 void mapPixels(const CRGB *input, CRGB *output) const;
63
64 void convertToLookUpTable();
65
66 void setRectangularGrid();
67
68 uint16_t operator()(uint16_t x, uint16_t y) const {
69 return mapToIndex(x, y);
70 }
71
72 uint16_t mapToIndex(uint16_t x, uint16_t y) const;
73
74 uint16_t getWidth() const;
75 uint16_t getHeight() const;
76 uint16_t getTotal() const;
77 XyMapType getType() const;
78
79 private:
80 XYMap(uint16_t width, uint16_t height, XyMapType type);
81
82 XyMapType type;
83 uint16_t width;
84 uint16_t height;
85 XYFunction xyFunction = nullptr;
86 fl::LUT16Ptr mLookUpTable; // optional refptr to look up table.
87 uint16_t mOffset = 0; // offset to be added to the output
88};
89
90} // namespace fl
Defines the red, green, and blue (RGB) pixel struct.
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54