33
44#define NUM_LEDS 96
55
6+ #if __has_include("ArduinoGraphics.h")
7+ #include < ArduinoGraphics.h>
8+ #define MATRIX_WITH_ARDUINOGRAPHICS
9+ #endif
10+
611static const int pin_zero_index = 28 ;
712
813static const uint8_t pins[][2 ] = {
@@ -138,10 +143,18 @@ static uint32_t reverse(uint32_t x)
138143
139144static uint8_t __attribute__ ((aligned)) framebuffer[NUM_LEDS / 8];
140145
141- class ArduinoLEDMatrix {
146+ class ArduinoLEDMatrix
147+ #ifdef MATRIX_WITH_ARDUINOGRAPHICS
148+ : public ArduinoGraphics
149+ #endif
150+ {
142151
143152public:
144- ArduinoLEDMatrix () {}
153+ ArduinoLEDMatrix ()
154+ #ifdef MATRIX_WITH_ARDUINOGRAPHICS
155+ : ArduinoGraphics(canvasWidth, canvasHeight)
156+ #endif
157+ {}
145158 // TODO: find a better name
146159 // autoscroll will be slower than calling next() at precise times
147160 void autoscroll (uint32_t interval_ms) {
@@ -153,7 +166,7 @@ class ArduinoLEDMatrix {
153166 void off (size_t pin) {
154167 turnLed (pin, false );
155168 }
156- void begin () {
169+ int begin () {
157170 uint8_t type;
158171 uint8_t ch = FspTimer::get_available_timer (type);
159172 // TODO: avoid passing "this" argument to remove autoscroll
@@ -231,7 +244,37 @@ class ArduinoLEDMatrix {
231244 void setCallback (voidFuncPtr callBack){
232245 _callBack = callBack;
233246 }
234-
247+
248+ #ifdef MATRIX_WITH_ARDUINOGRAPHICS
249+ virtual void set (int x, int y, uint8_t r, uint8_t g, uint8_t b) {
250+ if (y >= canvasHeight || x >= canvasWidth) {
251+ return ;
252+ }
253+ // the r parameter is (mis)used to set the character to draw with
254+ _canvasBuffer[y][x] = (r | g | b) > 0 ? 1 : 0 ;
255+ }
256+
257+ void endText (int scrollDirection = NO_SCROLL) {
258+ ArduinoGraphics::endText (scrollDirection);
259+ renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
260+ }
261+
262+ // display the drawing
263+ void endDraw () {
264+ ArduinoGraphics::endDraw ();
265+ // clear first line (no idea why it gets filled with random bits, probably some math not working fine for super small displays)
266+ for (int i = 0 ; i < canvasWidth; i++) {
267+ _canvasBuffer[0 ][i] = 0 ;
268+ }
269+ renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
270+ }
271+
272+ private:
273+ static const byte canvasWidth = 12 ;
274+ static const byte canvasHeight = 8 ;
275+ uint8_t _canvasBuffer[canvasHeight][canvasWidth] = {{0 }};
276+ #endif
277+
235278private:
236279 int _currentFrame = 0 ;
237280 uint32_t _frameHolder[3 ];
0 commit comments