Skip to main content
Associate
March 19, 2024
Solved

Repeat Button triggers immediately, bug or feature?

  • March 19, 2024
  • 3 replies
  • 2515 views

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?

This topic has been closed for replies.
Best answer by LouisB

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,

3 replies

LouisBBest answer
ST Employee
March 20, 2024

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,

Graduate II
March 21, 2024

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

Andrew Neil
Super User
March 21, 2024

@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 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
ST Employee
March 22, 2024

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, 

Andrew Neil
Super User
March 22, 2024

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.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.