#ifndef LOGICALMATRIX_H #define LOGICALMATRIX_H #include "LEDHAL2D.h" #include "FastLED.h" class LogicalMatrix : public LEDHAL2D { public: LogicalMatrix(char* _ledName, LEDHAL2D* _parent, int16_t _startX, int16_t _startY, int16_t _stopX, int16_t _stopY) : LEDHAL2D(_stopX - _startX, _stopY - _startY, _ledName, false), startX(_startX), stopX(_stopX), startY(_startY), stopY(_stopY), parent(_parent) {} virtual ~LogicalMatrix() {} void drawPixel(int16_t x, int16_t y, CRGB color) { parent->drawPixel(startX + x, startY + y, color); } void setColor(int16_t pixel, CRGB color) { //This is a computationally expensive cheap trick that I'm not //entirely convinced is necessary, it is essentially the reverse //of pixelPos = getHeight() * y + x //Integer division by getHeight returns y from the above //Modulous (remainder) by getHeight returns x from the above int16_t intDiv = pixel / getHeight(); //yPos int16_t intMod = pixel % getHeight(); //xPos parent->setColor((startX + intMod) * (startY + intDiv), color); } CRGB getColor(int16_t pixel) { //This is a computationally expensive cheap trick that I'm not //entirely convinced is necessary, it is essentially the reverse //of pixelPos = getHeight() * y + x //Integer division by getHeight returns y from the above //Modulous (remainder) by getHeight returns x from the above int16_t intDiv = pixel / getHeight(); //yPos int16_t intMod = pixel % getHeight(); //xPos return parent->getColor((startX + intMod) * (startY + intDiv)); } CRGB getColor(int16_t x, int16_t y) { return parent->getColor(startX + x, startY + y); } uint16_t getNumLEDs() { return getWidth() * getHeight(); } void requestShow() { parent->requestShow(); } protected: void updateLEDs() { //This does nothing, because show should never be called on //a logical strip } private: LEDHAL2D* parent; int16_t startX, stopX, startY, stopY; }; #endif