Skip to main content
AKetc
Associate III
October 16, 2019
Solved

How to switch screen using user code when a certain flag becomes true.

  • October 16, 2019
  • 9 replies
  • 2360 views

I have gone through the methods that are gui generated when change screen transition is done through the designer. I have also gone through the previously asked question how to implement switchscreen() in touchgfx. However, sadly I don't understand exactly how to fulfill my requirement. I want to carry out transition whenever a certain boolean variable becomes true. The variable becomes true after response from the hardware. Please guide me on how to implement this. I shall be thankful.

This topic has been closed for replies.
Best answer by Martin KJELDSEN

Some code for checking things in Model::tick where GUIEvent is the name of the message queue, ControlMessage is a struct that contains a message code and a value

typedef struct
{
 uint16_t messageCode;
 int16_t messageValue;
} ControlMessage;
 
...
 
void Model::tick()
{
 ...
 osEvent event = osMessageGet(GUIevent, 0); // Get GUIevent immediately
 if (event.status == osEventMessage)
 {
 // handle event
 ControlMessage* message = (ControlMessage*)event.value.p;
 switch (message->messageCode)
 {
 case MESSAGE_TYPE1:
 //go to type 1 screen
 break;
 
 case MESSAGE_TYPE2:
 //go to type 2 screen
 break;
 ...
}

9 replies

Martin KJELDSEN
Principal III
October 17, 2019

Hi,

If you're looking to change screens based on some hardware input you'd typically send this through an OS message queue to the gui task and handle the message in your model on every tick - THEN do your transition. Please check out the "integrating hardware and ui" sticky - I did a webinar on this very topic last year. Then you can use the goto... code that you've found here on the forum to make the transition.

/Martin

Martin KJELDSEN
Principal III
October 17, 2019
Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
October 17, 2019

Some code for checking things in Model::tick where GUIEvent is the name of the message queue, ControlMessage is a struct that contains a message code and a value

typedef struct
{
 uint16_t messageCode;
 int16_t messageValue;
} ControlMessage;
 
...
 
void Model::tick()
{
 ...
 osEvent event = osMessageGet(GUIevent, 0); // Get GUIevent immediately
 if (event.status == osEventMessage)
 {
 // handle event
 ControlMessage* message = (ControlMessage*)event.value.p;
 switch (message->messageCode)
 {
 case MESSAGE_TYPE1:
 //go to type 1 screen
 break;
 
 case MESSAGE_TYPE2:
 //go to type 2 screen
 break;
 ...
}

AKetc
AKetcAuthor
Associate III
October 17, 2019

I am actually not understanding how to make the transition with user code.

I saw the methods generated by the designer when you do transition using the designer. Now if I don't want to use designer for transition, should I leave the GUI generated methods as well and override them or delete the gui interaction and write my own function. Also in which class should I write the goto custom function.

Martin KJELDSEN
Principal III
October 17, 2019

There was a similar question recently, so i figured you might have seen it. Here it is:

https://community.st.com/s/question/0D50X0000BTdnsASQR/how-can-i-change-screen-in-software

AKetc
AKetcAuthor
Associate III
October 17, 2019

Thanks. Going through it right now.

AKetc
AKetcAuthor
Associate III
October 19, 2019

@Martin KJELDSEN​ I am sorry, I tried but not able to understand how to implement.

  • In my Frontendapplication.hpp and .cpp files, I have defined custom transition functions.
  • In my MainView, I have defined a custom function that calls static_cast<FrontendApplication*>(Application::getInstance())->gotoScreen2();

The problems are

  1. The compiler gives error that covertransition is not a member of touchgfx (I am not able to understand which Library I am missing.
  2. Is my above mentioned approach correct? Apart from the error being thrown?

AKetc
AKetcAuthor
Associate III
October 20, 2019

Done with it. Thankyou so much for the help.

Martin KJELDSEN
Principal III
October 21, 2019

Glad you solved it! :)

MPhil.1
Visitor II
February 7, 2020

@AKetc​ would you be so kind to share how you accomplished this? I am in a similar scenario where I want to change the screen based on a flag. Any help would be appreciated. Thank you! Mike