2020-07-13 04:01 AM
Hi,
I'm using list layout for my UI application. I'm holding some settings on the list and saving that data into flash. But when I erase an element(for example element 3 out of 6). element 3 erasing on the screen but not from the buffer. So when I write the data to flash I element 3 is still there but 6 is gone.
In here I don't have any elements and data on flash
Here I wrote data on flash
And here I erased second element (name two) and it didn't erase but number four is gone.
I'm using list example's code for erasing.
void listElement::deleteAction()
{
if(viewCallback-> isValid())
{
viewCallback-> execute(*this);
}
}
void settingsView::listElementClicked(listElement& element)
{
list.remove(element);
scrollCnt.invalidate();
}
2020-07-13 10:05 PM
Hello,
Could you attach your UI project to this post ? This way it will be easier to find an issue if there is.
Also, you probably did, but maybe looking at the ListLayout Example available on TouchGFX Designer can help you.
/Alexandre
2020-07-13 11:13 PM
Yes, I did look at the example and did it same but it works like that. Here is the link. I'm using listLayout on the settins_screen.
https://drive.google.com/file/d/1rZStIzJsNxjwUpRAGnX__e_1w_JoRUm8/view?usp=sharing
2020-07-14 12:37 AM
Hello,
I downloaded your project.
But I still need some clarifications :
/Alexandre
2020-07-14 01:25 AM
Hi, sorry for unclear post.
Yes it did removed from the screen but it is still in the memory. After I erased listElements[1] (named two) and write the whole list to the flash, it appears I couldn't erase listElements[1] insted I erased listElements[3](named four).
By buffer I mean from the memory alocation for list elements.
And it appears when I write it to flash (When I executed void settingsView::saveButtonHandler()) and all this function does is reading list elements and write them to the flash.
Thanks.
2020-07-14 02:06 AM
I checked it again it seems number four doesn't erase too. I don't write it to the flash because I decrease the listIndex whenever I erase element so I exit from the loop before number four is written. So my new problem is when I erase element it isn't exactly erasing It just doesn't seem on the screen. Can I actually erase or destroy one of the list elements? Not just from the screen but from the RAM as well.
2020-07-14 07:21 AM
Hello,
I think I found why it does not work and it's a coding mistake.
Here you can see the two functions (the one that saves in the Flash and one that is supposed to delete the element):
void settingsView::saveButtonHandler()
{
HAL_FLASH_Unlock();
FLASH_Erase_Sector(FLASH_SECTOR_1, VOLTAGE_RANGE_3);
HAL_FLASH_Lock();
listIndexSaved = listIndex;
int valf1, valf2, valf3;
for(int i = 0; i < listIndex; ++i)
{
nameBufferptr = listElements[i].getBuffer();
valf1 = listElements[i].getValueBuffer(1);
valf2 = listElements[i].getValueBuffer(2);
valf3 = listElements[i].getValueBuffer(3);
Unicode::strncpy(nameBuffer, nameBufferptr, BUFFER_SIZE);
// Some other code ....
}
}
/*
* removes element from the list
* */
void settingsView::listElementClicked(listElement& element)
{
list.remove(element);
--listIndex;
if(listIndex <= 0)
listIndex = 0;
scrollCnt.invalidate();
}
I you look closely, you remove item from list but you take the string from listElements. And from what I understood so far you don't delete the correspond element in listElements.
/Alexandre
2020-07-14 11:17 AM
Oh okay, I got it. But there is no function for deleting an element from listElements. So I have to do is shift other elements and overwrite to the element that I want to delete?
2020-07-15 02:57 AM
Hello,
This is your own list declaration, therefore it's normal that no function is available if you didn't implement any.
listElement listElements[numberOfListElements];
To remove an element, you have to delete the element like you would do in any project involving a list.
/Alexandre