2019-06-03 11:56 PM
In my current project i need a buzzer buzz every time any button is pressed, in simulator i'm just using Beep(F,D); but i was looking for a better approach than paste the beep function inside every single function called by any button, besides that won't work in buttons that just change screen, due that the code is in ViewBase File and so can't be modified.
Thanks
Stefano
2019-06-04 04:00 AM
Hi @Zui,
You could create a custom Button, BeepButton, If you don't want to manually insert a call to Beep() - Which is what i think you're saying. You won't be able to use this button from the designer as a trigger, however.
Let me know.
/Martin
2019-06-04 04:56 AM
i was wondering of a sort of override whatever any "clickable" is calling, but no idea if that was possible
2019-06-04 04:59 AM
The Button, specifically, has an internal handler that executes a callback which is typically tied to a handler, as you know. That's all you can do to "override" a standard button.
/Martin
2019-06-04 05:00 AM
Here's the handleClickEvent() method for AbstractButton (from which Button inherits).
#include <touchgfx/widgets/AbstractButton.hpp>
namespace touchgfx
{
void AbstractButton::handleClickEvent(const ClickEvent& event)
{
bool wasPressed = pressed;
pressed = (event.getType() == ClickEvent::PRESSED);
if ((pressed && !wasPressed) || (!pressed && wasPressed))
{
// Pressed state changed, so invalidate
invalidate();
}
if (wasPressed && (event.getType() == ClickEvent::RELEASED) && action)
{
// This is a click. Fire callback.
if (action->isValid())
{
action->execute(*this);
}
}
}
} // namespace touchgfx
2019-06-04 08:08 AM
works like a charm, Thanks ^^
2019-06-04 08:09 AM
works like a charm, Thanks ^^
2019-06-05 02:31 AM
I just realize that my Beep function is called on every screen click, not onl on buttons, but since the handleClickEvent takes only the vent type, and not the event source, i can't figure out how to make the function to be called only when a button is pressed.
Any suggestion?
Thanks
Stefano
EDIT:
i manage to do what i want in a "code injection" way, by adding throu the designer an interaction when the last added button is pressed i execute this piece of code:
}
#ifdef SIMULATOR
Beep(BUZZER_NOTE_MEDIUM, BUZZER_NOTE_DURATION);
#endif // SIMULATOR
presenter->touchFeedBack();
{
so in the viewbase.cpp the buttonCallbackHandler function exits from it's if-else if structure, and execute my code on Every button pression.
I know it's a BAD way of doing this, so any suggestions are welcome