summaryrefslogtreecommitdiff
path: root/src/components/motor
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-08-01 13:05:48 +0300
committerRiku Isokoski <riksu9000@gmail.com>2021-08-01 13:05:48 +0300
commite6dcb3009fe6f847a7486dbb1b3143bbf49a15b9 (patch)
treea957ff31f9b3509b41b6bc465693e26d56f80d1f /src/components/motor
parent5bdef365f2b8f8e0ba06d04216749205a5bba50d (diff)
Improvements
Diffstat (limited to 'src/components/motor')
-rw-r--r--src/components/motor/MotorController.cpp40
-rw-r--r--src/components/motor/MotorController.h12
2 files changed, 24 insertions, 28 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index 80883025..b25e6bc8 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -16,41 +16,37 @@ void MotorController::Init() {
nrf_gpio_pin_set(pinMotor);
app_timer_init();
- app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
- app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, vibrate);
- isBusy = false;
+ app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
+ app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring);
}
-void MotorController::runForDuration(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 || isBusy)
+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(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL);
+ app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
}
-void MotorController::startRunning(uint8_t motorDuration) {
- if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy )
+void MotorController::StartRinging() {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
return;
- //prevent other vibrations while running
- isBusy = true;
- nrf_gpio_pin_clear(pinMotor);
- app_timer_start(longVibTimer, APP_TIMER_TICKS(motorDuration), NULL);
+ }
+ Ring(this);
+ app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
-void MotorController::stopRunning() {
-
+void MotorController::StopRinging() {
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);
- }
+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 5daeb8ce..d2c9fe5f 100644
--- a/src/components/motor/MotorController.h
+++ b/src/components/motor/MotorController.h
@@ -12,14 +12,14 @@ namespace Pinetime {
public:
MotorController(Controllers::Settings& settingsController);
void Init();
- void runForDuration(uint8_t motorDuration);
- void startRunning(uint8_t motorDuration);
- void stopRunning();
+ 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);
- bool isBusy;
- };
+ static void StopMotor(void* p_context);
+ };
}
}