How can I handle a button in TouchGFX that allows me to switch on a LED when it is pressed, and switch off it when I release the button? The following code works but it switches the LED on/off every time you touch/untouch the screen...
void Screen1View::handleClickEvent(const ClickEvent& event)
{
if((event.getType() == ClickEvent::PRESSED))
{
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_SET);
HAL_Delay(50);
}
if((event.getType() == ClickEvent::RELEASED))
{
HAL_GPIO_WritePin(LD1_GPIO_Port, LD1_Pin, GPIO_PIN_RESET);
}
}
If I use "flexButtonCallbackHandler(const touchgfx::AbstractButtonContainer& event)" function I can detect if button1, button2, etc were pressed, but I cannot detect if a button was released ... Any suggest?
The standard
Button
class in TouchGFX only triggers onclicked
. You can check the source code forAbstractButton::handleClickEvent()
to see how the code works.Button
inherits from this class and adds functionality like clicked/released images.In order to do what you want, you have to create a new class that implements the behavior you want. Checking the source code for
AbstractButton
this should be straight forward to issue a callback for both clicked and released events.