Set buffer from serial data

I’m trying to set the matrix data from data streaming over Serial, coming from my animation library: GitHub - ManiacalLabs/BiblioPixel: A pure Python 3 library for programming light animations: Please direct questions and support requests to the forum: https://forum.maniacallabs.com/c/software - The Issues list here should be reserved for actual bugs.
I used to use the old FastLED interface, but needed to update to SM3 so that I could use the > 32x32 matrix size functionality. However, I cannot find any real details on setting the buffer all in one go. So far, I’ve got the follow (simplified for clarity):

#define COLOR_DEPTH 24                  // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 32;        // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 32;       // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 36;       // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 4;       // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN;   // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE);      // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
const uint8_t kScrollingLayerOptions = (SM_SCROLLING_OPTIONS_NONE);
const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE);

SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);

uint16_t numLEDs = (kMatrixWidth * kMatrixHeight);
rgb24 * _LEDS;

void setup(){
    _LEDS = (rgb24*)malloc(sizeof(rgb24)*numLEDs);
    memset(_LEDS, 0, sizeof(rgb24)*numLEDs);

    matrix.addLayer(&backgroundLayer);
    matrix.begin();
}

void loop() {
    static uint16_t size = 0;
    static uint16_t count = 0;
    static uint16_t packSize = numLEDs * 3;
    if (Serial.available())
	{
        count = 0;
        while (count < packSize - 1)
        {
            c = Serial.readBytes(((char*)_LEDS) + count, packSize - count);
            count += c;
        }
    }

    backgroundLayer.setBackBuffer(_LEDS);
    backgroundLayer.swapBuffers(true);
}

All I could find that even looked close was setBackBuffer on the BackgroundLayer class, but event though it looks like the data is getting sent over, nothing ever appears on the matrix.

Is there a better way to do this?

Hi Adam,

The FastLED_Functions example uses backbuffer, maybe you can start with that and modify it to meet your needs. The backgroundBuffer already includes two rgb24 buffers, one currently being used for refresh and another for drawing, so you (probably) don’t need to use malloc in your sketch.

https://github.com/pixelmatix/SmartMatrix/blob/master/examples/FastLED_Functions/FastLED_Functions.ino

If you need to have a third buffer so you can receive data during the brief period where both buffers are being used after a swapBuffers() call, then you’d have to use setBackBuffer(). I don’t know of any currently working sketches that use setBackBuffer(). I believe it was added by Daniel Garcia from FastLED for the now broken “SMART_MATRIX” controller in FastLED. If you really need it, post back and we’ll get it figured out.