Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
stop metro from triggering instantly after start() or changing .time (#…
- Loading branch information
Showing
with
6 additions
and
7 deletions.
-
+2
−1
ll/timers.c
-
+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) |
|
|
|