3#include "fl/bytestreammemory.h"
4#include "fl/math_macros.h"
12ByteStreamMemory::ByteStreamMemory(uint32_t size_buffer)
13 : mReadBuffer(size_buffer) {}
15ByteStreamMemory::~ByteStreamMemory() =
default;
17bool ByteStreamMemory::available(
size_t n)
const {
18 return mReadBuffer.size() >= n;
21size_t ByteStreamMemory::read(uint8_t *dst,
size_t bytesToRead) {
22 if (!available(bytesToRead) || dst ==
nullptr) {
23 FASTLED_WARN(
"ByteStreamMemory::read: !available(bytesToRead): " << bytesToRead <<
" mReadBuffer.size(): " << mReadBuffer.size());
27 size_t actualBytesToRead = MIN(bytesToRead, mReadBuffer.size());
30 while (bytesRead < actualBytesToRead) {
31 uint8_t& b = dst[bytesRead];
32 mReadBuffer.pop_front(&b);
37 FASTLED_WARN(
"ByteStreamMemory::read: bytesRead == 0");
43size_t ByteStreamMemory::write(
const uint8_t* src,
size_t n) {
44 if (src ==
nullptr || mReadBuffer.capacity() == 0) {
45 FASTLED_WARN_IF(src ==
nullptr,
"ByteStreamMemory::write: src == nullptr");
46 FASTLED_WARN_IF(mReadBuffer.capacity() == 0,
"ByteStreamMemory::write: mReadBuffer.capacity() == 0");
51 for (
size_t i = 0; i < n; ++i) {
52 if (mReadBuffer.full()) {
53 FASTLED_WARN(
"ByteStreamMemory::write: mReadBuffer.full(): " << mReadBuffer.size());
56 mReadBuffer.push_back(src[i]);
62size_t ByteStreamMemory::writeCRGB(
const CRGB* src,
size_t n) {
63 size_t bytes_written = write(
reinterpret_cast<const uint8_t*
>(src), n * 3);
64 size_t pixels_written = bytes_written / 3;
65 return pixels_written;
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Representation of an RGB pixel (Red, Green, Blue)