2 posts / 0 new
Last post
liuluan002
Offline
Last seen:3 months 4 days ago
加入:2015-11-27 14:24
关于cancel a timer before it starts

Hi Dialog,

I am using a timer "ke_timer_set(APP_CHECK_TIMER, TASK_APP, 1000);" to check the function "acc_sampling()" is running or not for each 10 seconds. Once the "acc_sampling()" is running, we want to cancel the old "APP_CHECK_TIMER" by using the " ke_timer_clear(APP_CHECK_SYSTEM_TIMER, TASK_APP);", then restart a new timer. Once the "acc_sampling()" is not running, the system will reset the sensor.

However we have find even we use the "ke_timer_clear" to cancel the old timer we called, the "APP_CHECK_TIMER" function will still be still calling. Is there any solution for this issue to kill the old timer been called also prevent running the "APP_CHECK_TIMER" function?

Device:
MT_dialog
Offline
Last seen:2 weeks 4 days ago
工作人员
加入:2015-06-08 11:34
Hi liuluan002,

Hi liuluan002,

I would suggest instead of using the ke_timer_set() and ke_timer_clear() to use the api functions for the ke_timers app_easy_timer_set() and app_easy_timer_cancel(), what you might experience is the fact that even if you ke_timer_clear() a timer if that timer has elapsed and entered the message queue it will be executed. The api ensures that even if the timer has entered the queue, the timer will hit, but the callback wont get executed the original callback gets replaced by a dummy one.

Thanks MT_dialog