Skip to main content
Azeem
Associate II
November 13, 2020
Question

TouchGFX with the Hardware Button

  • November 13, 2020
  • 12 replies
  • 5113 views

Hi,

I am new to the TouchGFX library and trying to make it work with the STM32F429-DISC1 board. The touch display is working fine and I don't see any issues with it. I am now trying to work around the Hardware Button to work with the TouchGFX library.

On the board there is a PUSH button and I want to make it work with the screens. I know there is a workshop available for the Hardware button and TouchGFX interface.

Is there any example available to work with the Push button or Hardware Buttons with the TouchGFX library or any resources?

I would appreciate your help.

Thanks

Azeem

This topic has been closed for replies.

12 replies

Azeem
AzeemAuthor
Associate II
November 13, 2020

Hi,

I was littering reading the same post. Is it please possible to please share an example for the TouchGFX hardware interaction library?

MM..1
Super User
November 13, 2020

How you dont understand on this example ?

Azeem
AzeemAuthor
Associate II
November 13, 2020

Well, I am trying to get it work. If I am successful then I will let know otherwise I will have to come here again. Thanks

Michael K
Senior III
November 13, 2020

The "proper" way to do this is to check your hardware state in the model tick() function, and if it changes, call a virtual modelListener function. Any screen you want to respond to the button press should implement this function in its presenter. When the presenter method is called, get the data from the model and call an appropriate method on the view.

For example, let's say you want to turn a box a certain color if the button is pressed.

In Model.cpp:

bool buttonStatus = false; // this should be a private variable in Model.hpp, with a public accessor like getButtonStatus();
 
void Model::tick(){
 bool currentButtonStatus = checkButtonHardware(); // implement this on your own
 if(currentButtonStatus != buttonStatus){
 buttonStatus = currentButtonStatus;
 modelListener->buttonChanged();
 }
}

In ModelListener.hpp:

virtual void buttonChanged() {}

In Screen1Presenter.cpp: (of course create prototypes in .hpp)

void Screen1Presenter::buttonChanged(){
 if(model->getButtonStatus() == true){
 view.setBoxColor(BoxColorEnum::BLUE);
 } else {
 view.setBoxColor(BoxColorEnum::RED);
 }
}

Finally, in Screen1View.cpp (of course create prototypes in .hpp)

enum class BoxColorEnum{ RED, BLUE, ... }; // in hpp file
 
#include <touchgfx/Color.hpp>
 
void Screen1View::setBoxColor(BoxColorEnum color){
 switch(color){
 case BoxColorEnum::RED:
 box1.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 0, 0);
 break;
 //... and so on
 }
 box1.invalidate();
}

Your checkButtonHardware button can either check it directly (e.g. HAL_GPIO_ReadPin(GPIOx, GPIO_Pin)) or it can receive an event from the RTOS if your hardware is processed in another task. The important thing is that your state is stored in the model, the modelListener is informed of changes, interested presenters decide what view functions to call depending on the model state, and the view is only concerned with changing the visuals.

Beyond this, if setting a variable with the state of a hardware pin is already outside your knowledge, the TouchGFX forum is not the place to ask those questions. TouchGFX is a graphics framework only. Just because you can put UIs on discovery boards without much fiddling, it doesn't mean that all the work is done for you. You are responsible for implementing your own hardware routines, and more basic STM32 tutorials are where you could acquire this knowledge.

Disclaimer: code should be used as a reference only, I've not validated or compiled it.

Embedded UI/UX Consulting: cadenza.design
MM..1
Super User
November 13, 2020

Example explain perfectly chaos in Model hw management. WTF is model->getButtonStatus()

Michael K
Senior III
November 13, 2020
bool buttonStatus = false; // this should be a private variable in Model.hpp, with a public accessor like getButtonStatus();

https://classes.mst.edu/compsci1570/mutators.htm

Embedded UI/UX Consulting: cadenza.design
Alexandre RENOUX
Visitor II
November 17, 2020

Hello AMuha.1,

You can take a look at the G071-NUCLEO Application template available in TouchGFX Designer 4.15. This project uses a proper ButtonController class that is used by TouchGFX to check the state of the hardware buttons (in this project case, it's a joystick with 5 states).

The only difference that you will face is that you need to find out which pin you need to look at on the F429-DISCO to get the current state of the hardware button :)

Hope this will help.

/Alexandre

Azeem
AzeemAuthor
Associate II
November 17, 2020

Thanks Guys, I will take a look at the above examples. Appreciated