summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/timer/TimerController.cpp32
-rw-r--r--src/components/timer/TimerController.h24
2 files changed, 17 insertions, 39 deletions
diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp
index 55b7d56..eeee61f 100644
--- a/src/components/timer/TimerController.cpp
+++ b/src/components/timer/TimerController.cpp
@@ -3,11 +3,9 @@
using namespace Pinetime::Controllers;
-namespace {
- void TimerCallback(TimerHandle_t xTimer) {
- auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer));
- controller->OnTimerEnd();
- }
+void TimerCallback(TimerHandle_t xTimer) {
+ auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer));
+ controller->OnTimerEnd();
}
void TimerController::Init(Pinetime::System::SystemTask* systemTask) {
@@ -18,37 +16,25 @@ void TimerController::Init(Pinetime::System::SystemTask* systemTask) {
void TimerController::StartTimer(uint32_t duration) {
xTimerChangePeriod(timer, pdMS_TO_TICKS(duration), 0);
xTimerStart(timer, 0);
- timerRunning = true;
- overtime = false;
}
-int32_t TimerController::GetSecondsRemaining() {
+uint32_t TimerController::GetTimeRemaining() {
if (IsRunning()) {
- int32_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
- return remainingTime / configTICK_RATE_HZ;
+ TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
+ return (remainingTime * 1000 / configTICK_RATE_HZ);
}
return 0;
}
void TimerController::StopTimer() {
xTimerStop(timer, 0);
- timerRunning = false;
- if (overtime) {
- StopAlerting();
- overtime = false;
- }
}
-void TimerController::StopAlerting() {
- if (systemTask != nullptr) {
- systemTask->PushMessage(System::Messages::StopRinging);
- }
+bool TimerController::IsRunning() {
+ return (xTimerIsTimerActive(timer) == pdTRUE);
}
void TimerController::OnTimerEnd() {
- overtime = true;
- if (systemTask != nullptr) {
- systemTask->PushMessage(System::Messages::OnTimerDone);
- }
+ systemTask->PushMessage(System::Messages::OnTimerDone);
}
diff --git a/src/components/timer/TimerController.h b/src/components/timer/TimerController.h
index c3bdc2a..93d8afc 100644
--- a/src/components/timer/TimerController.h
+++ b/src/components/timer/TimerController.h
@@ -2,7 +2,6 @@
#include <FreeRTOS.h>
#include <timers.h>
-#include <cstdint>
namespace Pinetime {
namespace System {
@@ -14,28 +13,21 @@ namespace Pinetime {
public:
TimerController() = default;
+ void Init(System::SystemTask* systemTask);
+
void StartTimer(uint32_t duration);
+
void StopTimer();
- void StopAlerting();
- int32_t GetSecondsRemaining();
- inline bool IsOvertime() {
- return overtime;
- }
- inline bool IsRunning() {
- return timerRunning;
- }
- void OnTimerEnd();
+ uint32_t GetTimeRemaining();
- protected:
- friend class Pinetime::System::SystemTask;
- void Init(System::SystemTask* systemTask);
+ bool IsRunning();
+
+ void OnTimerEnd();
private:
System::SystemTask* systemTask = nullptr;
TimerHandle_t timer;
- bool timerRunning = false;
- bool overtime = false;
};
}
-} \ No newline at end of file
+}