cancel
Showing results for 
Search instead for 
Did you mean: 

Saving String to model

belair55
Associate III

Hi all,

I have an application where I need to save multiple names for use between screens. I initialize the name array in the model using char[] then push the pointer through the presenter to the screen I need. This part seems to work as the string initialized in the model is properly displayed in my container in my startup screen. I then have an editing screen that uses a keyboard. When a new name is entered in the keyboard buffer and copied to the local name string on the edit screen that seems to also work. The issue I have is when changing back to the startup screen. I am using a "set name" method to update the string in the model but when I return to the startup screen the name is suppose to be updated in the container but for some reason only the first character is updated and the remaining characters from the prior string are displayed. I figured this was possibly due to having a storage size of char and working in the views with unicodechar? So, when I typecast down to a char I'm getting blanks between the characters. So to fix this I wanted to use unicodechar for all string variable stuff, but for some reason touchgfx doesn't like that because I was initializing a unicodechar array with a (const char*). I tried casting the initializing strings but that didn't work. So I am now trying to just convert from char to unicodechar for leaving the model and then convert from unicodechar to char when saving to the model, but am also having issues here. I will include the area of code I am currently having problems with along with my error message. Any other strategies for doing this would be appreciated as well. I seem to be pretty hemmed up on this.

void Model::setMenuItemName(uint16_t index, touchgfx::Unicode::UnicodeChar* newName)

{

touchgfx_printf("menu item name in early model '%c%c%c%c' \n", newName[0], newName[1], newName[2], newName[3]);

char* tempbuff;

touchgfx::Unicode::toUTF8((const uint16_t*)newName, (uint8_t*)tempbuff, sizeof(menuItemName[index]));

memset(menuItemName[index], 0, sizeof(menuItemName[index]));

uint16_t i = 0;

while (tempbuff[i] != '\0')

{

menuItemName[index][i] = tempbuff[i];

i++;

}

touchgfx_printf("menu item name in model '%c%c%c'", menuItemName[0][0], menuItemName[0][1], menuItemName[0][2]);

}

error message:

C2440 '=': cannot convert from 'char' to 'char *' \touchgfx\gui\src\model\model.cpp 43

1 REPLY 1
Martin KJELDSEN
Chief III

You're correct to do a conversion between char and UnicodeChar

typedef uint16_t UnicodeChar;

Maybe something like:

static void convertUnicodeToAscii(uint16_t* in, uint8_t* out){
    while(*in != 0){
        *out++ = (uint8_t)*in++;
    }
    *out = 0;
}

/Martin