Skip to main content
AGeis.4
Associate II
February 3, 2023
Solved

Hardware Button

  • February 3, 2023
  • 4 replies
  • 1753 views

Hello, I have been trying for 2 days to read my hardware button from the STM32F746G board and change the color on the display. Unfortunately, all tutorials are for older versions where the file ButtonController.hpp still exists, but in TouchGFX 4.21.1 this file is not generated. The button is set up as BTN_USER with a pull-down in Cube MX. In the .touchgfx file, I have added

"PhysicalButtons": [ { "Key": 1, "Name": "BTN_USER" } ],

I also cannot manually call Screen1ViewBase::handleKeyEvent(uint8_t key) because I always get include errors. It can't be that difficult to read a physical button.

Screen1ViewBase.cpp:

void Screen1ViewBase::handleKeyEvent(uint8_t key)

{

if(1 == key) { //Interaction1 //When hardware button 1 clicked change color of box1 //Set RGB color R:255, G:0, B:0 on box1 box1.setColor(touchgfx::Color::getColorFromRGB(255, 0, 0)); box1.invalidate();

This topic has been closed for replies.
Best answer by MM..1

Dont waste time with buttoncontroller...

simply in model

void Model::tick()
{
...
 if ( HAL_GPIO_ReadPin(SW2_GPIO_Port, SW2_Pin) == GPIO_PIN_RESET && filter == true )
 {
 	 	modelListener->shape();
 }
 else if (((HAL_GPIO_ReadPin(SW4_GPIO_Port, SW4_Pin) == GPIO_PIN_RESET && filter == false) ) 
 {
 filter = true;
 static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(89);
 }
 else if (Key_Code==ENC_VOL_UP || RC5_Inst==IR_VOLUP)
 {
 static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(86);
 }
...

where handlekeyevent is created in designer as interaction after key pressed choiced ascii char...

plus if you choice ascii chars of letters , this too will work in simulator with pc keyboard.

And for example shape() is created in MVP presenter and view ...

4 replies

Yoann KLEIN
ST Employee
February 3, 2023

Hello @AGeis.4​,

We are aware of this issue with hardware buttons, and it should be fixed in the next version of TouchGFX 4.21.2, coming soon.

In the meantime, you could use an older version of TouchGFX.

Sorry for the inconvenience.

/Yoann

Yoann KLEINST Software Developer | TouchGFX
MM..1
MM..1Best answer
Super User
February 3, 2023

Dont waste time with buttoncontroller...

simply in model

void Model::tick()
{
...
 if ( HAL_GPIO_ReadPin(SW2_GPIO_Port, SW2_Pin) == GPIO_PIN_RESET && filter == true )
 {
 	 	modelListener->shape();
 }
 else if (((HAL_GPIO_ReadPin(SW4_GPIO_Port, SW4_Pin) == GPIO_PIN_RESET && filter == false) ) 
 {
 filter = true;
 static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(89);
 }
 else if (Key_Code==ENC_VOL_UP || RC5_Inst==IR_VOLUP)
 {
 static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(86);
 }
...

where handlekeyevent is created in designer as interaction after key pressed choiced ascii char...

plus if you choice ascii chars of letters , this too will work in simulator with pc keyboard.

And for example shape() is created in MVP presenter and view ...

Romain DIELEMAN
ST Employee
February 6, 2023

Hi,

I'll just chip in to give a link to Gustavo's video on Backend Communication and on how to interact between the hardware (button + led example) and TouchGFX through the model without the buttoncontroller.hpp file.

/Romain

AGeis.4
AGeis.4Author
Associate II
February 6, 2023

Thank you MM...1 it works. Switching to older versions did not work.