cancel
Showing results for 
Search instead for 
Did you mean: 

Switching Screen by HW button?

mibra.1
Associate II
  • HI All,

I'm having an issue regarding switching screen.

in My GUI, i have Screen one and Screen two,

1- in screen one i set an interaction for changing the current screen (to screen two) by hardware button and i generated the code correctly and i found the next API

//Handles when a key is pressed

void Screen1ViewBase::handleKeyEvent(uint8_t key)

{

  if(0 == key)

  {

    application().gotoScreen2CoverTransitionEast();

  }

}

2- i used this handleKeyEvent(0) (in certain event) , in the screen1 view, but i didn't succeed to switch the screen2.

3- after debugging , i found that i actually go to the screen two setupScreen, the screen doesn't appear on the lcd.

Q: i want how ask how to use handleKeyEvent() properly ? do i use it in the screen view or the presenter or the model?

7 REPLIES 7
Alexandre RENOUX
Principal

Hello,

You can use handleKeyEvent() in your ScreenView.

Are you sure the code that handles the hardware button is correctly implemented ? Retrieving correctly the GPIO state for instance.

You might find some useful information there : https://support.touchgfx.com/docs/development/ui-development/touchgfx-engine-features/backend-communication

and https://support.touchgfx.com/docs/development/board-bring-up/example-gpio#touchgfx-hal-development and https://support.touchgfx.com/docs/development/board-bring-up/how-to/10-physical-buttons

Can you provide more code like your screen2View.cpp ?

/Alexandre

mibra.1
Associate II

HI Alexandre,

regarding the hardware button, yes have tested the function of the the button and it works fine for different task.

-----------------------------------------------------------------------

1- Screen1View.cpp

Screen1View::HomeView()

{

}

void Screen1View::setupScreen()

{

  Screen1ViewBase::setupScreen();

}

void Screen1View::tearDownScreen()

{

  Screen1ViewBase::tearDownScreen();

}

void Screen1View::UpdateNavigation()

{

if(KEY_enumGetKeyStatus(KEY_EncoderSW) == KEY_PRESSED)

{

Screen1ViewBase::handleKeyEvent(0);

}

}

-----------------------------------------------------------------------

2- Screen2View.cpp

Screen2View::MyInforationView()

{

  

}

void Screen2View::setupScreen()

{

  Screen2ViewBase::setupScreen();

}

void Screen2View::tearDownScreen()

{

  Screen2ViewBase::tearDownScreen();

}

-----------------------------------------------------------------------

3- after debugging i found that the execution go to ( Screen2View::setupScreen() ), but screen2 doesn't appear on the lcd.

4- i have tested to use touch button to change screen from screen1 to screen2 and it was working fine but when i add the hw button feature i didn't succeed to do the same by the hw button

Alexandre RENOUX
Principal

Hello,

I don't understand why you implemented handleKeyEvent in Screen1ViewBase. You should never write code in this file as it is generated code from Designer.

Again I suggest you to look at the examples that you will find on this link: https://support.touchgfx.com/docs/development/ui-development/touchgfx-engine-features/backend-communication

Also, when you call application().gotoScreen2CoverTransitionEast(), is this function generated in FrontApplicationBase.cpp (I think it is but just in case) ?

Btw, there is a button called "</>" when you are typing your message on the forum. This allows to add code so that it is easier to read it.

Finally, what board are you using ? Could you provide the code of your project ?

/Alexandre

mibra.1
Associate II

HI,

regarding handleKeyEvent implementation, i using touchgfx designer and i just added the required interaction for the HW button to change the from screen1 to screen2. after i generated the code by the touchgfx designer. So, i didn't implement the handleKeyEvent . i just found it in Screen1ViewBase.

i'm using STM32F769I-DISCO board.

regarding the "application().gotoScreen2CoverTransitionEast()" implementation in FrontApplicationBase.cp, i will review it to make sure.

and i need know to which part of my code/project you want me to provide?

Hello,

"i need know to which part of my code/project you want me to provide?"

Could you provide all the code that is related to your HW button implementation (even the generated code like the one in Screen1ViewBase.cpp and .hpp) ?

/Alexandre

mibra.1
Associate II

Hi Alexandre,

with your help and after debugging, i found the problem and the required solution

But before describing the problem and the required solution, i wanted to say that i found two ways to use HW button to change/switch the screen

1) Using KeySampler.cpp and Buttons.cpp modules generated by touchgfx

  • In TouchGFXHAL.cpp, touchgfx continuously scan/sample the used HW buttons and fire the required callback ( handleKeyEvent() ) directly when the key/button is pressed
  • the callback can be any thing (according to the implemented interaction, in my case the interaction is to change the screen)

2) Calling handleKeyEvent() in ScreenView

  • i wanted to use this way to control when call handleKeyEvent() at time i want (even if the key is not pressed)
  • in this method i have disable/cancel the of KeySampler.cpp, to control the handleKeyEvent() calling (from one source only "ScreenView")

The problem and the required solution

  • After using KeySampler.cpp method, that i only can change screen without any transition
  • And if tried change to another screen with transition, i fail
  • I confirmed this solution the second method (ScreenView) and succeed to change only the screens without any transition
  • i can continue debugging to understand why i can't change screens with transition, but for now i can work with solution

Hello,

Thank you for this explanation. I'm glad you found a solution and can move forward from now on.

Regarding the screen transitions, what transition did you try ? If it's the Slide transition then it might be normal. In fact, to be able to use the slide transition you need to allocate a certain amount of memory for this, otherwise it will never perform the animation and will automatically switch to the next screen.

To do so, you need to specify the start address in TouchGFXGeneratedHAL.cpp file as a parameter of the following function call:

setFrameBufferStartAddresses((void*)0xC0000000, (void*)0xC003FC00, (void*)0); //Third parameter corresponds to the buffer for the slide transition

Hope this will help,

/Alexandre