cancel
Showing results for 
Search instead for 
Did you mean: 

Hardware Button

AGeis.4
Associate III

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();

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief II

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 ...

View solution in original post

4 REPLIES 4
Yoann KLEIN
ST Employee

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 KLEIN
ST Software Developer | TouchGFX
MM..1
Chief II

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

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
Associate III

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