cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to set a "callback" for all touchable widgets in touchGFX?

zzzzz
Senior

I want to play a tap sound when user click button or elements on list. I have hundreds button in my project, so I don't want to add that sound play function to each single callback. Is there a way to create a callback for all touchable widgets or a mechanism to do so? Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Zui
Senior

1: no, the reason for last added button is that touchGFX designer creates screenviewbase file with the :

void ScreenViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)

{

if (&src == &BUTTON1)

  {

//button 1 code

}

else if (&src == &BUTTON2)

  {

//button2 code

}

//ecc

}

so if u add a dummy button 3 (hidden, not visible ecc) and add the code i wrote in previous code u will have:

void ScreenViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)

{

if (&src == &BUTTON1)

  {

//button 1 code

}

else if (&src == &BUTTON2)

  {

//button2 code

}

else if (&src == &BUTTON3)

{

}

#ifdef SIMULATOR

Beep(BUZZER_NOTE_MEDIUM, BUZZER_NOTE_DURATION);

#endif // SIMULATOR

presenter->touchFeedBack(); //function which make my buzzer beep

{

}

as u see the starting { close the button 3 condition, so the following code will be executed after any button is clicked

2: yes is invisible and i serve only the purpose to "inject that code, u can alsomuse the last button you create, but remember if later you add another button, you have to modify that interaction to always use the last button, ot the closing } trick won't work, try yourself and you will figure it out.

3 yes, i comunicate with my hardware through presenter, then model, so yes that trick must be used on every screen, but is better that do for every button

View solution in original post

7 REPLIES 7
zzzzz
Senior

I added my custom function to callback.hpp to get it work. But the touchgfx library file is changed in this way :(

Zui
Senior

i do a dirt trick to get that work, i added on the screen i needed (all in my case) an interection trigged by the last button added (you can use an hidden dummy button too), and the interaction execute c++ code:

}

#ifdef SIMULATOR

Beep(BUZZER_NOTE_MEDIUM, BUZZER_NOTE_DURATION);

#endif // SIMULATOR

presenter->touchFeedBack(); //function which make my buzzer beep

{

that code is executed after any button is pressed, not very elegant, but do it's job 😉

Thanks for your help. I don't quiet understand your solution. Would you mind be more specific? Here is my confusion:

  1. Is the execute c++ code only be executed when click last button? how to let the sound play if I click other buttons.
  2. Set the "dummy button" hidden means set it invisible? If so, how does it response the click?
  3. your code use a function in presenter, are you use MVP? is it like view -> presenter-> model-> backend? Is that means user need repeatedly add this code to all the views and presenters?

Thanks

Zui
Senior

1: no, the reason for last added button is that touchGFX designer creates screenviewbase file with the :

void ScreenViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)

{

if (&src == &BUTTON1)

  {

//button 1 code

}

else if (&src == &BUTTON2)

  {

//button2 code

}

//ecc

}

so if u add a dummy button 3 (hidden, not visible ecc) and add the code i wrote in previous code u will have:

void ScreenViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)

{

if (&src == &BUTTON1)

  {

//button 1 code

}

else if (&src == &BUTTON2)

  {

//button2 code

}

else if (&src == &BUTTON3)

{

}

#ifdef SIMULATOR

Beep(BUZZER_NOTE_MEDIUM, BUZZER_NOTE_DURATION);

#endif // SIMULATOR

presenter->touchFeedBack(); //function which make my buzzer beep

{

}

as u see the starting { close the button 3 condition, so the following code will be executed after any button is clicked

2: yes is invisible and i serve only the purpose to "inject that code, u can alsomuse the last button you create, but remember if later you add another button, you have to modify that interaction to always use the last button, ot the closing } trick won't work, try yourself and you will figure it out.

3 yes, i comunicate with my hardware through presenter, then model, so yes that trick must be used on every screen, but is better that do for every button

Thanks, now I understand. Your way does work without changing any library files. We finally overwrite click handle event on AbstractButton.hpp and it works. Although it changed one file in touchgfx, we don't have to do extra work on each screen.

One is glad to be of service.

I'm just replying to say that this is a brilliant trick, thank you! You just saved me a LOT of time