1
0
Fork 0
InfiniTime/src/components/motor/MotorController.cpp

32 lines
954 B
C++
Raw Normal View History

2021-01-16 04:11:53 +01:00
#include "MotorController.h"
#include <hal/nrf_gpio.h>
#include "systemtask/SystemTask.h"
#include "app_timer.h"
2021-08-03 20:32:23 +02:00
#include "drivers/PinMap.h"
2021-01-16 04:11:53 +01:00
2021-01-25 18:44:58 +01:00
APP_TIMER_DEF(vibTimer);
2021-01-16 04:11:53 +01:00
using namespace Pinetime::Controllers;
MotorController::MotorController(Controllers::Settings& settingsController) : settingsController {settingsController} {
}
2021-01-16 04:11:53 +01:00
void MotorController::Init() {
2021-08-03 20:32:23 +02:00
nrf_gpio_cfg_output(PinMap::Motor);
nrf_gpio_pin_set(PinMap::Motor);
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
2021-01-16 04:11:53 +01:00
}
void MotorController::SetDuration(uint8_t motorDuration) {
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
return;
2021-08-03 20:32:23 +02:00
nrf_gpio_pin_clear(PinMap::Motor);
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
2021-01-25 18:44:58 +01:00
}
2021-02-05 17:06:56 +01:00
void MotorController::vibrate(void* p_context) {
2021-08-03 20:32:23 +02:00
nrf_gpio_pin_set(PinMap::Motor);
2021-02-05 17:06:56 +01:00
}