Skip to content
Snippets Groups Projects
Commit 1b0df22d authored by schneider's avatar schneider
Browse files

fix(vibra): Don't crash when called while running

Closes #109
parent 15c8971b
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ static const gpio_cfg_t motor_pin = { ...@@ -6,7 +6,7 @@ static const gpio_cfg_t motor_pin = {
PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE 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) void epic_vibra_set(int status)
{ {
...@@ -25,8 +25,14 @@ void vTimerCallback() ...@@ -25,8 +25,14 @@ void vTimerCallback()
void epic_vibra_vibrate(int millis) void epic_vibra_vibrate(int millis)
{ {
int ticks = millis * (configTICK_RATE_HZ / 1000); int ticks = millis * (configTICK_RATE_HZ / 1000);
if (vibra_timer == NULL) {
vibra_timer = xTimerCreate(
"vibratimer", ticks, pdFALSE, 0, vTimerCallback
);
}
if (vibra_timer != NULL) {
epic_vibra_set(1); epic_vibra_set(1);
vibra_timer = xTimerChangePeriod(vibra_timer, ticks, 0);
xTimerCreate("vibratimer", ticks, pdFALSE, 0, vTimerCallback); }
xTimerStart(vibra_timer, 0);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment