The key function of the Parola library is to display text using different animations. From version 2.7 onwards, Parola allows user code to manage mixing graphics with the text. The extensions to the library and what they do is the subject of this article.
What’s the Problem?
The MD_Parola library uses the MD_MAX72xx library to control the hardware. The MD_MAX72xx library implements methods that allow arbitrary points and lines to be drawn on the display. However, using a different instance of MD_MAX72xx from the one used by MD_Parola gives unpredictable results. Each instance has a separate buffer and communications with the matrix displays, causing display access and update conflicts.
An earlier article (here) explains how animations are constructed. It is clear that if the animation ‘clears’ the display between each frame, user graphics could be lost at the same time. So, once the hardware access conflicts are resolved, some additional method of coordinating between Parola and user code is needed as well.
Mixing Things Up
To allow direct access to the display, the getGraphicObject() method returns a pointer to the MD_MAX72xx object being used by Parola. This allows the application and the Parola library to share the same display with no resource conflicts.
Graphics drawn in a dedicated Parola zone (ie, not shared with text) are safe and persist until the application makes a change. However if a zone has mixed text and graphics, the application will need to manage the graphics portion much more closely, as the text animations will take priority.
Coordination of mixed text and graphics requires the application code to be aware of when the display has been animated. A text effect frame may be advanced during the Parola call to displayAnimate() – not every call to displayAnimate() results in an changed display – so it is important to know when the animation has actually advanced. The method isAnimationAdvanced() is used to check if the latest call to displayAnimate() resulted in an animation frame. With this knowledge, the application can refresh/redraw the graphics as required.
If isAnimationAdvanced() is used in a multi zone display, the method will tell you when one of the zones has advanced an animation frame. The application should check in which zone this occurred. This works the same as the displayAnimate() method.
The application should also make use of the getTextExtent(), getDisplayExtent() and getZoneExtent() methods to determine the columns bounding the respective areas. Using these methods ensures that the library and application will use consistent coordinates.
The relationship between these extents is shown in the figure above.
- The text extents are the first and last columns occupied by the text on the display. The start and end of the text string are always the left and the right boundaries, respectively. The text extents for a specific message are not known by the Parola library until the first text animation frame is drawn.
- The display and zone extents are the first and last columns of the display/zone. Note that the Parola coordinate X and Y axes increase to the left and down, respectively, from the top right corner (the origin).
The application has uncontrolled access to all the functionality of MD_MAX72xx, which means that it can unexpectedly interfere with the normal running of the Parola library.
Not all text effects work well mixed with graphics, so experiment and try different combinations.
Drawing graphics will slow down text animations, sometimes considerably.