2019-07-02 06:56 AM
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.
Solved! Go to Solution.
2019-07-03 11:50 AM
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
2019-07-02 12:31 PM
I added my custom function to callback.hpp to get it work. But the touchgfx library file is changed in this way :(
2019-07-03 12:39 AM
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 ;)
2019-07-03 10:42 AM
Thanks for your help. I don't quiet understand your solution. Would you mind be more specific? Here is my confusion:
Thanks
2019-07-03 11:50 AM
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
2019-07-05 06:02 AM
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.
2019-07-05 10:02 AM
One is glad to be of service.
2024-04-15 12:59 AM
I'm just replying to say that this is a brilliant trick, thank you! You just saved me a LOT of time