cancel
Showing results for 
Search instead for 
Did you mean: 

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

AKetc
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

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;
    ...
}

View solution in original post

10 REPLIES 10
Martin KJELDSEN
Chief III

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
Chief III
Martin KJELDSEN
Chief III

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
Associate III

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
Chief III

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
Associate III

Thanks. Going through it right now.

AKetc
Associate III

@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
Associate III

Done with it. Thankyou so much for the help.

Glad you solved it! :)