~aleteoryx/muditaos

ref: d5de12f7cea071555de4058ebf62b160a86a36af muditaos/module-services/service-gui/ServiceGUI.hpp -rw-r--r-- 3.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/*
 * ServiceGUI.hpp
 *
 *  Created on: 22 maj 2019
 *      Author: robert
 */

#ifndef MODULE_SERVICES_SERVICE_GUI_SERVICEGUI_HPP_
#define MODULE_SERVICES_SERVICE_GUI_SERVICEGUI_HPP_

#include <stdint.h> // for uint32_t
#include <memory>   // for allocator, unique_ptr
#include <string>   // for string
#include <vector>   // for vector

// module-gui
#include "gui/core/Context.hpp"
#include "gui/core/Renderer.hpp" // for Renderer
#include "gui/input/Translator.hpp"
#include "messages/DrawMessage.hpp"
#include "Service/Service.hpp" // for Service
#include "Service/Message.hpp" // for Message_t, DataMessage (ptr only), ResponseMessage (ptr only)
#include "WorkerGUI.hpp"
#include "Common.hpp"         // for RefreshModes, RefreshModes::GUI_REFRESH_DEEP
#include "Service/Common.hpp" // for ReturnCodes, ServicePowerMode
#include "queue.h"            // for QueueDefinition
#include "semphr.h"           // for SemaphoreHandle_t

namespace gui
{
    class Context;
    class DrawCommand;
} // namespace gui

namespace sgui
{

    class WorkerGUI;

    class ServiceGUI : public sys::Service
    {
        friend WorkerGUI;

      protected:
        // this is where every incomming frame is painted.
        gui::Context *renderContext;
        // this buffer is provided to eink
        gui::Context *transferContext;
        // ID of the last rendered frame
        uint32_t renderFrameCounter;
        // ID of the last frame sent to eink for rendering
        uint32_t transferedFrameCounter;
        // Horizontal size of the screen in pixels
        uint32_t screenWidth;
        // vertical size of the screen in pixels
        uint32_t screenHeight;
        // object responsible for rendering images to context
        gui::Renderer renderer;
        // flag that defines whether eink is ready for new frame buffer
        volatile bool einkReady   = false;
        volatile bool requestSent = false;
        volatile bool rendering   = false;
        // set of commands recently received. If this vector is not empty and new set of commands is received
        // previous commands are removed.
        std::vector<std::unique_ptr<gui::DrawCommand>> commands;
        //	uint32_t timer_id= 0;
        gui::RefreshModes mode = gui::RefreshModes::GUI_REFRESH_DEEP;

        // semaphore used to protect commands vector while commands are taken from service to worker.
        SemaphoreHandle_t semCommands;

        WorkerGUI *worker;

        /**
         * Flag controls process of redrawing screen when suspend is in progress.
         */
        bool suspendInProgress = false;
        /**
         * Flag controls process of redrawing screen when phone is shutting down.
         */
        bool shutdownInProgress = false;

        void sendBuffer();
        void sendToRender();

      public:
        ServiceGUI(const std::string &name,
                   std::string parent    = "",
                   uint32_t screenWidth  = 480,
                   uint32_t screenHeight = 600);
        ~ServiceGUI();

        sys::Message_t DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override;

        sys::ReturnCodes InitHandler() override;

        sys::ReturnCodes DeinitHandler() override;

        sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final;
    };

} /* namespace sgui */

#endif /* MODULE_SERVICES_SERVICE_GUI_SERVICEGUI_HPP_ */