/* * @file ApplicationViewer.cpp * @author Robert Borzecki (robert.borzecki@mudita.com) * @date 1 cze 2019 * @brief * @copyright Copyright (C) 2019 mudita.com * @details */ #include #include #include //module-gui #include "ApplicationViewer.hpp" #include "gui/widgets/Window.hpp" #include "gui/widgets/Item.hpp" #include "gui/widgets/Image.hpp" #include "gui/widgets/Label.hpp" #include "gui/widgets/BoxLayout.hpp" #include "gui/core/ImageManager.hpp" //module-utils #include "log/log.hpp" //module-services #include "service-kbd/EventManager.hpp" //MessageType #include "MessageType.hpp" //this module namespace app { ApplicationViewer::ApplicationViewer(std::string name,uint32_t stackDepth,sys::ServicePriority priority) : Application( name, stackDepth, priority ) { } ApplicationViewer::~ApplicationViewer() { // TODO Auto-generated destructor stub } // Invoked upon receiving data message sys::Message_t ApplicationViewer::DataReceivedHandler(sys::DataMessage* msgl) { //if keyboard message receivedz if(msgl->messageType == static_cast(MessageType::KBDKeyEvent) ) { KbdMessage* msg = static_cast(msgl); LOG_INFO("Clock key received %d", static_cast(msg->keyCode)); if( msg->keyState == KeyboardEvents::keyReleasedShort ) { uint32_t oldState = currentState; images[currentState]->setVisible(false); if( msg->keyCode == bsp::KeyCodes::FnLeft ) { currentState = states[currentState].leftState; } else if( msg->keyCode == bsp::KeyCodes::JoystickEnter ) { currentState = states[currentState].middleState; } else if( msg->keyCode == bsp::KeyCodes::FnRight ) { currentState = states[currentState].rightState; } images[currentState]->setVisible(true); if( oldState != currentState ) { if( states[currentState].deepRefresh ) render(gui::RefreshModes::GUI_REFRESH_DEEP ); else render(gui::RefreshModes::GUI_REFRESH_FAST ); } } } return std::make_shared( ); } // Invoked when timer ticked void ApplicationViewer::TickHandler(uint32_t id) { render(gui::RefreshModes::GUI_REFRESH_FAST ); } // Invoked during initialization sys::ReturnCodes ApplicationViewer::InitHandler() { //load all states from file auto file = vfs.fopen("sys/viewerStates.txt","r"); //read line with number of states std::string str = vfs.getline(file); uint32_t statesCount; std::stringstream(str) >> statesCount; LOG_INFO("States count: %d", statesCount ); bool err = false; for( uint32_t i=0; i> leftState; std::stringstream(middleStateStr) >> middleState; std::stringstream(rightStateStr) >> rightState; states.push_back( ViewerState(stateName, screenName, deepRefresh, states.size(), leftState, middleState, rightState ) ); LOG_INFO( "State: %s Screen: %s deep: %d, L:%d, M:%d, R:%d", stateName.c_str(), screenName.c_str(), deepRefresh, leftState, middleState, rightState ); } else { err = true; LOG_FATAL("ERROR reading viwer section"); break; } } if( err ) states.clear(); vfs.fclose(file); createUserInterface(); setActiveWindow("Main"); render(gui::RefreshModes::GUI_REFRESH_DEEP ); return sys::ReturnCodes::Success; } sys::ReturnCodes ApplicationViewer::DeinitHandler() { return sys::ReturnCodes::Success; } sys::ReturnCodes ApplicationViewer::WakeUpHandler() { return sys::ReturnCodes::Success; } sys::ReturnCodes ApplicationViewer::SleepHandler() { return sys::ReturnCodes::Success; } void ApplicationViewer::createUserInterface() { gui::Window* clockWin = new gui::Window("Main"); clockWin->setSize( 480, 600 ); for( ViewerState s : states ) { gui::Image* img = new gui::Image(clockWin,0,0,0,0); uint16_t id = gui::ImageManager::getInstance().getImageMapID(s.screenName); img->setImageWithID( id ); img->setVisible(false); images.push_back( img ); } currentState = 0; if( states.size() ) images[currentState]->setVisible(true); windows.insert(std::pair(clockWin->getName(), clockWin)); } void ApplicationViewer::destroyUserInterface() { } } /* namespace app */