Closed makelion closed 6 years ago
Did you measure the time difference between just setting the font and implementing your selection logic? Setting the new font requires very few operations and should be comparable to the 'if/else' logic. Would be interested in the benchmarks if you have some as I am all for efficiency but I don't see it in this case.
You are right!!! My bad!!! I was using the old version of the MD_MAX72XX and MD_Parola libraries when I added the getFont functions and I didn't check the new version of the MD_MAX72XX library assuming there was the same setFont function. I worked with the old:
bool MD_MAX72XX::setFont(fontType_t * f)
{
_fontData = (f == NULL ? _sysfont_var : f);
buildFontIndex();
return(true);
}
And there was some difference in speed. The new one:
bool MD_MAX72XX::setFont(fontType_t *f)
{
if (f != _fontData) // we actually have a change to process
{
_fontData = (f == nullptr ? _sysfont_var : f);
loadFontInfo();
}
return(true);
}
solves the problem of speed. Maybe there is no need of getFont functions anymore... the only case I think getFont can be useful is for conditional print. In example to print the time using different font:
if(P.getFont() == slimfont) P.print("12:34:56"); // fit in the display
if(P.getFont() == largefont) P.print("12:34"); // while 12:34:56 does not fit in the display
if you do that, without getFont, you have to use another variable as flag for the used font. The example is not great but I hope gives an idea of what I meant. Anyway, great libraries.
getFont() is easy to implement, so no problems having it. I just don't think it will used much.
In the old setFont(), buildFontIndex was only available if the USE_FONT_INDEX was set to 1, which it was not by default, so setFont() was basically just copying a pointer. buildFontIndex() has been eliminated in the new version as it provided no real speed improvements over linear search through the font table.
I find useful in my project to use getFont function to check if the font set is the one I need, instead of setting every time the font to use (slower). Usage example:
I think that can be useful for other project too. You may consider to add this feature in the library.