refactor MotorController
This commit is contained in:
parent
1bd5457848
commit
7ab153cd76
|
@ -2,39 +2,24 @@
|
||||||
#include <hal/nrf_gpio.h>
|
#include <hal/nrf_gpio.h>
|
||||||
#include "systemtask/SystemTask.h"
|
#include "systemtask/SystemTask.h"
|
||||||
#include "app_timer.h"
|
#include "app_timer.h"
|
||||||
#include "nrf_drv_clock.h"
|
|
||||||
|
|
||||||
APP_TIMER_DEF(vibTimer);
|
APP_TIMER_DEF(vibTimer);
|
||||||
|
|
||||||
using namespace Pinetime::Controllers;
|
using namespace Pinetime::Controllers;
|
||||||
|
|
||||||
static void lfclk_request(void) //get the low freq. clock
|
|
||||||
{
|
|
||||||
nrf_drv_clock_init();
|
|
||||||
nrf_drv_clock_lfclk_request(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void vibrateTimer(void * p_context)
|
|
||||||
{
|
|
||||||
nrf_gpio_pin_set(pinMotor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void create_timers()
|
|
||||||
{
|
|
||||||
//create timer, single shot, re-armable
|
|
||||||
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrateTimer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MotorController::Init() {
|
void MotorController::Init() {
|
||||||
nrf_gpio_cfg_output(pinMotor); // set the motor pin as an output
|
nrf_gpio_cfg_output(pinMotor);
|
||||||
nrf_gpio_pin_set(pinMotor);
|
nrf_gpio_pin_set(pinMotor);
|
||||||
lfclk_request(); //get lfclock ready
|
app_timer_init();
|
||||||
app_timer_init(); //start app timers to make calls
|
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
|
||||||
create_timers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorController::SetDuration(uint8_t motorDuration) {
|
void MotorController::SetDuration(uint8_t motorDuration) {
|
||||||
nrf_gpio_pin_clear(pinMotor);
|
nrf_gpio_pin_clear(pinMotor);
|
||||||
//start timer for motorDuration miliseconds
|
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
|
||||||
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration?
|
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MotorController::vibrate(void * p_context) {
|
||||||
|
nrf_gpio_pin_set(pinMotor);
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ namespace Pinetime {
|
||||||
void SetDuration(uint8_t motorDuration);
|
void SetDuration(uint8_t motorDuration);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void vibrate(void * p_context);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue