I prefer centered text on the LCD for legibility, so I wrote a small function to center text for me after I got tired of calculating the offsets in my head:
This code works well enough and takes the current 'character magnification coefficient' into consideration as well. It's not complicated.
I used the strlen() function twice here: once in calculating the horizontal offset and again to inform the DRAW_DisplayString() function how many characters to display. A more optimized solution would determine the string length once and store it in a local variable instead of calling the strlen() function twice with the same, unchanged parameter.
As written, this code will build but generates a warning:
If I #include the string function header file...:
then the above warning goes away but it replaced with another one:
...complaining of the use of the strcmp() function in the CircleOS version check at the beginning of the application initialization function, Application_Ini(), because the UTIL_GetVersion() function, which is documented as returning a "const char *" is actually returning a "u32" per the circle_api.h include file.
Adding a cast to the function call removes the warning. I'm not sure how to correct the header file as I am unfamiliar with the technique being used in the function declarations.
Thanks,
Dale Wheat