summaryrefslogtreecommitdiff
path: root/src/components/motor
diff options
context:
space:
mode:
authorFlorian Kraupa <fgrauper@gmail.com>2021-05-12 18:23:04 (GMT)
committerFlorian Kraupa <fgrauper@gmail.com>2021-05-15 22:42:31 (GMT)
commitd13dd6dee3e6194a2f3ed2a1adfbbd32ced525a3 (patch)
tree6c07d26460c04366f8f0affbee3de38d6dc56b2b /src/components/motor
parentd7fa000b851024f45e85e0cd0aa688ff088cf957 (diff)
implemented continuous vibration pattern for incoming calls
Diffstat (limited to 'src/components/motor')
-rw-r--r--src/components/motor/MotorController.cpp36
-rw-r--r--src/components/motor/MotorController.h7
2 files changed, 35 insertions, 8 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index a834ab6..2a14f4b 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;
@@ -14,19 +15,42 @@ void MotorController::Init() {
nrf_gpio_cfg_output(pinMotor);
nrf_gpio_pin_set(pinMotor);
app_timer_init();
- app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
+
+ app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
+ app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, vibrate);
+ isBusy = false;
}
-void MotorController::SetDuration(uint8_t motorDuration) {
+void MotorController::RunForDuration(uint8_t motorDuration) {
- if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy)
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), NULL);
}
-void MotorController::vibrate(void* p_context) {
+void MotorController::startRunning(uint8_t motorDuration) {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy )
+ return;
+ //prevent other vibrations while running
+ isBusy = true;
+ nrf_gpio_pin_clear(pinMotor);
+ app_timer_start(longVibTimer, APP_TIMER_TICKS(motorDuration), NULL);
+}
+
+void MotorController::stopRunning() {
+
+ app_timer_stop(longVibTimer);
nrf_gpio_pin_set(pinMotor);
+ isBusy = false;
+}
+
+void MotorController::vibrate(void* p_context) {
+ if (nrf_gpio_pin_out_read(pinMotor) == 0) {
+ nrf_gpio_pin_set(pinMotor);
+ } else {
+ nrf_gpio_pin_clear(pinMotor);
+ }
} \ No newline at end of file
diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h
index df61af7..be076ad 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 startRunning(uint8_t motorDuration);
+ void stopRunning();
private:
Controllers::Settings& settingsController;
static void vibrate(void* p_context);
- };
+ bool isBusy;
+ };
}
}