I'd like to write a C++ LED library that supports WS2812 APA104 etc. that does notwaste any SRAM/FLASH.
For each LED type I need to track constants for the number of cycles high/low the values Zero and one are. If someone links the library only for WS2812, I don't want the APA104 constants to use any memory.
How could I define those so I can use them as needed?
One way I'm thinking is with macros but I find that ugly:
#define WS2812_LEDSTRIP
char pixels[numPixels*3];
ledStrip strip1(WS2812, numPixels, portNumber, portDDR, portPin);
loop() {
strip1.show(pixels);
strip1.delay();
}
I'd like the user to not have to use a define...
This also means the use can't use 2 types of LED strips at the same time.
The class has to use predefined values for timing aka:
__builtin_avr_delay_cycles(CYCLES(WS2812B_1L));
The above solution would be:
__builtin_avr_delay_cycles(CYCLES(LEDSTRIP_1L));
where LEDSTRIP_1L is set the the WS2812B's value.
I'd rather have constants...
ledstrip::ledstrip(enum striptype,...)
{
switch(striptype) {
case WS2812:
this->ledstrip_1l = WS2812B_1L;
case APA104:
this->ledstrip_1l = WS2812B_1L;
default:
#error boom.
}
}
However I'd like to not use any SRAM for this->ledstrip_1l.
I could also create child classes maybe?
ledStrip_WS2812 : ledstrip {
const uint8_t ledstrip_1l = WS2812B_1L;
}
ledStrip_APA104 : ledstrip {
const uint8_t ledstrip_1l = APA104_1L;
}
If the APA104 class is not instantiated, then would this work maybe?
If you have general ideas and concepts to share on how to write optimal code for this, I'd like to hear it.