Skip to main content
ZExpo.1
Associate III
November 13, 2023
Question

Adding Buzzer sound in Button (TouchGfx)

  • November 13, 2023
  • 2 replies
  • 1614 views

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?

This topic has been closed for replies.

2 replies

MM..1
Chief III
November 13, 2023

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...

Visitor II
November 13, 2023

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

ZExpo.1
ZExpo.1Author
Associate III
November 13, 2023

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