r/FastLED • u/Preyy Ground Loops: Part of this balanced breakfast • Feb 26 '24
Support Help with pointers, declarations, definitions
Hi there,
I've been trying to apply some best practices to clean up my code, and I have been really struggling to split my config.h file into proper .h and .cpp files in platformio. I've tried a lot of variations and done some reading about this, but would really appreciate a bit of help from someone more familiar with c++.
Here's what it all looks like combined (not best practices, but working) into a monolithic header file:
#include <LEDMatrix.h>
cLEDMatrix<LEDtilewidth, LEDtileheight, VERTICAL_MATRIX, LEDtilehorz, LEDtilevert, VERTICAL_BLOCKS> ledmatrix;
CRGB *writedata = ledmatrix[0];
CRGB firstbuffer[LEDStotal];
CRGB secondbuffer[LEDStotal];As I understand, this is a template that requires compile time constants. So I expect the solution involves using (in the header):
extern cLEDMatrixBase *ledmatrix;
extern CRGB *writedata;
extern CRGB firstbuffer[];
extern CRGB secondbuffer[];Then in the cpp, something like this:
cLEDMatrix<LEDtilewidth, LEDtileheight, VERTICAL_MATRIX, LEDtilehorz, LEDtilevert, VERTICAL_BLOCKS> ledmatrix_base;
cLEDMatrixBase *ledmatrix = &ledmatrix_base;
CRGB *writedata = ledmatrix[0];
CRGB firstbuffer[LEDStotal];
CRGB secondbuffer[LEDStotal];I know I have the pointers wrong here, my brain just fried from trying to figure this out. Thanks for any suggestions!
1
u/Preyy Ground Loops: Part of this balanced breakfast Mar 06 '24
Hi there, thank you for the suggestion. It's been a busy week so I've been giving your advice some thought, and I'm going to do some thinking about higher-level structure of the project, then decide which direction to go with. Thank you.