Files
MuditaOS/module-apps/application-clock/ApplicationClock.cpp
2019-06-03 07:35:31 +02:00

133 lines
2.8 KiB
C++

/*
* @file ApplicationClock.cpp
* @author Robert Borzecki (robert.borzecki@mudita.com)
* @date 1 cze 2019
* @brief
* @copyright Copyright (C) 2019 mudita.com
* @details
*/
//module-gui
#include "gui/widgets/Window.hpp"
#include "gui/widgets/Item.hpp"
#include "gui/widgets/Label.hpp"
#include "gui/widgets/BoxLayout.hpp"
//module-utils
#include "log/log.hpp"
//this module
#include "ApplicationClock.hpp"
namespace app {
ApplicationClock::ApplicationClock(std::string name,uint32_t stackDepth,sys::ServicePriority priority) :
Application( name, stackDepth, priority ) {
timer_id = CreateTimer(1000,true);
ReloadTimer(timer_id);
}
ApplicationClock::~ApplicationClock() {
// TODO Auto-generated destructor stub
}
// Invoked upon receiving data message
sys::Message_t ApplicationClock::DataReceivedHandler(sys::DataMessage* msgl) {
return std::make_shared<sys::ResponseMessage>( );
}
// Invoked when timer ticked
void ApplicationClock::TickHandler(uint32_t id) {
LOG_DEBUG("ApplicationClock tick!");
seconds++;
if( seconds > 59 ) {
minute++;
seconds = 0;
}
if( minute > 59 ) {
hour++;
minute = 0;
}
if( hour > 23 ) {
hour = 0;
}
std::string h;
if( hour<10 ) {
h += "0";
}
h += std::to_string(hour);
std::string m;
if( minute < 10 ) {
m+= "0";
}
m += std::to_string(minute);
std::string t = h+":"+m;
UTF8 t8 = UTF8(t.c_str());
timeLabel->setText( t8 );
render(gui::RefreshModes::GUI_REFRESH_FAST );
}
// Invoked during initialization
sys::ReturnCodes ApplicationClock::InitHandler() {
createUserInterface();
setActiveWindow("main");
return sys::ReturnCodes::Success;
}
sys::ReturnCodes ApplicationClock::DeinitHandler() {
return sys::ReturnCodes::Success;
}
sys::ReturnCodes ApplicationClock::WakeUpHandler() {
return sys::ReturnCodes::Success;
}
sys::ReturnCodes ApplicationClock::SleepHandler() {
return sys::ReturnCodes::Success;
}
void ApplicationClock::createUserInterface() {
gui::Window* clockWin = new gui::Window(0);
clockWin = new gui::Window(0);
clockWin->setSize( 480, 600 );
// gui::VBox* vBox = new gui::VBox( clockWin, 0, 0, 480, 600 );
//
// gui::Rect* maxH1 = new gui::Rect();
// maxH1->setBorderColor( gui::ColorNoColor );
// maxH1->setMaxSize( 10, 300 );
//
// gui::Rect* maxH2 = new gui::Rect();
// maxH2->setBorderColor( gui::ColorNoColor );
// maxH2->setMaxSize( 15, 300 );
timeLabel = new gui::Label(clockWin, 0,0,480,600);
timeLabel->setFont("gt_pressura_bold_65");
timeLabel->setText("12:35");
timeLabel->setAlignement( gui::Alignment(gui::Alignment::ALIGN_HORIZONTAL_CENTER, gui::Alignment::ALIGN_VERTICAL_CENTER));
timeLabel->setMaxSize( 480, 180 );
// vBox->addWidget(maxH1);
// vBox->addWidget(timeLabel);
// vBox->addWidget(maxH2);
windows.insert(std::pair<std::string,gui::Window*>("main", clockWin));
}
void ApplicationClock::destroyUserInterface() {
}
} /* namespace app */