@@ -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
}
@@ -277,16 +283,48 @@ class ArduinoLEDMatrix
277
283
renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
278
284
}
279
285
280
- // display the drawing
286
+ // display the drawing or capture it to buffer when rendering dynamic anymation
281
287
void endDraw () {
282
288
ArduinoGraphics::endDraw ();
283
- renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
289
+
290
+ if (!captureAnimation) {
291
+ renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
292
+ } else {
293
+ if (captureAnimationHowManyRemains >= 4 ) {
294
+ loadPixelsToBuffer (&_canvasBuffer[0 ][0 ], sizeof (_canvasBuffer), captureAnimationFrame);
295
+ captureAnimationFrame[3 ] = _textScrollSpeed;
296
+ captureAnimationFrame += 4 ;
297
+ captureAnimationHowManyRemains -= 16 ;
298
+ }
299
+ }
300
+ }
301
+
302
+ void endTextToAnimationBuffer (int scrollDirection, uint32_t frames[][4 ], uint32_t howManyMax, uint32_t & howManyUsed) {
303
+ captureAnimationFrame = &frames[0 ][0 ];
304
+ captureAnimationHowManyRemains = howManyMax;
305
+
306
+ captureAnimation = true ;
307
+ ArduinoGraphics::textScrollSpeed (0 );
308
+ ArduinoGraphics::endText (scrollDirection);
309
+ ArduinoGraphics::textScrollSpeed (_textScrollSpeed);
310
+ captureAnimation = false ;
311
+
312
+ howManyUsed = howManyMax - captureAnimationHowManyRemains;
313
+ }
314
+
315
+ void textScrollSpeed (unsigned long speed) {
316
+ ArduinoGraphics::textScrollSpeed (speed);
317
+ _textScrollSpeed = speed;
284
318
}
285
319
286
320
private:
321
+ uint32_t * captureAnimationFrame = nullptr ;
322
+ uint32_t captureAnimationHowManyRemains = 0 ;
323
+ bool captureAnimation = false ;
287
324
static const byte canvasWidth = 12 ;
288
325
static const byte canvasHeight = 8 ;
289
326
uint8_t _canvasBuffer[canvasHeight][canvasWidth] = {{0 }};
327
+ unsigned long _textScrollSpeed = 100 ;
290
328
#endif
291
329
292
330
private:
0 commit comments