-
-
Notifications
You must be signed in to change notification settings - Fork 984
/
Copy pathTimer.cpp
38 lines (30 loc) · 995 Bytes
/
Timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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() {
TickType_t remainingTime = 0;
if (IsRunning()) {
remainingTime = xTimerGetExpiryTime(timer) - xTaskGetTickCount();
} else if (expired > 0) {
remainingTime = xTaskGetTickCount() - expired;
}
return std::chrono::milliseconds(remainingTime * 1000 / configTICK_RATE_HZ);
}
void Timer::StopTimer() {
xTimerStop(timer, 0);
}
bool Timer::IsRunning() {
return (xTimerIsTimerActive(timer) == pdTRUE);
}
void Timer::SetExpiredTime() {
expired = xTimerGetExpiryTime(timer);
}
void Timer::ResetExpiredTime() {
expired = 0;
}