From 1b0df22dec18f8ee82a318f79b61d0ce7f62a303 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 15 Sep 2019 01:30:20 +0200 Subject: [PATCH] fix(vibra): Don't crash when called while running Closes #109 --- epicardium/modules/vibra.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/epicardium/modules/vibra.c b/epicardium/modules/vibra.c index dd7c3131..882b0bef 100644 --- a/epicardium/modules/vibra.c +++ b/epicardium/modules/vibra.c @@ -6,7 +6,7 @@ static const gpio_cfg_t motor_pin = { PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE }; -static TimerHandle_t vibra_timer; +static TimerHandle_t vibra_timer = NULL; void epic_vibra_set(int status) { @@ -25,8 +25,14 @@ void vTimerCallback() void epic_vibra_vibrate(int millis) { int ticks = millis * (configTICK_RATE_HZ / 1000); - epic_vibra_set(1); - vibra_timer = - xTimerCreate("vibratimer", ticks, pdFALSE, 0, vTimerCallback); - xTimerStart(vibra_timer, 0); + + if (vibra_timer == NULL) { + vibra_timer = xTimerCreate( + "vibratimer", ticks, pdFALSE, 0, vTimerCallback + ); + } + if (vibra_timer != NULL) { + epic_vibra_set(1); + xTimerChangePeriod(vibra_timer, ticks, 0); + } } -- GitLab