~aleteoryx/muditaos

ref: 140cce4c8981263fcc14fc55a37354a2d555eb33 muditaos/module-services/service-evtmgr/WorkerEvent.hpp -rw-r--r-- 2.1 KiB
140cce4c — Lucjan Bryndza [EGD-4029] Prevent call handler recursively (#927) 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

/*
 * WorkerEvent.hpp
 *
 *  Created on: May 31, 2019
 *      Author: kuba
 */

#ifndef MODULE_SERVICES_SERVICE_KBD_WorkerEvent_HPP_
#define MODULE_SERVICES_SERVICE_KBD_WorkerEvent_HPP_

#include "bsp/keyboard/key_codes.hpp"
#include "Service/Service.hpp"
#include "Service/Message.hpp"
#include "Service/Worker.hpp"

#include "EventManager.hpp"

#include "bsp/common.hpp"
#include "bsp/keyboard/key_codes.hpp"

struct KeyState
{
    uint8_t event;
    uint8_t code;
};

enum class WorkerEventQueues
{
    queueService = 0,
    queueControl = 1,
    queueKeyboardIRQ,
    queueHeadsetIRQ,
    queueBattery,
    queueRTC,
    queueHarness,
    queueCellular,
    queueMagnetometerIRQ,
    queueTorch,
};

class WorkerEvent : public sys::Worker
{
  private:
    /**
     * @brief This method is responsible for catch and process keyboard event.
     * @param event key event
     * @param code key code
     * @note It sends message to service if event is processed succesfully.
     */
    void processKeyEvent(bsp::KeyEvents event, bsp::KeyCodes code);
    /**
     * @brief list of keys with long press enabled. First item is key code, second is long press time.
     */
    std::map<uint32_t, uint32_t> longPressParamsList;
    bool longPressTaskEnabled = false;
    bsp::KeyEvents lastState  = bsp::KeyEvents::Released;
    bsp::KeyCodes lastPressed = static_cast<bsp::KeyCodes>(0);

  public:
    WorkerEvent(sys::Service *service) : sys::Worker(service){};
    /**
     * This function is responsible for creating all queues provided in the constructor.
     * When all queues are created this method creates set of queues.
     */
    virtual bool init(std::list<sys::WorkerQueueInfo> queues) override;
    virtual bool deinit() override;

    /**
     * This method is called from thread when new message arrives in queue.
     * @param queueID Index of the queue in the queues vector.
     */
    bool handleMessage(uint32_t queueID) override final;
};

#endif /* MODULE_SERVICES_SERVICE_KBD_WorkerEvent_HPP_ */