summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/motor/MotorController.cpp37
-rw-r--r--src/components/motor/MotorController.h7
2 files changed, 34 insertions, 10 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index 3afa0ced..b25e6bc8 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -3,7 +3,8 @@
#include "systemtask/SystemTask.h"
#include "app_timer.h"
-APP_TIMER_DEF(vibTimer);
+APP_TIMER_DEF(shortVibTimer);
+APP_TIMER_DEF(longVibTimer);
using namespace Pinetime::Controllers;
@@ -13,19 +14,39 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
void MotorController::Init() {
nrf_gpio_cfg_output(pinMotor);
nrf_gpio_pin_set(pinMotor);
- app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
+ app_timer_init();
+
+ app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
+ app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring);
}
-void MotorController::SetDuration(uint8_t motorDuration) {
+void MotorController::Ring(void* p_context) {
+ auto* motorController = static_cast<MotorController*>(p_context);
+ motorController->RunForDuration(50);
+}
- if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
+void MotorController::RunForDuration(uint8_t motorDuration) {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
return;
+ }
nrf_gpio_pin_clear(pinMotor);
- /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
- app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
+ app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
+}
+
+void MotorController::StartRinging() {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
+ return;
+ }
+ Ring(this);
+ app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
-void MotorController::vibrate(void* p_context) {
+void MotorController::StopRinging() {
+ app_timer_stop(longVibTimer);
nrf_gpio_pin_set(pinMotor);
-} \ No newline at end of file
+}
+
+void MotorController::StopMotor(void* p_context) {
+ nrf_gpio_pin_set(pinMotor);
+}
diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h
index df61af78..d2c9fe5f 100644
--- a/src/components/motor/MotorController.h
+++ b/src/components/motor/MotorController.h
@@ -12,11 +12,14 @@ namespace Pinetime {
public:
MotorController(Controllers::Settings& settingsController);
void Init();
- void SetDuration(uint8_t motorDuration);
+ void RunForDuration(uint8_t motorDuration);
+ void StartRinging();
+ static void StopRinging();
private:
+ static void Ring(void* p_context);
Controllers::Settings& settingsController;
- static void vibrate(void* p_context);
+ static void StopMotor(void* p_context);
};
}
}