diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-17 08:21:42 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-17 08:21:42 (GMT) |
| commit | d73be76905c131c9d459cbb4e44be4bfc87dfddb (patch) | |
| tree | d1a1b09c9757e8cbbe0d381dbc60baf9d8451192 | |
| parent | 3e5fddede322814c2fea7634c1bf0d5f93bae315 (diff) | |
Simplify MotorController timer code
| -rw-r--r-- | src/components/motor/MotorController.cpp | 8 | ||||
| -rw-r--r-- | src/components/motor/MotorController.h | 9 | ||||
| -rw-r--r-- | src/components/timer/TimerController.cpp | 2 | ||||
| -rw-r--r-- | src/systemtask/SystemTask.cpp | 2 |
4 files changed, 13 insertions, 8 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index b895c83..714bff6 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -9,7 +9,9 @@ APP_TIMER_DEF(longVibTimer); using namespace Pinetime::Controllers; -void MotorController::Init() { +void MotorController::Init(System::SystemTask* systemTask) { + this->systemTask = systemTask; + nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); @@ -29,10 +31,6 @@ void MotorController::RunForDuration(uint8_t motorDuration) { && xTimerStart(shortVibTimer, 0) == pdPASS) { return; } - if (xTimerChangePeriodFromISR(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL) == pdPASS - && xTimerStartFromISR(shortVibTimer, NULL) == pdPASS) { - return; - } nrf_gpio_pin_set(PinMap::Motor); } diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 3c6cbd2..99a4e64 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -5,18 +5,25 @@ #include <cstdint> namespace Pinetime { + namespace System { + class SystemTask; + } namespace Controllers { class MotorController { public: MotorController() = default; - void Init(); void RunForDuration(uint8_t motorDuration); void StartRinging(); void StopRinging(); + protected: + friend class Pinetime::System::SystemTask; + void Init(System::SystemTask* systemTask); + private: + System::SystemTask* systemTask = nullptr; static void Ring(TimerHandle_t xTimer); static void StopMotor(TimerHandle_t xTimer); TimerHandle_t shortVibTimer; diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index fa00d3c..9802ded 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -15,7 +15,7 @@ namespace { } } -void Init(System::SystemTask* systemTask) { +void TimerController::Init(System::SystemTask* systemTask) { this->systemTask = systemTask; timerAppTimer = xTimerCreate("timerAppTm", 1, pdFALSE, this, TimerEnd); } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5a0a99d..ad73063 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -155,7 +155,7 @@ void SystemTask::Work() { touchPanel.Init(); dateTimeController.Register(this); batteryController.Register(this); - motorController.Init(); + motorController.Init(this); motionSensor.SoftReset(); timerController.Init(this); alarmController.Init(this); |
