cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement "SwitchScreen()" in touchgfx?

kvkhekale
Associate II

Hello all,

I am trying to switch the screen throuch code in touchgfx.

If I use SwitchScreen, how shall I state the argument (screen* newScreen)?

If, for example I want to switch to Screen7.

Shall I call the function with SwitchScreen(scr7)?

where scr7 is declared as follows:

ScreenView7 scr7;

33 REPLIES 33

Did you ever do the video for this. Are they any examples?

Hi,

I am unsure if Martin did a video on this, but I believe this one from Gustavo might help you. In this project he uses a hardware button to interact with his GUI (he makes a box widget appear/disappear). You can adapt his interaction to a screen transition if it is what you need.

Hope this helps.

/Romain

Many thanks for responding. That is useful information, but does not answer my specific question. I have an IMAGE when clicked that I would like to change the screen. As I cannot add an interaction to change screen based on the click of an IMAGE in the TouchGFX app I need to add a click-listener handle within the code. I have done that, and I can hit the designated breakpoint when I click the image. What I do not know how to do in the code is to switch to a different screen. Within gui_generated/src/common/FrontEndApplicationBase.cpp are the interactions for switching screens that were created within and by the TouchGFX application. Within gui/src/common/FrontEndApplication.cpp I am supposed to be able to write my own screen interactions which I then call from my touch listener handle. The issue is I do not know how to write an interaction to change screens. Can you please provide an example of this: Change to screen name "Screen_AD", Transistion = Wipe, Direction = East.

This does not answer the question directly but it is a work around that accomplishes pretty much the same thing. It will allow me to keep working and push figuring this out for another day. Just three simple steps within the touchGFX app is all that is necessary:

  1. Place your image (do not select the clicklistner option)
  2. Place a flexbutton widget over the image (size to match image)
  3. Add the interaction as you normally would for the flexbutton to change screen or do whatever

Why can't you make an image into a button?

Just use the same image as both the clicked and unclicked source picture?

Anyway, the code you are probably looking for is:

static_cast<FrontendApplication*>(Application::getInstance())->gotoIDScreenScreenNoTransition();

Just make sure that the transition code is actually generated. If you have a screen that is only accessed programatically you need to make a button somewhere offscreen and add an interaction to that button. that way you have the interaction generated.

Your solution is better. I am working my way through TouchGFX , I did not realize that was possible; now I see it. I played with the development board for a bit, now I have my own hardware. So I learn a little more each time. Thanks so much for responding. Now I have another way to get this done.

Hi Martin,

I (think I) did what you suggested:

  • in the Designer I generated a screen change to the screen I wanted to appear (only programmatically, not by UI interaction)
  • I cut & pasted the generated methods from FrontendApplicationBase.cpp to FrontendApplication.cpp (applying the needed corrections to method names)
  • I added this in the protected section of FrontendApplication.hpp
    touchgfx::Callback<FrontendApplication> transitionCallback;

but I keep getting this compiler error:

invalid initialization of reference of type 'touchgfx::MVPHeap&' from expression of type 'FrontendHeap'

at this line

 touchgfx::makeTransition<Screen_resetView, Screen_resetPresenter, touchgfx::NoTransition, Model >(&currentScreen, &currentPresenter, frontendHeap, &currentTransition, &model);

What am I missing?

Thanks in advance for your help,

Andrea

GBert.2
Senior

I don't think I have the perfect answer, but here's my workaround:

How do you switch between screens from the Model.cpp?

Using the Application handle, I was able to change screens.

#include <gui/common/FrontendApplication.hpp>
 
void Model::forceScreenTransition(eScreenIndex_t const eScreenIndex)
{
    FrontendApplication *const poApp = static_cast<FrontendApplication *>(Application::getInstance());
    switch (eScreenIndex)
    {
    default:
    case SCREEN_UNKNOWN: break; //< Do nothing.
    case SCREEN_SELF_TEST: poApp->gotoSelfTestScreenNoTransition(); break;
    case SCREEN_WAITING_CONNECTION: poApp->gotoWaitingConnectionScreenNoTransition(); break;
    // etc ...
    }
}

But what if the gotoMyScreen() function has not been generated?

For some reason, TouchGFX does not generate the transition functions for a screen without an interaction.

My workaround was to add a useless interaction (When hardware button is clicked, switch to <my screen>) to force TouchGFX Designer to generate the code in FrontendApplicationBase.cpp.

Hope it helps.

Sharing is caring.

See my reply for an idea. (3 years late, but maybe it will still be helpful)

I have done this step by step. Each step is committed and explained in git so you can see how to add very few lines of codes, test them and go ahead.

Last commit that enter SettingsMenu if user button is pushed is 0c571f9.

https://github.com/RPatriziDesign/STM32F769-DiscoProject01/network

Regards, Roberto