@@ -141,8 +141,10 @@ static uint32_t reverse(uint32_t x)
141141}
142142
143143// 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)
146148
147149static uint8_t __attribute__ ((aligned)) framebuffer[NUM_LEDS / 8];
148150
@@ -227,11 +229,11 @@ class ArduinoLEDMatrix
227229 return false ;
228230 }
229231
230- void loadPixels (uint8_t * arr, size_t size) {
232+ static void loadPixelsToBuffer (uint8_t * arr, size_t size, uint32_t * dst) {
231233 uint32_t partialBuffer = 0 ;
232234 uint8_t pixelIndex = 0 ;
233235 uint8_t *frameP = arr;
234- uint32_t *frameHolderP = _frameHolder ;
236+ uint32_t *frameHolderP = dst ;
235237 while (pixelIndex < size) {
236238 partialBuffer |= *frameP++;
237239 if ((pixelIndex + 1 ) % 32 == 0 ) {
@@ -240,6 +242,10 @@ class ArduinoLEDMatrix
240242 partialBuffer = partialBuffer << 1 ;
241243 pixelIndex++;
242244 }
245+ }
246+
247+ void loadPixels (uint8_t *arr, size_t size){
248+ loadPixelsToBuffer (arr, size, _frameHolder);
243249 loadFrame (_frameHolder);
244250 };
245251
@@ -255,9 +261,9 @@ class ArduinoLEDMatrix
255261
256262 void clear () {
257263 const uint32_t fullOff[] = {
258- 0x00000000 ,
259- 0x00000000 ,
260- 0x00000000
264+ 0x00000000 ,
265+ 0x00000000 ,
266+ 0x00000000
261267 };
262268 loadFrame (fullOff);
263269 }
@@ -277,16 +283,48 @@ class ArduinoLEDMatrix
277283 renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
278284 }
279285
280- // display the drawing
286+ // display the drawing or capture it to buffer when rendering dynamic anymation
281287 void endDraw () {
282288 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;
284318 }
285319
286320 private:
321+ uint32_t * captureAnimationFrame = nullptr ;
322+ uint32_t captureAnimationHowManyRemains = 0 ;
323+ bool captureAnimation = false ;
287324 static const byte canvasWidth = 12 ;
288325 static const byte canvasHeight = 8 ;
289326 uint8_t _canvasBuffer[canvasHeight][canvasWidth] = {{0 }};
327+ unsigned long _textScrollSpeed = 100 ;
290328#endif
291329
292330private:
0 commit comments