Skip to content
Permalink
Browse files

stop metro from triggering instantly after start() or changing .time (#…

  • Loading branch information
trentgill committed May 14, 2020
1 parent 83931ee commit f4917815139e566f8b794bdad90574c8162de5c0
Showing with 6 additions and 7 deletions.
  1. +2 −1 ll/timers.c
  2. +4 −6 lua/crowlib.lua
@@ -77,7 +77,6 @@ int Timer_Init(void)
// static setup
TimHandle[i].Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;
TimHandle[i].Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle[i].Init.RepetitionCounter = 0;
TimHandle[i].Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

Timer_Set_Params( i, 1.0 );
@@ -133,6 +132,8 @@ void Timer_Set_Params( int ix, float seconds )
uint8_t err;
BLOCK_IRQS(
err = HAL_TIM_Base_Init( &(TimHandle[ix]) );
// Clear the update flag to avoid an instant callback
__HAL_TIM_CLEAR_FLAG( &(TimHandle[ix]), TIM_FLAG_UPDATE );
);
if( err != HAL_OK ){
printf("Timer_Set_Params(%i) failed\n", ix);
@@ -158,12 +158,10 @@ function delay(action, time, repeats)
local r = repeats or 1
local d = {}
function devent(c)
if c > 1 then
action(c-1) -- make the action aware of current iteration
if c > r then
metro.free(d.id)
d = nil
end
action(c) -- make the action aware of current iteration
if c > r then
metro.free(d.id)
d = nil
end
end
d = metro.init(devent, time)

0 comments on commit f491781

Please sign in to comment.