aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/timer
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/timer')
-rw-r--r--src/components/timer/Timer.cpp28
-rw-r--r--src/components/timer/Timer.h (renamed from src/components/timer/TimerController.h)14
-rw-r--r--src/components/timer/TimerController.cpp39
3 files changed, 30 insertions, 51 deletions
diff --git a/src/components/timer/Timer.cpp b/src/components/timer/Timer.cpp
new file mode 100644
index 00000000..279178cd
--- /dev/null
+++ b/src/components/timer/Timer.cpp
@@ -0,0 +1,28 @@
+#include "components/timer/Timer.h"
+
+using namespace Pinetime::Controllers;
+
+Timer::Timer(void* const timerData, TimerCallbackFunction_t timerCallbackFunction) {
+ timer = xTimerCreate("Timer", 1, pdFALSE, timerData, timerCallbackFunction);
+}
+
+void Timer::StartTimer(std::chrono::milliseconds duration) {
+ xTimerChangePeriod(timer, pdMS_TO_TICKS(duration.count()), 0);
+ xTimerStart(timer, 0);
+}
+
+std::chrono::milliseconds Timer::GetTimeRemaining() {
+ if (IsRunning()) {
+ TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
+ return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ);
+ }
+ return std::chrono::milliseconds(0);
+}
+
+void Timer::StopTimer() {
+ xTimerStop(timer, 0);
+}
+
+bool Timer::IsRunning() {
+ return (xTimerIsTimerActive(timer) == pdTRUE);
+}
diff --git a/src/components/timer/TimerController.h b/src/components/timer/Timer.h
index 1c2e44b6..2469666f 100644
--- a/src/components/timer/TimerController.h
+++ b/src/components/timer/Timer.h
@@ -6,17 +6,10 @@
#include <chrono>
namespace Pinetime {
- namespace System {
- class SystemTask;
- }
-
namespace Controllers {
-
- class TimerController {
+ class Timer {
public:
- TimerController() = default;
-
- void Init(System::SystemTask* systemTask);
+ Timer(void* timerData, TimerCallbackFunction_t timerCallbackFunction);
void StartTimer(std::chrono::milliseconds duration);
@@ -26,10 +19,7 @@ namespace Pinetime {
bool IsRunning();
- void OnTimerEnd();
-
private:
- System::SystemTask* systemTask = nullptr;
TimerHandle_t timer;
};
}
diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp
deleted file mode 100644
index 5e7f1eed..00000000
--- a/src/components/timer/TimerController.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "components/timer/TimerController.h"
-#include "systemtask/SystemTask.h"
-
-using namespace Pinetime::Controllers;
-
-void TimerCallback(TimerHandle_t xTimer) {
- auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer));
- controller->OnTimerEnd();
-}
-
-void TimerController::Init(Pinetime::System::SystemTask* systemTask) {
- this->systemTask = systemTask;
- timer = xTimerCreate("Timer", 1, pdFALSE, this, TimerCallback);
-}
-
-void TimerController::StartTimer(std::chrono::milliseconds duration) {
- xTimerChangePeriod(timer, pdMS_TO_TICKS(duration.count()), 0);
- xTimerStart(timer, 0);
-}
-
-std::chrono::milliseconds TimerController::GetTimeRemaining() {
- if (IsRunning()) {
- TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
- return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ);
- }
- return std::chrono::milliseconds(0);
-}
-
-void TimerController::StopTimer() {
- xTimerStop(timer, 0);
-}
-
-bool TimerController::IsRunning() {
- return (xTimerIsTimerActive(timer) == pdTRUE);
-}
-
-void TimerController::OnTimerEnd() {
- systemTask->PushMessage(System::Messages::OnTimerDone);
-}