cancel
Showing results for 
Search instead for 
Did you mean: 

Change the visibility of a generated image?

TStum.1
Associate II

Hello,

my problem is simple, but I don't seem to understand TouchGFX well enough to find the solution.

I have created a simple GUI with TouchGFX Designer. The GUI of this project consists of 1 screen "Screen1" with an image "image1". As usual, TouchGFX Designer adds this image1 in Screen1ViewBase.cpp.

I want to change the visibility of image1 at a certain point of my application sequence. For this, I have added the following function to Screen1View.cpp:

void Screen1View::ChangeImageVisibility()

{

   if(Screen1ViewBase::image1.isVisible())

   {

      Screen1ViewBase::image1.setVisible(false);

   }

   else

   {

      Screen1ViewBase::image1.setVisible(true);

   }

   Screen1ViewBase::image1.invalidate();

}

When I call ChangeImageVisibility() from my application, the image is still visible. I checked in the debugger, ChangeImageVisibility() is called and executed.

For a quick check, I added a button in the TouchGFX Designer that and three interactions that make the image invisible and visible again after 1000ms. This button works as expected.

What am I doing wrong with ChangeImageVisibility()?

Thank you very much for your help in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
LTimm.1
Associate III

If it is the task context issue, then this link really gives all the information needed: https://touchgfx.zendesk.com/hc/en-us/articles/205074561-Connecting-the-UI-to-your-system

An easy way to verify is to call ChangeImageVisibility() from Model::tick.

Maybe add a counter and increment it every time tick is called (How often tick is called is depending on you display configuration, but apx. every 16 ms)

Every time the counter reaches 120 call the ChangeImageVisibility().

If this works, then you can experiment with the more advanced methods with message queues to change thread context.

View solution in original post

6 REPLIES 6
LTimm.1
Associate III

Not sure if this is your problem or not, but changing UI elements must only be done from the UI thread context. Doing it from another application thread does not work as expected.

Button interactions are automatically execution in the UI thread context, so that could be why they work as expected.

If this is your issue, then this is a good read: https://touchgfx.zendesk.com/hc/en-us/articles/205074561-Connecting-the-UI-to-your-system

Romain DIELEMAN
ST Employee

Hi,

Your function works fine. I tested it as well to make sure with a simple project using an image, a background and a button to call the function. You can remove Screen1ViewBase:: when you use image1 by the way. The only thing that I can think of is have you actually put a background image? You always need one when using TouchGFX.

If this is not the issue, please add some more code and an image of your project on designer to have a better insight of this problem. Thanks.

/Romain

TStum.1
Associate II

Hello Ltimm.1,

hello Romain,

thank you for your replies.

My screen consists of a white box as background, a button and a small image. So I think this is not the problem.

I attached a zipped file to this message that contains my example project. This project contains a GUI created with TouchGFX Designer template for STM32F769I-DISC0 board. I added a FreeRTOS task "TestTask" that calls a sequence "TestTaskSequence()". In this sequence, ChangeImageVisibility is called every 2000ms. Additionally, I added a button that calls a virtual function that also calls ChangeImageVisibility(). I tested both cases individually, i,e. in the first test only the call by button was enabled and in the second test only the call by TestTaskSequence() was enabled. Th call by button worked as expected whereas the call by TestTaskSequence() did not work.

Is this the problem that LTimm.1 mentioned? If yes, how can I solve this problem so that I can call ChangeImageVisibility() by another task (like TestTask)?

Thank you very much for your help and your effort. Looking forward to your answers. If you need more information, please let me know.

LTimm.1
Associate III

If it is the task context issue, then this link really gives all the information needed: https://touchgfx.zendesk.com/hc/en-us/articles/205074561-Connecting-the-UI-to-your-system

An easy way to verify is to call ChangeImageVisibility() from Model::tick.

Maybe add a counter and increment it every time tick is called (How often tick is called is depending on you display configuration, but apx. every 16 ms)

Every time the counter reaches 120 call the ChangeImageVisibility().

If this works, then you can experiment with the more advanced methods with message queues to change thread context.

TStum.1
Associate II

Hello LTimm.1,

thanks again for your reply.

I tried the approach you linked (Model::tick and ModelListener) and it works. I think this is the correct way to implement the wanted behavior of my application.

Thank you very much for your help.

LTimm.1
Associate III

I'm glad it worked. :)

It's great that we are able to help each other.