FastLED 3.9.15
Loading...
Searching...
No Matches
rectangular_draw_buffer.cpp
Go to the documentation of this file.
1
3#include "fl/allocator.h"
4#include "fl/namespace.h"
5#include "rgbw.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
19 auto it = mPinToLedSegment.find(pin);
20 if (it == mPinToLedSegment.end()) {
21 FASTLED_ASSERT(false, "Pin not found in RectangularDrawBuffer");
22 return fl::Slice<uint8_t>();
23 }
24 fl::Slice<uint8_t> slice = it->second;
25 if (clear_first) {
26 memset(slice.data(), 0, slice.size() * sizeof(slice[0]));
27 }
28 return slice;
29}
30
32 if (mQueueState == QUEUEING) {
33 return false;
34 }
36 mPinToLedSegment.clear();
38 mDrawList.clear();
41 }
42 return true;
43}
44
46 mDrawList.push_back(item);
47}
48
50 if (mQueueState == QUEUE_DONE) {
51 return false;
52 }
55 // iterator through the current draw objects and calculate the total
56 // number of bytes (representing RGB or RGBW) that will be drawn this frame.
57 uint32_t total_bytes = 0;
58 uint32_t max_bytes_in_strip = 0;
59 uint32_t num_strips = 0;
60 getBlockInfo(&num_strips, &max_bytes_in_strip, &total_bytes);
61 if (total_bytes > mAllLedsBufferUint8Size) {
62 uint8_t *old_ptr = mAllLedsBufferUint8.release();
64 uint8_t *ptr = fl::LargeBlockAllocator<uint8_t>::Alloc(total_bytes);
65 mAllLedsBufferUint8.reset(ptr);
66 }
67 mAllLedsBufferUint8Size = total_bytes;
68 uint32_t offset = 0;
69 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
70 uint8_t pin = it->mPin;
72 max_bytes_in_strip);
73 mPinToLedSegment[pin] = slice;
74 offset += max_bytes_in_strip;
75 }
76 return true;
77}
78
80 uint32_t max_bytes = 0;
81 for (auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
82 max_bytes = MAX(max_bytes, it->mNumBytes);
83 }
84 return max_bytes;
85}
86
88 uint32_t num_strips = mDrawList.size();
89 uint32_t max_bytes = getMaxBytesInStrip();
90 return num_strips * max_bytes;
91}
92
93void RectangularDrawBuffer::getBlockInfo(uint32_t *num_strips,
94 uint32_t *bytes_per_strip,
95 uint32_t *total_bytes) const {
96 *num_strips = mDrawList.size();
97 *bytes_per_strip = getMaxBytesInStrip();
98 *total_bytes = (*num_strips) * (*bytes_per_strip);
99}
100
101} // namespace fl
static T * Alloc(size_t n)
Definition allocator.h:15
static void Free(T *p)
Definition allocator.h:20
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:86
size_t size() const
Definition slice.h:90
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
#define MAX(a, b)
Definition math_macros.h:11
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