Here’s a question for the c wizards!
I would like to modify my cLEDMatrix class library to allow a matrix type declaration in its constructor that would change the compiled internal mXY() function dependent on matrix type?
Something like:-
CRGB leds[NUM_LEDS];
cLEDMatrix MyMatrix<H_ZIGZAG>(16, 16, leds);
Then in the cLEDMatrix class I would want to change the internal inline mXY(int16_t x, int16_t y) function to have the calculation code for the appropriate type of matrix e.g.
For H_ZIGZAG
if (y % 2)
return((((y + 1) * m_Width) - 1) - x);
else
return((y * m_Width) + x);
or V_ZIGZAG
if (x % 2)
return((((x + 1) * m_Height) - 1) - y);
else
return((x * m_Height) + y);
It would be nice not to have to include several ‘if’ conditions in a frequently called function, especially as the matrix type is fixed at compiler time.
#ifdef would work great if the code was not in a library.
I hope my question makes sense ![]()
