cancel
Showing results for 
Search instead for 
Did you mean: 

Repeat Button triggers immediately, bug or feature?

ulix
Associate

I want the user to hold a button for at least 3 seconds before it triggers its interaction. So I created a Repeat Button, because the documentation says on delay: "Delay specifies the time (ms) to wait when the button is pressed before starting the loop of triggers."

But when I configure a delay of e.g. 2000 ms and an interval time of 8000 ms, it triggers immediately and then after 2 seconds (and then every 8 seconds). Is this misleading in the documentation or a wrong behavior of the button?

1 ACCEPTED SOLUTION

Accepted Solutions
LouisB
ST Employee

Hello @ulix ,

First, welcome to the TouchGFX community :)

The repeat button is working as it's supposed to be, it repeats the trigger every X ms. The delay is the delay between each triggers, e.g with a 2000ms the button will be triggered every 2000ms.

The behaviour you want can be done by using HandleClick on your button with HandleTick. by setting up a timer, that increments with HandleTick and allows you to click.

I hope it answers your question,

Regards,

Louis BOUDO
ST Software Developer | TouchGFX

View solution in original post

5 REPLIES 5
LouisB
ST Employee

Hello @ulix ,

First, welcome to the TouchGFX community :)

The repeat button is working as it's supposed to be, it repeats the trigger every X ms. The delay is the delay between each triggers, e.g with a 2000ms the button will be triggered every 2000ms.

The behaviour you want can be done by using HandleClick on your button with HandleTick. by setting up a timer, that increments with HandleTick and allows you to click.

I hope it answers your question,

Regards,

Louis BOUDO
ST Software Developer | TouchGFX
JTP1
Lead

Hello

You can also achieve your goal by modifing repeatButton.cpp

Browse to \Middlewares\ST\touchgfx\framework\source\touchgfx\widgets\- folder of your project and copy RepeatButton.cpp- file to  \TouchGFX\gui\src\common\ folder. Edit that copy in \common\ folder.

Locate handleClickEvent and comment out executeAction- function call.

void RepeatButton::handleClickEvent(const ClickEvent& event) { pressed = false; // To prevent AbstractButton from calling action->execute(). invalidate(); // Force redraw after forced state change Button::handleClickEvent(event); if (event.getType() == ClickEvent::PRESSED) { //Comment out call to 'executeAction' to get initial delay before first click //executeAction(); ticks = 0; ticksBeforeContinuous = ticksDelay; Application::getInstance()->registerTimerWidget(this); } else { Application::getInstance()->unregisterTimerWidget(this); } }

 

Then if needed to get only one delayed click, just add 'unregisterTimerWidget' after first click is generated after initial delay.

void RepeatButton::handleTickEvent() { Button::handleTickEvent(); if (!pressed) { return; } if (ticks == ticksBeforeContinuous) { executeAction(); ticks = 0; ticksBeforeContinuous = ticksInterval; // Add unregisterTimerWidget after first generated click Application::getInstance()->unregisterTimerWidget(this); } else { ticks++; } }

 Perhaps this kind of features would be nice to have directly from the Tgfx Designer in the future releases.

Br JTP


@JTP1 wrote:

Perhaps this kind of features would be nice to have directly from the Tgfx Designer in the future releases.


+1

Indeed - this would seem like a pretty common requirement.

@LouisB 

LouisB
ST Employee

Hello all,

Thanks for your feedbacks, I will talk about this feature to the Team and see if there's an interest for it in a next release.

Regards, 

Louis BOUDO
ST Software Developer | TouchGFX

thanks.

I see very common applications for both; eg,

  • The auto-repeat on a keyboard typically give you one character immediately you press the key, and then the auto-repeat starts if you keep it held down;
     
  • Typically a power-off button will not actually start the power-down sequence until it has been held for the required time - to ensure that an accidental "brush" doesn't shut the system down!

That's just 2 straight off the top of my head.