From 4de2d2412a557489ef699f2abf8d3ff2abc21afc Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Mon, 20 Jul 2020 01:26:53 +0200 Subject: [PATCH] fix(vibra): Stop timer if duration <= 0 --- epicardium/modules/vibra.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/epicardium/modules/vibra.c b/epicardium/modules/vibra.c index da1325093..aacbdf4e8 100644 --- a/epicardium/modules/vibra.c +++ b/epicardium/modules/vibra.c @@ -27,22 +27,24 @@ void epic_vibra_vibrate(int millis) { int ticks = millis * (configTICK_RATE_HZ / 1000); - /* Make sure the duration is valid */ - if (ticks < 1) { - /* Disable a potentially running motor */ - epic_vibra_set(0); - return; - } - if (vibra_timer == NULL) { vibra_timer = xTimerCreateStatic( "vibratimer", - ticks, + 1, pdFALSE, /* one-shot */ 0, vTimerCallback, &vibra_timer_data); } + + /* Make sure the duration is valid */ + if (ticks < 1) { + /* Disable a potentially running motor / timer */ + epic_vibra_set(0); + xTimerStop(vibra_timer, 0); + return; + } + if (vibra_timer != NULL) { epic_vibra_set(1); xTimerChangePeriod(vibra_timer, ticks, 0); -- GitLab