~aleteoryx/muditaos

ref: d5de12f7cea071555de4058ebf62b160a86a36af muditaos/module-apps/GuiTimer.cpp -rw-r--r-- 1.5 KiB
d5de12f7 — Radosław Wicik [EGD-3852] clean include in service (#928) 5 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "GuiTimer.hpp"
#include "Item.hpp"                    // for Item
#include "Service/Timer.hpp"           // for Timer, Timer::Type, Timer::Ty...
#include "module-apps/Application.hpp" // for Application
#include <memory>                      // for allocator

namespace app
{
    namespace
    {
        constexpr auto toSysTimerType(gui::Timer::Type type) noexcept -> sys::Timer::Type
        {
            if (type == gui::Timer::Type::Single) {
                return sys::Timer::Type::SingleShot;
            }
            return sys::Timer::Type::Periodic;
        }
    } // namespace

    void GuiTimer::start()
    {
        sys::Timer::start();
    }

    void GuiTimer::stop()
    {
        sys::Timer::stop();
    }

    void GuiTimer::reset()
    {
        sys::Timer::start();
    }

    void GuiTimer::setInterval(gui::ms time)
    {
        sys::Timer::setInterval(time);
    }

    GuiTimer::GuiTimer(Application *parent) : GuiTimer("GUI", parent)
    {}

    GuiTimer::GuiTimer(const std::string &name, Application *parent, gui::ms timeout, gui::Timer::Type type)
        : sys::Timer(name, parent, timeout, toSysTimerType(type)), sysapi{*this}
    {}

    void GuiTimer::Sysapi::connect(gui::Item *item)
    {
        if (item != nullptr) {
            parent.connect([item, this](sys::Timer &timer) { item->onTimer(parent); });
        }
    }
} // namespace app