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