From a3dc13e3fb19c79282a1030bb3997aaafaeaf7a4 Mon Sep 17 00:00:00 2001 From: devsaurus Date: Thu, 9 Mar 2017 23:31:02 +0100 Subject: [PATCH] fix tmr.interval() --- components/modules/tmr.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/components/modules/tmr.c b/components/modules/tmr.c index d611ccb5..041ea4de 100755 --- a/components/modules/tmr.c +++ b/components/modules/tmr.c @@ -192,12 +192,13 @@ static int tmr_interval(lua_State* L) luaL_argcheck(L, interval > 0 && interval <= MAX_TIMEOUT, 2, MAX_TIMEOUT_ERR_STR); if (tmr->mode != TIMER_MODE_OFF) { tmr->interval = interval; - if (!(tmr->mode & TIMER_IDLE_FLAG)) { - xTimerStop(tmr->timer, portMAX_DELAY); - if (xTimerChangePeriod(tmr->timer, tmr->interval, portMAX_DELAY) != pdPASS) { - luaL_error(L, "cannot change period"); - } - // stop again since xTimerChangePeriod will re-start the timer + if (xTimerChangePeriod(tmr->timer, + pdMS_TO_TICKS(tmr->interval), + portMAX_DELAY) != pdPASS) { + luaL_error(L, "cannot change period"); + } + if (tmr->mode & TIMER_IDLE_FLAG) { + // xTimerChangePeriod will start a dormant timer, thus force stop if it was dormant xTimerStop(tmr->timer, portMAX_DELAY); } }