cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Buzzer sound in Button (TouchGfx)

ZExpo.1
Senior

I am currently using the touch gfx button with its callback function to call PWM code to execute when I press the button on the GUI as shown below.

#include <main.h>
#include "cmsis_os.h"
extern TIM_HandleTypeDef htim4;

void MAINViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)
{
    if (&src== &button1)
    {
      	 TIM4->CCR2 = 50;
      	 HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2);
      	 osDelay(50);
      	 HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_2);
        //Interaction1
        //When button1 clicked change screen to SETTINGS
        //Go to SETTINGS with screen transition towards East
        application().gotoSETTINGSScreenSlideTransitionEast();
    }
}

But I have to add this function manually every time I make any change in the GUI which is kind of repetitive to do, Is there any method of adding a custom Button function where I can write this code as default with the button?

3 REPLIES 3
MM..1
Chief II

Change your handler to 

MM1_0-1699899365596.png

to virtual function call and in func buzz start no delay... stop place on timed handler or next screen onload part.

Delays in code result to block gui ...
Too you can use next interaction to start screen change when this ends...

liaifat85
Senior II

You can create a custom button class that inherits from the Button class in TouchGFX.

If it's possible ,could you please write that here?