~aleteoryx/muditaos

ref: 9098f69e7b9f22e2333d83e2f2503797a1d6b8df muditaos/module-gui/gui/core/Timer.hpp -rw-r--r-- 1.1 KiB
9098f69e — Wojtek Rzepecki [EGD-5814] Fix battery revert 4 years ago
                                                                                
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
39
40
41
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

namespace gui
{
    using ms = unsigned int;

    /// gui::Timer helper class to be used as passed to gui::Item `onTimer` function
    /// this interface should be connected to real timer build with system Timer
    /// all gui timers should be `Coarse` timers
    class Timer
    {
      public:
        virtual ~Timer() = default;
        enum Type
        {
            Single,   /// single run timer
            Continous /// free running timers
        };
        virtual void start()              = 0;
        virtual void stop()               = 0;
        virtual void reset()              = 0;
        virtual void setInterval(ms time) = 0;
        [[nodiscard]] auto interval() const -> ms;

      protected:
        Type type = Single;

      public:
        [[nodiscard]] auto getType() const -> Type
        {
            return type;
        }
        virtual void setType(Type new_type)
        {
            type = new_type;
        };
    };
}; // namespace gui