FastLED 3.10.8
Loading...
Searching...
No Matches
rectangular_draw_buffer.cpp.hpp
Go to the documentation of this file.
1
3#include "fl/stl/allocator.h"
4#include "fl/gfx/rgbw.h"
5#include "fl/stl/string.h"
6#include "fl/stl/cstring.h" // for fl::memset()
7#include "fl/stl/noexcept.h"
8
9namespace fl {
10
11DrawItem::DrawItem(u8 pin, u16 numLeds, bool is_rgbw)
12 FL_NO_EXCEPT : mPin(pin), mIsRgbw(is_rgbw) {
13 if (is_rgbw) {
14 numLeds = Rgbw::size_as_rgb(numLeds);
15 }
16 mNumBytes = numLeds * 3;
17}
18
21 auto it = mPinToLedSegment.find(pin);
22 if (it == mPinToLedSegment.end()) {
23 FASTLED_ASSERT(false, "Pin not found in RectangularDrawBuffer");
24 return fl::span<u8>();
25 }
26 fl::span<u8> slice = it->second;
27 if (clear_first) {
28 fl::memset(slice.data(), 0, slice.size() * sizeof(slice[0]));
29 }
30 return slice;
31}
32
34 if (mQueueState == QUEUEING) {
35 return false;
36 }
38 mPinToLedSegment.clear();
40 mDrawList.clear();
43 }
44 return true;
45}
46
48 mDrawList.push_back(item);
49}
50
52 if (mQueueState == QUEUE_DONE) {
53 return false;
54 }
57 // iterator through the current draw objects and calculate the total
58 // number of bytes (representing RGB or RGBW) that will be drawn this frame.
59 u32 total_bytes = 0;
60 u32 max_bytes_in_strip = 0;
61 u32 num_strips = 0;
62 getBlockInfo(&num_strips, &max_bytes_in_strip, &total_bytes);
63 if (total_bytes > mAllLedsBufferUint8Size) {
64 u8 *old_ptr = mAllLedsBufferUint8.release();
66 u8 *ptr = fl::PSRamAllocator<u8>::Alloc(total_bytes);
67 mAllLedsBufferUint8.reset(ptr);
68 }
69 mAllLedsBufferUint8Size = total_bytes;
70 u32 offset = 0;
71 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
72 u8 pin = it->mPin;
74 max_bytes_in_strip);
75 mPinToLedSegment[pin] = slice;
76 offset += max_bytes_in_strip;
77 }
78 return true;
79}
80
82 u32 max_bytes = 0;
83 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
84 max_bytes = fl::max(max_bytes, it->mNumBytes);
85 }
86 return max_bytes;
87}
88
90 u32 num_strips = mDrawList.size();
91 u32 max_bytes = getMaxBytesInStrip();
92 return num_strips * max_bytes;
93}
94
96 u32 *bytes_per_strip,
97 u32 *total_bytes) const FL_NO_EXCEPT {
98 *num_strips = mDrawList.size();
99 *bytes_per_strip = getMaxBytesInStrip();
100 *total_bytes = (*num_strips) * (*bytes_per_strip);
101}
102
103} // namespace fl
static T * Alloc(fl::size n) FL_NO_EXCEPT
Definition allocator.h:120
static void Free(T *p) FL_NO_EXCEPT
Definition allocator.h:125
void getBlockInfo(u32 *num_strips, u32 *bytes_per_strip, u32 *total_bytes) const FL_NO_EXCEPT
fl::flat_map< u8, fl::span< u8 > > mPinToLedSegment
void queue(const DrawItem &item) FL_NO_EXCEPT
unique_ptr< u8[], PSRamDeleter< u8 > > mAllLedsBufferUint8
fl::span< u8 > getLedsBufferBytesForPin(u8 pin, bool clear_first=true) FL_NO_EXCEPT
u32 getMaxBytesInStrip() const FL_NO_EXCEPT
const T * data() const FL_NO_EXCEPT
Definition span.h:486
constexpr fl::size size() const FL_NO_EXCEPT
Definition span.h:483
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
Functions for red, green, blue, white (RGBW) output.
unsigned char u8
Definition stdint.h:131
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FASTLED_FORCE_INLINE void * memset(void *s, int c, size_t n) FL_NO_EXCEPT
Definition cstring.h:148
Base definition for an LED controller.
Definition crgb.hpp:179
DrawItem() FL_NO_EXCEPT=default
static u32 size_as_rgb(u32 num_of_rgbw_pixels) FL_NO_EXCEPT
Definition rgbw.h:262