2#include "fl/rectangular_draw_buffer.h"
5#include "fl/allocator.h"
9DrawItem::DrawItem(uint8_t pin, uint16_t numLeds,
bool is_rgbw)
10 : mPin(pin), mIsRgbw(is_rgbw) {
12 numLeds = Rgbw::size_as_rgb(numLeds);
14 mNumBytes = numLeds * 3;
17Slice<uint8_t> RectangularDrawBuffer::getLedsBufferBytesForPin(uint8_t pin,
bool clear_first) {
18 auto it = mPinToLedSegment.find(pin);
19 if (it == mPinToLedSegment.end()) {
20 FASTLED_ASSERT(
false,
"Pin not found in RectangularDrawBuffer");
25 memset(slice.data(), 0, slice.size() *
sizeof(slice[0]));
30bool RectangularDrawBuffer::onQueuingStart() {
31 if (mQueueState == QUEUEING) {
34 mQueueState = QUEUEING;
35 mPinToLedSegment.clear();
36 mDrawList.swap(mPrevDrawList);
38 if (mAllLedsBufferUint8Size > 0) {
39 memset(mAllLedsBufferUint8.get(), 0, mAllLedsBufferUint8Size);
44void RectangularDrawBuffer::queue(
const DrawItem &item) {
45 mDrawList.push_back(item);
48bool RectangularDrawBuffer::onQueuingDone() {
49 if (mQueueState == QUEUE_DONE) {
52 mQueueState = QUEUE_DONE;
53 mDrawListChangedThisFrame = mDrawList != mPrevDrawList;
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();
64 mAllLedsBufferUint8.reset(ptr);
66 mAllLedsBufferUint8Size = total_bytes;
68 for (
auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
69 uint8_t pin = it->mPin;
70 Slice<uint8_t> slice(mAllLedsBufferUint8.get() + offset,
72 mPinToLedSegment[pin] = slice;
73 offset += max_bytes_in_strip;
78uint32_t RectangularDrawBuffer::getMaxBytesInStrip()
const {
79 uint32_t max_bytes = 0;
80 for (
auto it = mDrawList.begin(); it != mDrawList.end(); ++it) {
81 max_bytes = MAX(max_bytes, it->mNumBytes);
86uint32_t RectangularDrawBuffer::getTotalBytes()
const {
87 uint32_t num_strips = mDrawList.size();
88 uint32_t max_bytes = getMaxBytesInStrip();
89 return num_strips * max_bytes;
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);
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Functions for red, green, blue, white (RGBW) output.