guix
January 8, 2022, 3:22am
21
But it's not possible, ä cannot be stored in one char, you should have a compiler warning about that : 'ä'
However, you can have a function that searches in a string and replaces the utf8 characters by whatever you want
Here is an example : t703532.ino - Wokwi Arduino and ESP32 Simulator
Thanks, seems to be working, now ÅÄÅ and åäö works just fine, any idea on how I can add the scrolling features also to your example. I tried this but it do not work.
void setup()
{
P.begin();
char str[] = "ÅÄÖåäö";
P.displayText(replace_utf8( str ), PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT );
}
void loop() {
if (P.displayAnimate()) {
P.displayReset();
}
}
guix
January 8, 2022, 3:02pm
23
I don't know, it works for me. At least, on wokwi.. t703532_2.ino - Wokwi Arduino and ESP32 Simulator
Really strange. With just "P.print( replace_utf8( str ) );" it works great, but when adding scrolling parameters is displays this:
This is the code I am using now:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 8
#define CLK_PIN D5 // or SCK
#define DATA_PIN D7 // or MOSI
#define CS_PIN D8 // or SS
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
struct Substitute
{
char const * const utf8;
uint8_t const sub;
};
Substitute substitutes[] =
{
{ "Å", 0xC5 },
{ "Ä", 0xC4 },
{ "Ö", 0xD6 },
{ "å", 0xE5 },
{ "ä", 0xE4 },
{ "ö", 0xF6 },
};
size_t const substitutes_count = sizeof( substitutes ) / sizeof ( substitutes[0] );
char * replace_utf8( char * const str )
{
char *p = str;
while ( *p )
{
if ( (*p & 0xFF) > 127 )
{
for ( size_t i = 0; i < substitutes_count; ++i )
{
size_t len = strlen( substitutes[i].utf8 );
if ( !strncmp( p, substitutes[i].utf8, len ) )
{
*p = substitutes[i].sub;
strcpy( p + 1, p + len );
break;
}
}
}
++p;
}
return str;
}
void setup()
{
P.begin();
char str[] = "testar";
P.displayText(replace_utf8( str ), PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT );
}
void loop() {
if (P.displayAnimate()) {
P.displayReset();
}
}
guix
January 9, 2022, 1:39am
25
Did you try to put str in global scope ..?