diff options
author | Kieran Cawthray <kieranc@gmail.com> | 2021-06-16 16:33:34 +0200 |
---|---|---|
committer | Kieran Cawthray <kieranc@gmail.com> | 2021-06-16 16:33:34 +0200 |
commit | f5d756928ffef032fb5ac85e73f9a68b7b8f64dc (patch) | |
tree | 907608958d0be8a97a3d646c842fde3095cef939 /src/components/timer/TimerController.cpp | |
parent | f2d01166c380b72ebcb13ef649def88ff4cf2d21 (diff) | |
parent | e90e8c7426f9a44e696b208a5b393a60476a3d43 (diff) |
Merge remote-tracking branch 'upstream/develop' into pinetimestyle
Diffstat (limited to 'src/components/timer/TimerController.cpp')
-rw-r--r-- | src/components/timer/TimerController.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index 3b25901c..8d5f5c33 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -12,14 +12,17 @@ using namespace Pinetime::Controllers; APP_TIMER_DEF(timerAppTimer); - -TimerController::TimerController(System::SystemTask& systemTask) : systemTask{systemTask} { +namespace { + void TimerEnd(void* p_context) { + auto* controller = static_cast<Pinetime::Controllers::TimerController*> (p_context); + if(controller != nullptr) + controller->OnTimerEnd(); + } } void TimerController::Init() { - app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, timerEnd); - + app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, TimerEnd); } void TimerController::StartTimer(uint32_t duration) { @@ -47,13 +50,6 @@ uint32_t TimerController::GetTimeRemaining() { return (static_cast<TickType_t>(deltaTicks) / static_cast<TickType_t>(configTICK_RATE_HZ)) * 1000; } -void TimerController::timerEnd(void* p_context) { - - auto* controller = static_cast<Controllers::TimerController*> (p_context); - controller->timerRunning = false; - controller->systemTask.PushMessage(System::SystemTask::Messages::OnTimerDone); -} - void TimerController::StopTimer() { app_timer_stop(timerAppTimer); timerRunning = false; @@ -61,4 +57,13 @@ void TimerController::StopTimer() { bool TimerController::IsRunning() { return timerRunning; -}
\ No newline at end of file +} +void TimerController::OnTimerEnd() { + timerRunning = false; + if(systemTask != nullptr) + systemTask->PushMessage(System::Messages::OnTimerDone); +} + +void TimerController::Register(Pinetime::System::SystemTask* systemTask) { + this->systemTask = systemTask; +} |