# Timer Legato BTA

**URL:** <https://forum.legato.io/t/timer-legato-bta/3794>\
**Category:** Legato Application Framework\
**Created:** [October 19, 2018, 8:36am UTC](https://forum.legato.io/t/timer-legato-bta/3794 "2018-10-19T08:36:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hassan\_ATYQ](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@Hassan\_ATYQ](https://forum.legato.io/u/Hassan_ATYQ)\
**Post date:** [October 19, 2018, 8:36am UTC](https://forum.legato.io/t/timer-legato-bta/3794/1 "2018-10-19T08:36:22Z")

</div>

Hi Everyone,

I have a problem with a timer that does not wake up, could you help me if it pleases.

Best Regards

le\_result\_t Motion::StartTimer()  
{  
le\_result\_t ret = LE\_FAULT;  
static size\_t PeriodetosendP = 0;

```
puts(" ---[Motion] ***Start timer*** \n");

/*mutexPeriod.lock();
PeriodetosendP = Alert_Motion_Period;
mutexPeriod.unlock();*/

//std::cout<<"---[Motion] ***periode = "<<PeriodetosendP <<"***"<<std::endl;

if((ModeExecTimer = le_timer_Create("ModeExecTimer")) == NULL)
{
	std::cout<<"---[Motion] *** Could not create the ModeExecTimer"<<std::endl;

}
le_clk_Time_t clk = { .sec = 60, .usec = 1000000 };
std::cout<<"clk sec = "<<clk.sec<<"clk usec "<<clk.usec<<std::endl;
le_timer_SetInterval(ModeExecTimer, clk);

if(le_timer_SetInterval(ModeExecTimer, clk) == LE_OK)
{
	std::cout<<"---[Motion] ***success status to set interval ret == LE_OK*** \n"<<std::endl;
}
else
{
	std::cout<<"---[Motion] ***Erreur to set periode status to set interval ret == LE_OK*** \n"<<std::endl;
}

/*if(le_timer_SetMsInterval(ModeExecTimer, PeriodetosendP*1000) == LE_OK)
{
	std::cout<<"---[Motion] ***success status to set interval ret == LE_OK*** \n"<<std::endl;
}
else
{

}*/

if(le_timer_SetRepeat(ModeExecTimer, 0) == LE_OK)
{
	std::cout<<"---[Motion] success to repeat Timer"<<std::endl;
}
else
{
	std::cout<<"---[Motion] this timer is currently running echeck to repeat timer "<<std::endl;
}

if(le_timer_SetHandler(ModeExecTimer, SetHundler) != LE_OK)
{
	std::cout<<"---[Motion] ***Could not set the handler for ModeExecTimer***"<<std::endl;
}

if( le_timer_Start(ModeExecTimer) == LE_OK)
{
	printf("---[Motion] ***timer start*** \n");
}
else
{
	printf("---[Motion] ***timer start = LE_BUSY the timer is already running*** \n");

}

if(le_timer_IsRunning(ModeExecTimer))
{
	std::cout<<"---[Motion] *** is running status le_timer_IsRunning = LE_OK "<<std::endl;
}
else
{
	std::cout<<"---[Motion] ***this timer object currently running*** \n"<<std::endl;

	if(le_timer_SetMsInterval(ModeExecTimer, PeriodetosendP*1000) != LE_OK)
	{
		std::cout<<"---[Motion] ****Cannot set Interval timer!***"<<std::endl;
	}
	else
	{
		le_timer_Start(ModeExecTimer);

	}
}
le_timer_GetContextPtr(ModeExecTimer);
NumrExpTimer = le_timer_GetExpiryCount(ModeExecTimer);
std::cout<<"---[Motion] ****Expiry Count***" << NumrExpTimer <<std::endl;

return ret;

```

}

void SetHundler(le\_timer\_Ref\_t timerRef)  
{  
timerRef = NULL;  
Motion motion;

```
std::cout <<"---[Motion] ****hello*** \n"<< " ***"<< __func__ <<"***"<<std::endl;

if(ModeExecTimer != NULL)
{
	le_timer_Stop(ModeExecTimer);
	std::cout<<"---[Motion] ***Timer != NULL*** \n"<<std::endl;
}
else
{
	std::cout<<"---[Motion] ***Timer == NULL*** \n "<<std::endl;
}

//std::cout<<"---[Motion] ***Set Period*** \n"<<std::endl;
//motion.SetPeriod();

//std::cout<<"---[Motion] ***Start Timer*** \n"<<std::endl;
//motion.StartTimer();

```

}

---

<div class="post-metadata">

**Author:** ![shib](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@shib](https://forum.legato.io/u/shib)\
**Post date:** [October 23, 2018, 2:58am UTC](https://forum.legato.io/t/timer-legato-bta/3794/2 "2018-10-23T02:58:57Z")

</div>

What is the output when you run your program?  
I didn’t see anything wrong with how you set up your timer, other than it being quite verbose.

---

<div class="post-metadata">

**Author:** ![Hassan\_ATYQ](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@Hassan\_ATYQ](https://forum.legato.io/u/Hassan_ATYQ)\
**Post date:** [October 23, 2018, 3:24pm UTC](https://forum.legato.io/t/timer-legato-bta/3794/3 "2018-10-23T15:24:21Z")

</div>

Hi Shib,

Thank you for your answer.

the problem is that I have to call my function in a thread and that way it works well

---

<div class="post-metadata">

**Author:** ![Vasantha\_lax](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@Vasantha\_lax](https://forum.legato.io/u/Vasantha_lax)\
**Post date:** [October 31, 2018, 6:50am UTC](https://forum.legato.io/t/timer-legato-bta/3794/4 "2018-10-31T06:50:44Z")

</div>

Has this issue been resolved.

---

<div class="post-metadata">

**Author:** ![Hassan\_ATYQ](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@Hassan\_ATYQ](https://forum.legato.io/u/Hassan_ATYQ)\
**Post date:** [November 13, 2018, 12:07pm UTC](https://forum.legato.io/t/timer-legato-bta/3794/5 "2018-11-13T12:07:55Z")

</div>

yes Thank you Vasantha\_lax
