2021-07-02 07:50 AM
TouchGFX 4.16.1, Win10 (I promise I will update to 4.17)
I'm working on a project where I create an array of custom elements purely with code, such as an array of scrollable containers filled with the array of boxes and textAreas with wildcards, custom buttons (these still in work). It took a while to figure it out, but I added my own callback function to my button (for now just one), etc. (mainly by creating element in TouchGFX designer, generating code and then copy-paste-understand-modifying).
The one thing I'm failing to implement on my own at this point is wait function. Like I want to click a button, wait and then do whatever (or any other use for wait).
I've created a button and a box in TouchGFX Designer, added interactions with Wait (box changes color after 1000ms), so that I have a working code of wait that I can break down. The code for wait turned out to be pretty simple: it calls ViewBase::handleTickEvent on every tick and simply does a countdown. You set the number of ms, it's converted into number of frames.
Auto-generated wait in ViewBase.cpp looks like this:
void ScreenMeasurementsViewBase::handleTickEvent()
{
if(interaction1Counter > 0)
{
interaction1Counter--;
if(interaction1Counter == 0)
{
//Interaction2
//When Interaction1 completed change color of box1
//Set RGB color R:255, G:72, B:72 on box1
box1.setColor(touchgfx::Color::getColorFrom24BitRGB(255,72,72));
box1.invalidate();
}
}
}
The problem is that the interaction counter is actually private, so I can't set it to anything on my own.
So, I figure, I'll have my own handleTickEvent function in View.cpp with blackjack my own interaction counter. Just as I created my own callback for my buttons. Piece of cake.
So, in View.cpp, I've created my own interaction counter variable and handleTickEvent function in View.cpp. So ViewBase and View cpp of the screen each have their own handleTickEvent.
Turned out, when they both exist at the same time, wait simply doesn't work. The interaction doesn't start and the chain of interactions is basically frozen. I'm actually not sure if my function gets called on every tick at all, but it seems to destroy the work of auto-generated Wait, so I guess something is happening, except that none of the waits works as intended then.
Here is my function in View.cpp, not very inventive:
void ScreenMeasurementsView::handleTickEvent() {
if (WAIT_TIMER_TICKS > 0) {
WAIT_TIMER_TICKS--;
if (WAIT_TIMER_TICKS == 0) {
}
}
}
Maybe I should find some global tick handler independent of the screen and be like "hey on every tick if you're also on screen ScreenWithCustomWait (how do I check it?) then do THIS (this = my own tick handler for the screen with my custom wait). Or maybe there is a simpler way, I actually don't know, which exactly why I'm asking.
2021-07-03 02:12 AM
Turned out, if I remove wait function from the TouchGFX Designer (and, as a consequence, from the ViewBase), there is no more conflict between handleTickEvent() from the View and View base.
Experimented a little
If there is Wait in TouchGFX Designer (handleTickEvent in ViewBase.cpp) and no wait manually in View, the one in TouchGFX (generated to ViewBase), obviously, works. This is basically when you create wait only in TouchGFX designer without custom code.
If there is TouchGFX Designer's Wait AND manually created handleTickEvent in View.cpp, ONLY manually created one works, such as:
void ScreenMeasurementsView::handleTickEvent() {
if (WAIT_TIMER_TICKS > 0) {
WAIT_TIMER_TICKS--;
if (WAIT_TIMER_TICKS == 0) {
scrollableContainerFromFile.setVisible(false);
fromFileCoverBox.setVisible(false);
scrollableContainerFromFile.invalidate();
fromFileCoverBox.invalidate();
}
}
}
Wait interaction created in TouchGFX Designer does not trigger, as if it gets overridden by the custom created handleTickEvent() in View.cpp
If I have TouchGFX Designer generated handleTickEvent() AND custom handleTickEvent in View.cpp, and I comment out the one in the View, then the Wait interaction from TouchGFX Designer starts to work again.
Unfortunately, merging the two is impossible (Having working WAIT function generated by TouchGFX Designer AND custom created wait functionat the same time), because the countdown variable of the TouchGFX Designer is protected, I can't access it.
On the other hand...maybe I could create a call to the custom virtual function instead of wait in TouchGFX Designer, and this virtual function would actually call my wait? Will try it now.
EDIT: attempts to call virtual function that would wait, have failed. Seems like I can have wait interaction EITHER generated by TouchGFX Designer ("interactions") OR as custom-created function(s) in View.cpp
EDIT2: since there is no way to reference the ViewBase (Designer-created) objects from custom code View.cpp due to them being private/protected, I decided to add flags to my counter.
void ScreenMeasurementsView::handleTickEvent() {
if (WAIT_TIMER_TICKS > 0) {
WAIT_TIMER_TICKS--;
if (WAIT_TIMER_TICKS == 0) {
if (tickHandlerFlag == 1) {
scrollableContainerFromFile.setVisible(false);
fromFileCoverBox.setVisible(false);
scrollableContainerFromFile.invalidate();
fromFileCoverBox.invalidate();
}
if (((tickHandlerFlag >> 1) & 1) == 1) {
touchgfx_printf("time has passed\n");
}
}
}
}
I call virtual function, which sets my countdown variable and my tickHandlerFlag to distinguish between different actions I have to do after the time expires (including simultaneously). Chose 32-bit variable where every bit is a flag for specific action. So I can have multiple functions execute after the time goes off, literally defined by binary combination of flags.