2023-02-03 05:20 AM
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();
Solved! Go to Solution.
2023-02-03 06:20 AM
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 ...
2023-02-03 06:05 AM
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
2023-02-03 06:20 AM
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 ...
2023-02-05 07:13 PM
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
2023-02-05 10:50 PM
Thank you MM...1 it works. Switching to older versions did not work.