@@ -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#ifdef MATRIX_WITH_ARDUINOGRAPHICS
@@ -280,16 +286,48 @@ class ArduinoLEDMatrix
280286 renderBitmap (_canvasBuffer, canvasHeight, canvasWidth);
281287 }
282288
283- // display the drawing
289+ // display the drawing or capture it to buffer when rendering dynamic anymation
284290 void endDraw () {
285291 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;
287321 }
288322
289323 private:
324+ uint32_t * captureAnimationFrame = nullptr ;
325+ uint32_t captureAnimationHowManyRemains = 0 ;
326+ bool captureAnimation = false ;
290327 static const byte canvasWidth = 12 ;
291328 static const byte canvasHeight = 8 ;
292329 uint8_t _canvasBuffer[canvasHeight][canvasWidth] = {{0 }};
330+ unsigned long _textScrollSpeed = 100 ;
293331#endif
294332
295333private:
0 commit comments