Skip to content

Add support for scrolling text asynchronously #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

misaz
Copy link
Contributor

@misaz misaz commented May 11, 2024

I implemented support for generating animation (sequence) from text input. This can be later used for scrolling text asynchronously instead of doing it using endText which blocks execution untill text scroll is done on display.

The new proposed API contains TEXT_ANIMATION_DEFINE macro (in new file TextAnimation.h) which (staticaly) declare buffer for specified number of frames. The API for sequences requires static number of frames, but this new API can dynamicaly adjust length of sequence depending on text length up to limit specified in second TEXT_ANIMATION_DEFINE parameter. For example:

TEXT_ANIMATION_DEFINE(anim, 100)

declare buffers for up to 100 frames which is 20 characters using font 5x7 or 25 characters using font 4x6.

Then you can render text in exactly the same way as before. For example:

 matrix.beginDraw();

 matrix.stroke(0xFFFFFFFF);
 matrix.textFont(Font_5x7);
 matrix.textScrollSpeed(60);
 matrix.setCallback(matrixCallback);
 
 const char text[] = "   UNO r4 ";
 matrix.beginText(0, 1, 0xFFFFFF);
 matrix.println(text);

and then you call endTextAnimation instead of endText. endTextAnimation renders text to the passed buffer (anim defined above) and do not show anything on display immidiately. Now you have animation rendered in the buffer, but because animation length is dynamic, you can't use loadSequence because it assumes that sequence spans over whole buffer. Instead there is new loadTextAnimationSequence which loads buffer and animation length correctly. Finally, once you loaded you can play it asynchronously (matrix.play();), or play it endlesly (matrix.play(true);).

matrix.endTextAnimation(SCROLL_LEFT, anim); 
matrix.loadTextAnimationSequence(anim);
matrix.play();

Proposed change contains new example TextWithArduinoGraphicsAsynchronous showing the proposed new API.

// Note that current main branch do not compile with ArduinoGraphics as described in #282 but I did not fix it here for making this change unique to this feature.

@pennam pennam merged commit 613fc37 into arduino:main Nov 26, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants