FastLED 3.9.15
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
8namespace fl {
9
10DrawItem::DrawItem(u8 pin, u16 numLeds, bool is_rgbw)
11 : mPin(pin), mIsRgbw(is_rgbw) {
12 if (is_rgbw) {
13 numLeds = Rgbw::size_as_rgb(numLeds);
14 }
15 mNumBytes = numLeds * 3;
16}
17
20 auto it = mPinToLedSegment.find(pin);
21 if (it == mPinToLedSegment.end()) {
22 FASTLED_ASSERT(false, "Pin not found in RectangularDrawBuffer");
23 return fl::span<u8>();
24 }
25 fl::span<u8> slice = it->second;
26 if (clear_first) {
27 fl::memset(slice.data(), 0, slice.size() * sizeof(slice[0]));
28 }
29 return slice;
30}
31
33 if (mQueueState == QUEUEING) {
34 return false;
35 }
37 mPinToLedSegment.clear();
39 mDrawList.clear();
42 }
43 return true;
44}
45
47 mDrawList.push_back(item);
48}
49
51 if (mQueueState == QUEUE_DONE) {
52 return false;
53 }
56 // iterator through the current draw objects and calculate the total
57 // number of bytes (representing RGB or RGBW) that will be drawn this frame.
58 u32 total_bytes = 0;
59 u32 max_bytes_in_strip = 0;
60 u32 num_strips = 0;
61 getBlockInfo(&num_strips, &max_bytes_in_strip, &total_bytes);
62 if (total_bytes > mAllLedsBufferUint8Size) {
63 u8 *old_ptr = mAllLedsBufferUint8.release();
65 u8 *ptr = fl::PSRamAllocator<u8>::Alloc(total_bytes);
66 mAllLedsBufferUint8.reset(ptr);
67 }
68 mAllLedsBufferUint8Size = total_bytes;
69 u32 offset = 0;
70 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
71 u8 pin = it->mPin;
73 max_bytes_in_strip);
74 mPinToLedSegment[pin] = slice;
75 offset += max_bytes_in_strip;
76 }
77 return true;
78}
79
81 u32 max_bytes = 0;
82 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
83 max_bytes = fl::max(max_bytes, it->mNumBytes);
84 }
85 return max_bytes;
86}
87
89 u32 num_strips = mDrawList.size();
90 u32 max_bytes = getMaxBytesInStrip();
91 return num_strips * max_bytes;
92}
93
95 u32 *bytes_per_strip,
96 u32 *total_bytes) const {
97 *num_strips = mDrawList.size();
98 *bytes_per_strip = getMaxBytesInStrip();
99 *total_bytes = (*num_strips) * (*bytes_per_strip);
100}
101
102} // namespace fl
static void Free(T *p) FL_NOEXCEPT
Definition allocator.h:124
static T * Alloc(fl::size n) FL_NOEXCEPT
Definition allocator.h:119
fl::flat_map< u8, fl::span< u8 > > mPinToLedSegment
fl::span< u8 > getLedsBufferBytesForPin(u8 pin, bool clear_first=true)
unique_ptr< u8[], PSRamDeleter< u8 > > mAllLedsBufferUint8
void getBlockInfo(u32 *num_strips, u32 *bytes_per_strip, u32 *total_bytes) const
const T * data() const FL_NOEXCEPT
Definition span.h:461
constexpr fl::size size() const FL_NOEXCEPT
Definition span.h:458
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_NOEXCEPT
Definition math.h:75
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179
DrawItem() FL_NOEXCEPT=default
static u32 size_as_rgb(u32 num_of_rgbw_pixels) FL_NOEXCEPT
Definition rgbw.h:186