~aleteoryx/muditaos

ref: 3cbbeff551230786ae13c23a7bf4fa8c50099896 muditaos/module-bsp/board/linux/hal/key_input/KeyInput.hpp -rw-r--r-- 1.0 KiB
3cbbeff5 — Lefucjusz [MOS-1011] Fix frequency switching stability 2 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <hal/key_input/AbstractKeyInput.hpp>

namespace hal::key_input
{
    class LinuxKeyInput : public AbstractKeyInput
    {
        using KeyEvents                   = std::vector<bsp::KeyEvent>;
        static constexpr auto keyDataSize = 2U;
        using KeyData                     = std::array<int, keyDataSize>;

      public:
        LinuxKeyInput();
        void init(xQueueHandle qHandle) final;
        void deinit() final;
        std::vector<bsp::KeyEvent> getKeyEvents(KeyNotificationSource) final;

      private:
        void worker();

        void addKeyEvent(KeyData data);
        void consumeBytes(std::uint8_t *buff, std::size_t size);
        std::optional<bsp::KeyEvent> translateSliderEvent(KeyData key);

        bool shouldRun{true};
        KeyEvents keyEvents;
        xQueueHandle queueHandle{};
        TaskHandle_t taskHandle{};
    };
} // namespace hal::key_input