Files
MuditaOS/module-apps/GuiTimer.cpp
T
Przemyslaw Brudny 50d0cf0be9 [EGD-5598] GuiTimer refresh window on count
Added Gui timer auto refresh window on count and additional
name based API to detach timer from window. Added
TimerIDGenerator and exception throw on creating user timer
with same name.
2021-02-17 17:33:32 +01:00

61 lines
1.7 KiB
C++

// Copyright (c) 2017-2021, 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), sys::UserTimerIDGenerator()), sysapi{*this, parent}
{}
void GuiTimer::Sysapi::connect(gui::Item *item)
{
if (item != nullptr) {
parent.connect([item, this](sys::Timer &timer) {
if (item->onTimer(parent)) {
app->refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
}
});
}
}
} // namespace app