aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/timer/Timer.h
blob: a99f6c4d0429c5a6699dde58004eaaa096f1c2c0 (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
#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();

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