FastLED 3.10.8
Loading...
Searching...
No Matches
leds.h
Go to the documentation of this file.
1#pragma once
2
3#include "crgb.h" // IWYU pragma: keep
4#include "fl/math/xymap.h"
5#include "fl/stl/span.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9
10// Leds definition.
11// Drawing operations on a block of leds requires information about the layout
12// of the leds. Hence this class.
13class Leds {
14 public:
17
18 // Copy constructor and assignment operator.
19 Leds(const Leds &) FL_NO_EXCEPT = default;
20 Leds &operator=(const Leds &) FL_NO_EXCEPT = default;
21 Leds(Leds &&) FL_NO_EXCEPT = default;
22
23 // out of bounds access returns empty() led and is safe to read/write.
24 CRGB &operator()(int x, int y) FL_NO_EXCEPT;
25 const CRGB &operator()(int x, int y) const FL_NO_EXCEPT;
26
27 CRGB &at(int x, int y) FL_NO_EXCEPT { return (*this)(x, y); }
28 const CRGB &at(int x, int y) const FL_NO_EXCEPT { return (*this)(x, y); }
29
30 fl::size width() const FL_NO_EXCEPT { return mXyMap.getHeight(); }
31 fl::size height() const FL_NO_EXCEPT { return mXyMap.getWidth(); }
32
33 // Allows normal matrix array (row major) access, bypassing the XYMap.
34 // Will assert if XYMap is not serpentine or line by line.
36 const CRGB *operator[](int x) const FL_NO_EXCEPT;
37 // Raw data access.
40
41 const XYMap &xymap() const FL_NO_EXCEPT { return mXyMap; }
42
43 operator CRGB *() FL_NO_EXCEPT { return mLeds.data(); }
44 operator const CRGB *() const FL_NO_EXCEPT { return mLeds.data(); }
45
46 void fill(const CRGB &color) FL_NO_EXCEPT {
47 for (fl::size i = 0; i < mXyMap.getTotal(); ++i) {
48 mLeds[i] = color;
49 }
50 }
51
52
53
54 protected:
55 static CRGB &empty() FL_NO_EXCEPT; // Allows safe out of bounds access.
58};
59
60template <fl::size W, fl::size H> class LedsXY : public Leds {
61 public:
62 LedsXY() FL_NO_EXCEPT : Leds(mLedsData, XYMap::constructSerpentine(W, H)) {}
63 explicit LedsXY(bool is_serpentine)
66 LedsXY(const LedsXY &) FL_NO_EXCEPT = default;
67 LedsXY &operator=(const LedsXY &) FL_NO_EXCEPT = default;
69 void setSerpentine(bool is_serpentine) FL_NO_EXCEPT {
70 mXyMap = is_serpentine ? XYMap::constructSerpentine(W, H)
72 }
73
74 private:
75 CRGB mLedsData[W * H] = {};
76};
77
78} // namespace fl
CRGB leds[1]
static const int H
Definition PerfDisc.ino:21
static const int W
Definition PerfDisc.ino:20
fl::span< CRGB > rgb() FL_NO_EXCEPT
Definition leds.h:38
fl::size width() const FL_NO_EXCEPT
Definition leds.h:30
fl::span< const CRGB > rgb() const FL_NO_EXCEPT
Definition leds.h:39
Leds(Leds &&) FL_NO_EXCEPT=default
const CRGB & at(int x, int y) const FL_NO_EXCEPT
Definition leds.h:28
fl::span< CRGB > mLeds
Definition leds.h:57
fl::size height() const FL_NO_EXCEPT
Definition leds.h:31
Leds(CRGB *leds, u16 width, u16 height) FL_NO_EXCEPT
Definition leds.cpp.hpp:43
CRGB * operator[](int x) FL_NO_EXCEPT
Definition leds.cpp.hpp:32
void fill(const CRGB &color) FL_NO_EXCEPT
Definition leds.h:46
XYMap mXyMap
Definition leds.h:56
CRGB & at(int x, int y) FL_NO_EXCEPT
Definition leds.h:27
const XYMap & xymap() const FL_NO_EXCEPT
Definition leds.h:41
Leds(const Leds &) FL_NO_EXCEPT=default
static CRGB & empty() FL_NO_EXCEPT
Definition leds.cpp.hpp:20
Leds & operator=(const Leds &) FL_NO_EXCEPT=default
LedsXY(const LedsXY &) FL_NO_EXCEPT=default
void setXyMap(const XYMap &xymap) FL_NO_EXCEPT
Definition leds.h:68
void setSerpentine(bool is_serpentine) FL_NO_EXCEPT
Definition leds.h:69
CRGB mLedsData[W *H]
Definition leds.h:75
LedsXY & operator=(const LedsXY &) FL_NO_EXCEPT=default
LedsXY() FL_NO_EXCEPT
Definition leds.h:62
LedsXY(bool is_serpentine) FL_NO_EXCEPT
Definition leds.h:63
static XYMap constructSerpentine(u16 width, u16 height, u16 offset=0) FL_NO_EXCEPT
Definition xymap.cpp.hpp:61
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0) FL_NO_EXCEPT
Definition xymap.cpp.hpp:36
Defines the 8-bit red, green, and blue (RGB) pixel type in the fl namespace.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38