satspares / DWIN_DGUS_HMI

Arduino Libabry for DWIN DGUS T5L HMI Displays
15 stars 3 forks source link

How send unicode Text? #9

Closed pbenaim closed 5 months ago

pbenaim commented 6 months ago

Hi,

Thanks for this nice library 😍

Somebody make one function to send Unicode Text? Like setTextUnicode (long address, String textData) ;🤔

Thank you for your suggestions.

Philippe

pbenaim commented 5 months ago

This code is only for Unicode between 0000 and 00FF Over 00FF, you must adapt Pre VAR...

Dont' Forget that Unicode is in 2 Bytes, so you must define NbCaract * 2 in DGUS

So If you want ( for example ) 4 Chars , you must define 8 chars in DGUS...

Last thing: Don't forget to declare void setUnicodeText(long address, String textData); in your DWIN_Arduino.h

Don't forget, again, either, that the addresses must not overlap. For example, if you want 100 characters, the next address must be greater than twice (unicode, of course because twice as much space)

I wasted a lot of time with this. I hope this will be useful to you and that you will lose less than me...

Do us a favor and let us know your progress...

So my Code is:


void DWIN::setUnicodeText(long address, String textData)
{
    byte ffEnding[2] = { 0xFF,0xFF };
    int dataLen = textData.length();
    int dataLen_Unicode = textData.length() * 2;

    byte startCMD[] = { CMD_HEAD1, CMD_HEAD2, (uint8_t)(dataLen_Unicode + 5), CMD_WRITE,
                       (uint8_t)((address >> 8) & 0xFF), (uint8_t)((address) & 0xFF) };

    byte dataCMD[dataLen];
    textData.getBytes(dataCMD, dataLen + 1);

    byte dataCMD_Unicode[dataLen_Unicode];
    byte Pre = 0;

    int Pos_dataCMD_Unicode = 0;

    for (int pos = 0; pos < dataLen; pos++)
    {
        dataCMD_Unicode[Pos_dataCMD_Unicode] = Pre; // Base under 00FF
        Pos_dataCMD_Unicode++;

        dataCMD_Unicode[Pos_dataCMD_Unicode] = dataCMD[pos];
        Pos_dataCMD_Unicode++;
    }

    byte sendBuffer[8 + dataLen_Unicode];

    memcpy(sendBuffer, startCMD, sizeof(startCMD));
    memcpy(sendBuffer + 6, dataCMD_Unicode, sizeof(dataCMD_Unicode));
    memcpy(sendBuffer + (6 + sizeof(dataCMD_Unicode)), ffEnding, 2); // add ending 0xFFFF

    _dwinSerial->write(sendBuffer, sizeof(sendBuffer));
    readDWIN();

}