~aleteoryx/muditaos

ref: 4b66a8974f369f4f3820a53cc348a4c3b78e01b0 muditaos/module-services/service-evtmgr/screen-light-control/ScreenLightControlParameters.hpp -rw-r--r-- 4.9 KiB
4b66a897 — Lefucjusz [BH-1782] Add brightness fade in 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "ControlFunctions.hpp"
#include <optional>

namespace screen_light_control
{
    // Sender which send light request
    enum class Sender
    {
        Other,
        AlarmPrewakeup,
        Alarm,
        PowerNap
    };

    /// Modes in which front light can operate
    enum class ScreenLightMode
    {
        Automatic, /// Automatically sets screen brightness based on sensor data
        Manual     /// Manually set brightness level
    };

    /// Set of actions to control the screen light
    enum class Action
    {
        turnOff,                    ///< Turn off screen frontlight
        turnOn,                     ///< Turn on screen frontlight
        enableAutomaticMode,        ///< Enable automatic mode of screen frontlight
        disableAutomaticMode,       ///< Disable automatic mode of screen frontlight
        setManualModeBrightness,    ///< Set screen brightness in manual mode control
        setAutomaticModeParameters, ///< Set parameters for automatic mode of screen frontlight
        fadeOut,                    ///< Set light fade out in automatic mode
        ignoreKeypress,             ///< Enter state that ignores keypress turnon
        stopIgnoringKeypress,       ///< Leave state that ignores keypress turon
    };

    struct ManualModeParameters
    {
        static constexpr auto MAX_BRIGHTNESS = 100.0;
        /// Screen brightness 0-100% in manual mode
        bsp::eink_frontlight::BrightnessPercentage manualModeBrightness = 50.0f;
    };

    struct AutomaticModeParameters
    {
        /// Vector of points for screen brightness [%] in relation to ambient light [Lux] function. Points have to be in
        /// ascending order of ambient light values.
        functions::BrightnessFunction functionPoints = functions::BrightnessFunction(
            {{0.0f, 35.0f}, {10.0f, 75.0f}, {85.0f, 100.0f}, {500.0f, 100.0f}, {520.0f, 0.0f}});
        /// Ramp time of screen brightness in milliseconds per 0-100% change
        unsigned int rampTimeMS = 1500;
        /// Hysteresis value of screen brightness control
        float brightnessHysteresis = 10.0f;
        /// Gamma factor for screen brightness correction
        float gammaFactor = 2.5f;
    };

    struct LinearProgressModeParameters
    {
        using LinearFunctions = std::vector<functions::LinearProgressFunction>;

        /// Manually set starting value of the brightness
        float startBrightnessValue = 0.0f;
        /// Vector of linear functions of progressive screen brightness
        LinearFunctions functions{
            functions::LinearProgressFunction{.target = 100.0f, .duration = std::chrono::milliseconds{1500}}};
        /// Hysteresis value of screen brightness control
        float brightnessHysteresis = 0.0f;
    };

    struct ConstLinearProgressModeParameters
    {
        float targetBrightness = 0.0f;
    };

    class Parameters
    {
        std::optional<ManualModeParameters> manualModeParams;
        std::optional<AutomaticModeParameters> autoModeParams;
        std::optional<LinearProgressModeParameters> linearProgressModeParams;
        std::optional<ConstLinearProgressModeParameters> constLinearProgressModeParams;

      public:
        Parameters() = default;
        explicit Parameters(ManualModeParameters manualModeParams) : manualModeParams{manualModeParams}
        {}

        explicit Parameters(const AutomaticModeParameters &autoModeParams) : autoModeParams{autoModeParams}
        {}

        explicit Parameters(const LinearProgressModeParameters &autoModeParams)
            : linearProgressModeParams{autoModeParams}
        {}
        explicit Parameters(const ConstLinearProgressModeParameters &autoModeParams)
            : constLinearProgressModeParams{autoModeParams}
        {}

        [[nodiscard]] bool hasManualModeParams() const noexcept
        {
            return manualModeParams.has_value();
        }

        [[nodiscard]] auto getManualModeParams() const noexcept -> ManualModeParameters;

        [[nodiscard]] bool hasAutoModeParams() const noexcept
        {
            return autoModeParams.has_value();
        }

        [[nodiscard]] auto getAutoModeParams() const noexcept -> const AutomaticModeParameters &;

        [[nodiscard]] bool hasLinearProgressModeParams() const noexcept
        {
            return linearProgressModeParams.has_value();
        }

        [[nodiscard]] auto getLinearProgressModeParams() const noexcept -> const LinearProgressModeParameters &;

        [[nodiscard]] bool hasConstLinearProgressModeParams() const noexcept
        {
            return constLinearProgressModeParams.has_value();
        }

        [[nodiscard]] auto getConstLinearProgressModeParams() const noexcept
            -> const ConstLinearProgressModeParameters &;
    };
} // namespace screen_light_control