aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/timer/Timer.h
blob: d43c7970e7fa0f13fda2c795d9245ba55fe91a7f (plain)
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
#pragma once

#include <FreeRTOS.h>
#include <timers.h>

#include <chrono>
#include <optional>

namespace Pinetime {
  namespace Controllers {
    class Timer {
    public:
      struct TimerStatus {
        std::chrono::milliseconds distanceToExpiry;
        bool expired;
      };

      Timer(void* timerData, TimerCallbackFunction_t timerCallbackFunction);

      void StartTimer(std::chrono::milliseconds duration);

      void StopTimer();

      std::optional<TimerStatus> GetTimerState();

      bool IsRunning();

      void ResetExpiredTime();

    private:
      TimerHandle_t timer;
      TickType_t expiry;
      bool triggered = false;
    };
  }
}