FastLED 3.9.15
Loading...
Searching...
No Matches
rectangular_draw_buffer.cpp
Go to the documentation of this file.
1
3#include "fl/namespace.h"
4#include "rgbw.h"
5#include "fl/allocator.h"
6
7namespace fl {
8
9DrawItem::DrawItem(uint8_t pin, uint16_t numLeds, bool is_rgbw)
10 : mPin(pin), mIsRgbw(is_rgbw) {
11 if (is_rgbw) {
12 numLeds = Rgbw::size_as_rgb(numLeds);
13 }
14 mNumBytes = numLeds * 3;
15}
16
18 auto it = mPinToLedSegment.find(pin);
19 if (it == mPinToLedSegment.end()) {
20 FASTLED_ASSERT(false, "Pin not found in RectangularDrawBuffer");
21 return fl::Slice<uint8_t>();
22 }
23 fl::Slice<uint8_t> slice = it->second;
24 if (clear_first) {
25 memset(slice.data(), 0, slice.size() * sizeof(slice[0]));
26 }
27 return slice;
28}
29
31 if (mQueueState == QUEUEING) {
32 return false;
33 }
35 mPinToLedSegment.clear();
37 mDrawList.clear();
40 }
41 return true;
42}
43
45 mDrawList.push_back(item);
46}
47
49 if (mQueueState == QUEUE_DONE) {
50 return false;
51 }
54 // iterator through the current draw objects and calculate the total
55 // number of bytes (representing RGB or RGBW) that will be drawn this frame.
56 uint32_t total_bytes = 0;
57 uint32_t max_bytes_in_strip = 0;
58 uint32_t num_strips = 0;
59 getBlockInfo(&num_strips, &max_bytes_in_strip, &total_bytes);
60 if (total_bytes > mAllLedsBufferUint8Size) {
61 uint8_t* old_ptr = mAllLedsBufferUint8.release();
63 uint8_t* ptr = fl::LargeBlockAllocator<uint8_t>::Alloc(total_bytes);
64 mAllLedsBufferUint8.reset(ptr);
65 }
66 mAllLedsBufferUint8Size = total_bytes;
67 uint32_t offset = 0;
68 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
69 uint8_t pin = it->mPin;
70 Slice<uint8_t> slice(mAllLedsBufferUint8.get() + offset,
71 max_bytes_in_strip);
72 mPinToLedSegment[pin] = slice;
73 offset += max_bytes_in_strip;
74 }
75 return true;
76}
77
79 uint32_t max_bytes = 0;
80 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
81 max_bytes = MAX(max_bytes, it->mNumBytes);
82 }
83 return max_bytes;
84}
85
87 uint32_t num_strips = mDrawList.size();
88 uint32_t max_bytes = getMaxBytesInStrip();
89 return num_strips * max_bytes;
90}
91
92void RectangularDrawBuffer::getBlockInfo(uint32_t *num_strips,
93 uint32_t *bytes_per_strip,
94 uint32_t *total_bytes) const {
95 *num_strips = mDrawList.size();
96 *bytes_per_strip = getMaxBytesInStrip();
97 *total_bytes = (*num_strips) * (*bytes_per_strip);
98}
99
100} // namespace fl
#define FASTLED_ASSERT(x, MSG)
Definition assert.h:9
static T * Alloc(size_t n)
Definition allocator.h:18
static void Free(T *p)
Definition allocator.h:23
void getBlockInfo(uint32_t *num_strips, uint32_t *bytes_per_strip, uint32_t *total_bytes) const
fl::Slice< uint8_t > getLedsBufferBytesForPin(uint8_t pin, bool clear_first=true)
fl::FixedMap< uint8_t, fl::Slice< uint8_t >, 50 > mPinToLedSegment
void queue(const DrawItem &item)
scoped_array< uint8_t > mAllLedsBufferUint8
const T * data() const
Definition slice.h:54
size_t size() const
Definition slice.h:62
#define MAX(a, b)
Definition math_macros.h:4
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Functions for red, green, blue, white (RGBW) output.
static uint32_t size_as_rgb(uint32_t num_of_rgbw_pixels)
Definition rgbw.h:41
DrawItem()=default