2025-01-08 07:47 AM - last edited on 2025-01-08 08:55 AM by SofLit
Hi,
I have been trying to implement the functionality to change the currently active screen on TouchGFX using a hardware button with no luck so far.
I'm using an STM32H743zit6.
Here are the resources I've looked at but haven't managed to get working:
https://www.youtube.com/watch?v=ufvJ5bcesL8
https://www.youtube.com/watch?v=QgEDSjvGAlk
https://support.touchgfx.com/docs/development/scenarios/example-gpio
https://support.touchgfx.com/docs/development/board-bring-up/how-to/10-physical-buttons
https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/hardware-button/td-p/640357
Any help would be greatly appreciated,
Thanks.
2025-01-08 08:14 AM
@Josh_W020 wrote:Here are the resources I've looked at
What we really need to see is what you've done.
@Josh_W020 wrote:I have been trying to implement the functionality to change the currently active screen on TouchGFX using a hardware button .
Which part are you stuck on:
2025-01-08 08:52 AM
Hello,
I think you need to use application().gotoScreen2CoverTransitionxxx() API from the button callback.
See for example this thread.
2025-01-08 11:01 AM - edited 2025-01-08 11:03 AM
Ohh boy zero info... Try this
run simultor and press A key on keyboard Work transition ?
Interaction1 in my example is add on main screen (FYI your screen marked to start) and transition go to Screen1...
When this works ok you can step to physical button code ...
2025-01-09 01:26 AM
Hi thanks for the reply,
I have tried setting the hardware button up in this way and the screen changes as expected in the simulator.
I also know the hardware button is working as I have another button used for saving images to a USB that works correctly.
However, if you have any suggestions on how to call the change screen functions through code even without pressing a button that would be great too (for example calling it after a short delay in the main while loop).
Josh
2025-01-09 01:30 AM - edited 2025-01-09 01:31 AM
The transition is done using the call of application().gotoScreenXXXTransitionYYY()
See the link I share previously.
2025-01-09 01:40 AM
Hi,
I already have a different hardware button implemented for a separate function so I believe this is working correctly.
Sorry if I haven't provided enough info, I'll drop some code in below that i have tried so far.
Button setup in TouchGFX:
This is the cpp file as created in the youtube video provided by STM.
#include <newButtonController.hpp>
#include <main.h>
#include <touchgfx/hal/HAL.hpp>
extern "C" uint8_t User_ButtonState;
void newButtonController::init()
{
previousState = 0xFF;
}
bool newButtonController::sample(uint8_t& key)
{
if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_2) == GPIO_PIN_RESET && previousState == 0x00)
{
previousState = 0xFF;
key = 1; // here key determines which key will be trigger in TouchGFX
return true;
}
previousState = 0x00;
return false;
}
And this the header file:
#ifndef NEWBUTTONCONTROLLER_HPP_
#define NEWBUTTONCONTROLLER_HPP_
#include <platform/driver/button/ButtonController.hpp>
class newButtonController : public touchgfx::ButtonController
{
virtual void init();
virtual bool sample(uint8_t& key);
private:
uint8_t previousState;
};
#endif /* NEWBUTTONCONTROLLER_HPP_ */
Finally the modified TouchGFXHAL.cpp file:
#include <TouchGFXHAL.hpp>
/* USER CODE BEGIN TouchGFXHAL.cpp */
#include "main.h"
#include <newButtonController.hpp>
newButtonController bc;
using namespace touchgfx;
extern "C" uint8_t framebuffer[800 * 480];
void TouchGFXHAL::initialize()
{
// Calling parent implementation of initialize().
//
// To overwrite the generated implementation, omit the call to the parent function
// and implement the needed functionality here.
// Please note, HAL::initialize() must be called to initialize the framework.
/*
*/
TouchGFXGeneratedHAL::initialize();
// Set the framebuffer start address
HAL::getInstance()->setFrameBufferStartAddresses(
framebuffer, // Framebuffer for the first layer (internal memory)
nullptr, // Framebuffer for the second layer (if unused, set to nullptr)
nullptr // Framebuffer for the third layer (if unused, set to nullptr)
);
setButtonController(&bc);
}
And here is how the button is configured in the ioc file:
Thanks again,
Josh
2025-01-09 01:50 AM
Hi, thanks for the response.
I have checked my StartUpScreenViewBAse.cpp file and it appears to have generated correctly.
void StartUpScreenViewBase::handleKeyEvent(uint8_t key)
{
if(1 == key)
{
//Interaction1
//When hardware button 1 clicked change screen to FFTScreen
//Go to FFTScreen with no screen transition
application().gotoFFTScreenScreenNoTransition();
}
}
Is it that I need to call "application().gotoFFTScreenScreenNoTransition();" from another place in my code?
2025-01-09 04:11 AM
Hello @Josh_W020 ,
From what I understood, you are sure that the button itself works and you are sure that you are able to do a screen transition.
So the issue must be between connecting these 2 actions.
We provide examples of boards and UI using hardware buttons with the GFX01M2 display extension.
One of the GUI using hardware button is the "Aircon remote demo":
Instead of adding a hardware button to TouchGFX Designer (which is possible), we mapped it to a keyboard key.
This way, we can execute an interaction from pressing a key on the keyboard (when simulating for instance) and we are also able to map our physical button to execute the interaction.
Here you can see that the interaction is executed when pressing the key '8' :
And here you can see how we mapped the hardware button to a key in MB1642ButtonController.cpp :
I hope this example is helpful to you!
Regards,
2025-01-09 06:51 AM
I manage it in model tick, TGFX examples with key is long way ...
Try in model.cpp
void Model::tick() {
if (HAL_GPIO your button test == SET) {
//wait for release add here
static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(
'A'); // here use key from my window example
...
good is add inteligent key handler release this is only example. Positive is this send event A key to actual screen , and this can handle different reactions on different screens. All is setup in designer.
And your second Q transition with delay you can setup in designer. Not require any code in main or while.
Learn use Interactions, here for example exist action wait for ...