2021-06-08 04:23 AM
I am using TouchGFX for a project with hardware buttons, but no touch screen.
Im trying to interface with the UI elements using the hardware buttons. For example I have a ScrollList full of toggle buttons, and I wish to toggle these buttons using the hardware buttons.
Screen1ViewBase.cpp
ClickEvent ce(ClickEvent::PRESSED, 14, 12);
scrollList1.handleClickEvent(ce);
ClickEvent ce1(ClickEvent::RELEASED, 14, 12);
scrollList1.handleClickEvent(ce1);
scrollList1.invalidate();
However this does not trigger the toggle button at 14,12 on the screen (origin top left).
As well as this, is there generally a better way to interact with the UI using hardware buttons, or is the emulation of ClickEvents and DragEvents the best solution?
Thanks,
2021-06-08 06:28 AM
2021-06-08 11:29 PM
Hello EHolm.2,
First of all you should never modify Screen1ViewBase.cpp. The user file is Screem1View.cpp.
Interacting with a ScrollList via hardware buttons should be possible. I don't know what you are trying to do with code above but interfacing hardware button is very simple. Simply create a CustomButtonController class which inherits touchgfx::ButtonController (see documentation here).
Have a look also at the G0 Application Template available in TouchGFX Designer.
#include <MB1642BButtonController.hpp>
#include <main.h>
#include <touchgfx/hal/HAL.hpp>
void MB1642AButtonController::init()
{
previousState = 0;
}
bool MB1642AButtonController::sample(uint8_t& key)
{
uint8_t state = MB1642KeyState();
if (state == previousState)
{
return false;
}
previousState = state;
if (state != 0)
{
key = state;
return true;
}
return false;
}
And in TouchGFXHAL.cpp
#include <MB1642BButtonController.hpp>
MB1642AButtonController bc;
...
void TouchGFXHAL::initialize()
{
....
/* Initialize TouchGFX Engine */
TouchGFXGeneratedHAL::initialize();
setButtonController(&bc);
}
When your hardware buttons are set up correctly you can use the function virtual void handleKeyEvent(uint8_t c) to retrieve the hardware buttons event. (See the Online Application : STM32G071 AIRCON REMOTE DEMO available in TouchGFX Designer).
At this point you can start trying to manipulate the ScrollList with hardware buttons using AnimateToItem(). If you want to use AnimateToPosition() you will need to modify the ScrollList which will lead to the incapability of using the Designer for your modified widget.
/Alexandre