cancel
Showing results for 
Search instead for 
Did you mean: 

TGFX Class Life Cycles or How to change screens programmatically on startup?

M-Schiller
Associate III

Hi again,

I'm currently working on a TouchGFX project that requires me to have some one-time setup with some screens that are only shown to the user if the device is not yet set up, Let's call the first of these screens "WelcomeScreen" as opposed to the "MainScreen" for the sake of brevity.

So, if the device is set up, I want to show the MainScreen to the user, and if the setup procedure is not yet done, I want to show the WelcomeScreen to the user.

What I have tried now is

  1. add a method `bool isSetupComplete()` to the Model class.
  2. add invisible buttons that have dummy "Change Screen" interactions attached, and
  3. basically copy the code generated when adding a transition on a button in a view, i.e.
FrontendApplication& Model::application()
{
  return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
}

and then add the following lines to the Model's c'tor:

if(setupIsComplete())
{
  application().gotoMainScreenNoTransition();
}
else
{
  application().gotoWelcomeScreenNoTransition();
}

While testing for different return values of `isSetupComplete` I observed that it doesn't matter what it returned as the calls to gotoXXXScreenNoTransition() have no effect in the Model's c'tor.

Since I thought maybe Model construction occurs too early and the touchgfx::Application is not yet fully initialized at that point, I moved the "switching logic" into the WelcomeScreen's Presenter's `activate` method, which now looks like this:

void WelcomeScreenPresenter::activate()
{
  if(model->isSetupComplete())
  {
    model->goToMainScreen();
  }
}

Again, no matter what `isSetupComplete` returns, the screen change does not occur. After the initial troubles, I can change screens programmatically with the method described above without any issues.

Am I missing something here? Is there a better way to change screens according to variables at runtime?

Best Regards,

Michael

1 ACCEPTED SOLUTION

Accepted Solutions
Osman SOYKURT
ST Employee

Hello Michael,

What I would do is kind of a "splash screen" that you can configure the behavior, like if isSetupComplete returns true, then change screen to Mainscreen, else change to WelcomeScreen.

There's already a post on the forum explaining how to make it, I invite you to have a look at .

Also, I attached a simple project that does it, you can use it for reference.

Let me know if you succeed on what you want to do, and if you need further help 🙂

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX

View solution in original post

3 REPLIES 3
Osman SOYKURT
ST Employee

Hello Michael,

What I would do is kind of a "splash screen" that you can configure the behavior, like if isSetupComplete returns true, then change screen to Mainscreen, else change to WelcomeScreen.

There's already a post on the forum explaining how to make it, I invite you to have a look at .

Also, I attached a simple project that does it, you can use it for reference.

Let me know if you succeed on what you want to do, and if you need further help 🙂

/Osman

Osman SOYKURT
ST Software Developer | TouchGFX
M-Schiller
Associate III

Thanks for your response. I looked at the code and figured that the procedure is something like.

  • Wait for 1st screen to render (splash screen)
  • When rendered, call a method (check where to go)
  • When this method executes, call one of two actions
  • depending on the action being called, change the screen to one of two possibilities.

This results in the splash screen being rendered a split-second before another screen is being shown.

What I am still curious about is, why is it possible to switch the screen at that point in time but neither in the Model's C'tor nor in the initial screen's presenter's activate?

If this not at all possible, I'll have to check back with our customer to see if they are fine with a splash screen being shown.

M-Schiller
Associate III

I have now used something very close to what @Osman SOYKURT​ suggests with the splash screen being empty (except for the background color), having two actions as described and doing the following:

  • Start at splash screen
  • When transition to splash screen ends, wait for 50ms
  • When the wait is over, call a virtual method and call actions accordingly
  • change to screen{1,2} when action{1,2} occurs