~aleteoryx/muditaos

ref: b8239928370663155dc8556354b3715dd387fc5a muditaos/module-services/service-evtmgr/backlight-handler/BacklightHandler.hpp -rw-r--r-- 3.4 KiB
b8239928 — Jakub Pyszczak [EGD-6655] Screen light when active 4 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
// 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 <bsp/keypad_backlight/keypad_backlight.hpp>
#include <service-evtmgr/screen-light-control/ScreenLightControl.hpp>
#include <Timers/TimerHandle.hpp>

namespace settings
{
    class Settings;
} // namespace settings

namespace backlight
{
    class SettingsInterface
    {
      public:
        virtual ~SettingsInterface() = default;

      protected:
        virtual auto getValue(std::string path) const -> std::string = 0;
        virtual void setValue(std::string path, std::string value)   = 0;
    };

    /// @brief Backlight events handler
    class Handler : public SettingsInterface
    {
      public:
        Handler(std::shared_ptr<settings::Settings> settings, sys::Service *parent);

        /// Process request of the screen light control
        /// @screen_light_control::Action an action to perform
        void processScreenRequest(screen_light_control::Action action);

        /// Process request of the screen light control with specified parameters
        /// @screen_light_control::ParameterizedAction an action to perform
        /// @screen_light_control::Parameters parameters being set
        void processScreenRequest(screen_light_control::ParameterizedAction action,
                                  screen_light_control::Parameters params);

        void handleKeyPressed();
        /// Process request of the keypad light control
        /// @screen_light_control::ParameterizedAction an action to perform
        /// @return True if request was processed succesfully, false otherwise
        auto processKeypadRequest(bsp::keypad_backlight::Action action) -> bool;

        [[nodiscard]] auto getScreenLightState() const noexcept -> bool;
        [[nodiscard]] auto getScreenAutoModeState() const noexcept -> screen_light_control::ScreenLightMode;
        [[nodiscard]] auto getScreenBrightnessValue() const noexcept -> bsp::eink_frontlight::BrightnessPercentage;

      protected:
        [[nodiscard]] auto getValue(std::string path) const -> std::string override;
        void setValue(std::string path, std::string value) override;

      private:
        std::shared_ptr<settings::Settings> settings;
        std::unique_ptr<screen_light_control::ScreenLightControl> screenLightControl;
        /// Timer that keeps key backlight on for a certain time if there was key pressed
        sys::TimerHandle keypadLightTimer;
        /// Timer that keeps screen backlight on for a certain time if there was key pressed
        sys::TimerHandle screenLightTimer;
        bsp::keypad_backlight::State keypadLightState = bsp::keypad_backlight::State::off;
        bool isKeypadLightInCallMode                  = false;

        void startKeypadLightTimer();
        void startScreenLightTimer();
        void stopKeypadTimer();
        void setKeypadLightInCallMode(bool value) noexcept;
        void setKeypadLightState(bsp::keypad_backlight::State value) noexcept;
        void restoreKeypadLightState();
        void handleKeypadLightRefresh();
        void handleScreenLightRefresh();
        void handleScreenLightSettings(screen_light_control::Action action);
        void handleScreenLightSettings(screen_light_control::ParameterizedAction action,
                                       screen_light_control::Parameters params);
    };
} // namespace backlight