Skip to main content
KNara.2
Associate III
December 19, 2023
Solved

Disable ticks in handleTickEvent() / Exit from handleTickEvent()

  • December 19, 2023
  • 2 replies
  • 2042 views

Hi @Romain DIELEMAN  @Yoann KLEIN  @JTP1 @Mohammad MORADI ESFAHANIASL ...Please guide.....

 

 

 

I'm in the process of developing a screen which takes input from main board and the down timer keeps ticking. 

LED blinks until the progress bar fills.

The requirement for the LED is to blink when the progress bar is filling and become stable green once the down timer displays 0:00.

The calculation for the down timer is done inside handleTickEvent() and I get to know that the timer has reached 0:00 inside handleTickEvent() and this is how my code looks.

if (testDuration == 0) //To set LED intensity to stable green
{
      StableRGB(GREEN);
}
else if ((tickCounter % 30) == 0) //To set LED intensity to blinking green
 {

          if ((BlinkingGREEN() != HAL_OK))
         {
           //Report error
         }
}
Since the check, whether timer has reached 0:00 is done inside handleTickEvent(), stable LED looks a bit flickering.
I would like to exit from handleTickEvent() once the timer reaches 0:00...How can that be achieved?
Please suggest a solution for this.
This topic has been closed for replies.
Best answer by Mohammad MORADI ESFAHANIASL

Hello @KNara.2 ,

You cannot use "Application::getInstance()->unregisterTimerWidget(this);" because it is used for registering and unregistering widgets not a View (or screen). So, you cannot stop receiving the tick and you have to change the logic of your code. 
A simple solution would be to have a flag next to to your testDuration so, when it is called once you won't pass the condition again. Like this:

if (testDuration == 0 && !greenLEDIsOn) //To set LED intensity to stable green
{
 StableRGB(GREEN);
 greenLEDIsON = true;
}
else if ((tickCounter % 30) == 0) //To set LED intensity to blinking green
 {

 if ((BlinkingGREEN() != HAL_OK))
 {
 //Report error
 }
}

I hope this helps, good luck

 

2 replies

KNara.2
KNara.2Author
Associate III
December 19, 2023

In other words can somebody guide me how to stop the tick counter when the timer reaches 0:00.

I saw this post and tried adding this code in handleTickEvent()

https://community.st.com/t5/stm32-mcus-touch-gfx-and-gui/handletickevent-not-working-with-container/td-p/263835

  if (testDuration == 0) //To set LED intensity to stable green
  {
  StableRGB(GREEN);
 
  Application::getInstance()->unregisterTimerWidget(this);
  }

This is giving me compilation errors.

Can we stop the  receiving ticks every frame from handleTickEvent()?

ST Employee
December 20, 2023

Hello @KNara.2 ,

You cannot use "Application::getInstance()->unregisterTimerWidget(this);" because it is used for registering and unregistering widgets not a View (or screen). So, you cannot stop receiving the tick and you have to change the logic of your code. 
A simple solution would be to have a flag next to to your testDuration so, when it is called once you won't pass the condition again. Like this:

if (testDuration == 0 && !greenLEDIsOn) //To set LED intensity to stable green
{
 StableRGB(GREEN);
 greenLEDIsON = true;
}
else if ((tickCounter % 30) == 0) //To set LED intensity to blinking green
 {

 if ((BlinkingGREEN() != HAL_OK))
 {
 //Report error
 }
}

I hope this helps, good luck

 

KNara.2
KNara.2Author
Associate III
December 20, 2023

Thank you so much @Mohammad MORADI ESFAHANIASL that worked.

ST Employee
December 20, 2023

Glad to hear, you're very welcome