3
3
4
4
#define NUM_LEDS 96
5
5
6
+ #if __has_include("ArduinoGraphics.h")
7
+ #include < ArduinoGraphics.h>
8
+ #define MATRIX_WITH_ARDUINOGRAPHICS
9
+ #endif
10
+
6
11
static const int pin_zero_index = 28 ;
7
12
8
13
static const uint8_t pins[][2 ] = {
@@ -138,10 +143,18 @@ static uint32_t reverse(uint32_t x)
138
143
139
144
static uint8_t __attribute__ ((aligned)) framebuffer[NUM_LEDS / 8];
140
145
141
- class ArduinoLEDMatrix {
146
+ class ArduinoLEDMatrix
147
+ #ifdef MATRIX_WITH_ARDUINOGRAPHICS
148
+ : public ArduinoGraphics
149
+ #endif
150
+ {
142
151
143
152
public:
144
- ArduinoLEDMatrix () {}
153
+ ArduinoLEDMatrix ()
154
+ #ifdef MATRIX_WITH_ARDUINOGRAPHICS
155
+ : ArduinoGraphics(canvasWidth, canvasHeight)
156
+ #endif
157
+ {}
145
158
// TODO: find a better name
146
159
// autoscroll will be slower than calling next() at precise times
147
160
void autoscroll (uint32_t interval_ms) {
@@ -153,7 +166,7 @@ class ArduinoLEDMatrix {
153
166
void off (size_t pin) {
154
167
turnLed (pin, false );
155
168
}
156
- void begin () {
169
+ int begin () {
157
170
uint8_t type;
158
171
uint8_t ch = FspTimer::get_available_timer (type);
159
172
// TODO: avoid passing "this" argument to remove autoscroll
@@ -231,7 +244,37 @@ class ArduinoLEDMatrix {
231
244
void setCallback (voidFuncPtr callBack){
232
245
_callBack = callBack;
233
246
}
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
+
235
278
private:
236
279
int _currentFrame = 0 ;
237
280
uint32_t _frameHolder[3 ];
0 commit comments