@@ -141,8 +141,10 @@ static uint32_t reverse(uint32_t x)
141
141
}
142
142
143
143
// TODO: this is dangerous, use with care
144
- #define loadSequence (frames ) loadWrapper(frames, sizeof (frames))
145
- #define renderBitmap (bitmap, rows, columns ) loadPixels(&bitmap[0 ][0 ], rows*columns)
144
+ #define loadSequence (frames ) loadWrapper(frames, sizeof (frames))
145
+ #define renderBitmap (bitmap, rows, columns ) loadPixels(&bitmap[0 ][0 ], rows*columns)
146
+ #define endTextAnimation (scrollDirection, anim ) endTextToAnimationBuffer(scrollDirection, anim ## _buf, sizeof (anim ## _buf), anim ## _buf_used)
147
+ #define loadTextAnimationSequence (anim ) loadWrapper(anim ## _buf, anim ## _buf_used)
146
148
147
149
static uint8_t __attribute__ ((aligned)) framebuffer[NUM_LEDS / 8];
148
150
@@ -227,11 +229,11 @@ class ArduinoLEDMatrix
227
229
return false ;
228
230
}
229
231
230
- void loadPixels (uint8_t * arr, size_t size) {
232
+ static void loadPixelsToBuffer (uint8_t * arr, size_t size, uint32_t * dst) {
231
233
uint32_t partialBuffer = 0 ;
232
234
uint8_t pixelIndex = 0 ;
233
235
uint8_t *frameP = arr;
234
- uint32_t *frameHolderP = _frameHolder ;
236
+ uint32_t *frameHolderP = dst ;
235
237
while (pixelIndex < size) {
236
238
partialBuffer |= *frameP++;
237
239
if ((pixelIndex + 1 ) % 32 == 0 ) {
@@ -240,6 +242,10 @@ class ArduinoLEDMatrix
240
242
partialBuffer = partialBuffer << 1 ;
241
243
pixelIndex++;
242
244
}
245
+ }
246
+
247
+ void loadPixels (uint8_t *arr, size_t size){
248
+ loadPixelsToBuffer (arr, size, _frameHolder);
243
249
loadFrame (_frameHolder);
244
250
};
245
251
@@ -255,9 +261,9 @@ class ArduinoLEDMatrix
255
261
256
262
void clear () {
257
263
const uint32_t fullOff[] = {
258
- 0x00000000 ,
259
- 0x00000000 ,
260
- 0x00000000
264
+ 0x00000000 ,
265
+ 0x00000000 ,
266
+ 0x00000000
261
267
};
262
268
loadFrame (fullOff);
263
269
#ifdef MATRIX_WITH_ARDUINOGRAPHICS
@@ -280,16 +286,48 @@ class ArduinoLEDMatrix
280
286
renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
281
287
}
282
288
283
- // display the drawing
289
+ // display the drawing or capture it to buffer when rendering dynamic anymation
284
290
void endDraw () {
285
291
ArduinoGraphics::endDraw ();
286
- renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
292
+
293
+ if (!captureAnimation) {
294
+ renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
295
+ } else {
296
+ if (captureAnimationHowManyRemains >= 4 ) {
297
+ loadPixelsToBuffer (&_canvasBuffer[0 ][0 ], sizeof (_canvasBuffer), captureAnimationFrame);
298
+ captureAnimationFrame[3 ] = _textScrollSpeed;
299
+ captureAnimationFrame += 4 ;
300
+ captureAnimationHowManyRemains -= 16 ;
301
+ }
302
+ }
303
+ }
304
+
305
+ void endTextToAnimationBuffer (int scrollDirection, uint32_t frames[][4 ], uint32_t howManyMax, uint32_t & howManyUsed) {
306
+ captureAnimationFrame = &frames[0 ][0 ];
307
+ captureAnimationHowManyRemains = howManyMax;
308
+
309
+ captureAnimation = true ;
310
+ ArduinoGraphics::textScrollSpeed (0 );
311
+ ArduinoGraphics::endText (scrollDirection);
312
+ ArduinoGraphics::textScrollSpeed (_textScrollSpeed);
313
+ captureAnimation = false ;
314
+
315
+ howManyUsed = howManyMax - captureAnimationHowManyRemains;
316
+ }
317
+
318
+ void textScrollSpeed (unsigned long speed) {
319
+ ArduinoGraphics::textScrollSpeed (speed);
320
+ _textScrollSpeed = speed;
287
321
}
288
322
289
323
private:
324
+ uint32_t * captureAnimationFrame = nullptr ;
325
+ uint32_t captureAnimationHowManyRemains = 0 ;
326
+ bool captureAnimation = false ;
290
327
static const byte canvasWidth = 12 ;
291
328
static const byte canvasHeight = 8 ;
292
329
uint8_t _canvasBuffer[canvasHeight][canvasWidth] = {{0 }};
330
+ unsigned long _textScrollSpeed = 100 ;
293
331
#endif
294
332
295
333
private:
0 commit comments