73 lines
1.9 KiB
C++
73 lines
1.9 KiB
C++
#ifndef CLEDCONTROLLERPHYSICALMATRIX_H
|
|
#define CLEDCONTROLLERPHYSICALMATRIX_H
|
|
|
|
#include "LEDHAL2D.h"
|
|
|
|
enum ArrangementType {
|
|
HORIZONTALSCAN,
|
|
HORIZONTALSERPENTINE,
|
|
COLUMNSCAN,
|
|
COLUMNSERPENTINE
|
|
};
|
|
|
|
class CLEDControllerPhysicalMatrix : public LEDHAL2D {
|
|
public:
|
|
CLEDControllerPhysicalMatrix(CLEDController* _controller, char* ledName, ArrangementType _arrangement,
|
|
int16_t width, int16_t height): LEDHAL2D(width, height, ledName, true), controller(_controller), arrangement(_arrangement) {}
|
|
virtual ~CLEDControllerPhysicalMatrix() {}
|
|
|
|
void drawPixel(int16_t x, int16_t y, CRGB color) {
|
|
controller->leds()[XY(x, y)] = color;
|
|
}
|
|
|
|
void setColor(int16_t pixel, CRGB color) {
|
|
controller->leds()[pixel] = color;
|
|
}
|
|
|
|
CRGB getColor(int16_t pixel) {
|
|
return controller->leds()[pixel];
|
|
}
|
|
|
|
CRGB getColor(int16_t x, int16_t y) {
|
|
return getColor(XY(x, y));
|
|
}
|
|
|
|
int16_t XY(int16_t x, int16_t y) {
|
|
if(arrangement == ArrangementType::HORIZONTALSCAN) {
|
|
return getWidth() * y + x;
|
|
} else if(arrangement == ArrangementType::COLUMNSCAN) {
|
|
return getHeight() * x + y;
|
|
} else if(arrangement == ArrangementType::HORIZONTALSERPENTINE) {
|
|
if(y & 0x1) {
|
|
return y * getWidth() + (getWidth() - 1 - x);
|
|
} else {
|
|
return y * getWidth() + x;
|
|
}
|
|
} else if(arrangement == ArrangementType::COLUMNSERPENTINE) {
|
|
if(x & 0x1) {
|
|
return x * getHeight() + (getHeight() - 1 - y);
|
|
} else {
|
|
return x * getHeight() + y;
|
|
}
|
|
} else {
|
|
return 0; //How did you get here?
|
|
}
|
|
}
|
|
|
|
uint16_t getNumLEDs() {
|
|
return getWidth() * getHeight();
|
|
}
|
|
|
|
protected:
|
|
void updateLEDs() {
|
|
controller->showLeds();
|
|
}
|
|
|
|
private:
|
|
CLEDController*
|
|
controller;
|
|
ArrangementType
|
|
arrangement;
|
|
};
|
|
|
|
#endif |