TimerController: Use chrono for durations
This commit is contained in:
@@ -13,17 +13,17 @@ void TimerController::Init(Pinetime::System::SystemTask* systemTask) {
|
||||
timer = xTimerCreate("Timer", 1, pdFALSE, this, TimerCallback);
|
||||
}
|
||||
|
||||
void TimerController::StartTimer(uint32_t duration) {
|
||||
xTimerChangePeriod(timer, pdMS_TO_TICKS(duration), 0);
|
||||
void TimerController::StartTimer(std::chrono::milliseconds duration) {
|
||||
xTimerChangePeriod(timer, pdMS_TO_TICKS(duration.count()), 0);
|
||||
xTimerStart(timer, 0);
|
||||
}
|
||||
|
||||
uint32_t TimerController::GetTimeRemaining() {
|
||||
std::chrono::milliseconds TimerController::GetTimeRemaining() {
|
||||
if (IsRunning()) {
|
||||
TickType_t remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
|
||||
return (remainingTime * 1000 / configTICK_RATE_HZ);
|
||||
return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ);
|
||||
}
|
||||
return 0;
|
||||
return std::chrono::milliseconds(0);
|
||||
}
|
||||
|
||||
void TimerController::StopTimer() {
|
||||
|
@@ -3,6 +3,8 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <timers.h>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
class SystemTask;
|
||||
@@ -16,11 +18,11 @@ namespace Pinetime {
|
||||
|
||||
void Init(System::SystemTask* systemTask);
|
||||
|
||||
void StartTimer(uint32_t duration);
|
||||
void StartTimer(std::chrono::milliseconds duration);
|
||||
|
||||
void StopTimer();
|
||||
|
||||
uint32_t GetTimeRemaining();
|
||||
std::chrono::milliseconds GetTimeRemaining();
|
||||
|
||||
bool IsRunning();
|
||||
|
||||
|
Reference in New Issue
Block a user