~aleteoryx/muditaos

ref: 44d3306f280cc7d6daa718d2a9f6323e48f54616 muditaos/module-services/service-evtmgr/tests/test-ScreenLightControlFunctions.cpp -rw-r--r-- 3.7 KiB
44d3306f — rrandomsky [CP-1059] Fix for erase only sensitive data from logs 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp>
#include <screen-light-control/ControlFunctions.hpp>

TEST_CASE("ScreenLightControlFunctions")
{
    using namespace screen_light_control::functions;
    constexpr auto controlTimerMS = 25;

    SECTION("Ramp an hysteresis test")
    {
        INFO("Setup");
        const unsigned int testRampTime                          = 500;
        const bsp::eink_frontlight::BrightnessPercentage testVal = 100.0f;
        screen_light_control::functions::BrightnessFunction functionPoints =
            BrightnessFunction({{0.0f, testVal}, {100.0f, 0.0f}});
        const float hysteresis = 10.0f;

        setRampStep(100.0f * (static_cast<float>(controlTimerMS) / static_cast<float>(testRampTime)));
        setHysteresis(hysteresis);
        setFunctionFromPoints(functionPoints);

        INFO("Simple ramp test");
        // Timer callback cycles
        int cyclesPerRamp = testRampTime / controlTimerMS;
        // Mock the measurement
        calculateBrightness(0.0f);
        auto rampOut = 0.0f;
        for (int i = 0; i < cyclesPerRamp; ++i) {
            rampOut = brightnessRampOut();
        }
        CHECK(rampOut == testVal);

        INFO("Hysteresis preventing the change");
        calculateBrightness(9.5f);
        for (int i = 0; i < cyclesPerRamp; ++i) {
            rampOut = brightnessRampOut();
        }
        CHECK(rampOut == testVal);

        INFO("Out of hysteresis");
        calculateBrightness(110.0f);
        for (int i = 0; i < cyclesPerRamp; ++i) {
            rampOut = brightnessRampOut();
        }
        CHECK(rampOut == 0.0f);
    }

    SECTION("Brightness function check")
    {
        INFO("Setup and iterate through points");
        const unsigned int testRampTime   = 100;
        BrightnessFunction functionPoints = BrightnessFunction({{50.0f, 50.0f},
                                                                {100.0f, 100.0f},
                                                                {150.0f, 100.0f},
                                                                {200.0f, 0.0f},
                                                                {250.0f, 0.0f},
                                                                {300.0f, 100.0f},
                                                                {350.0f, 50.0f}});
        const float hysteresis            = 10.0f;

        setRampStep(100.0f * (static_cast<float>(controlTimerMS) / static_cast<float>(testRampTime)));
        setHysteresis(hysteresis);
        setFunctionFromPoints(functionPoints);

        int cyclesPerRamp = testRampTime / controlTimerMS;
        // Checking values between the points
        BrightnessFunction testPoints = BrightnessFunction({{0.0f, 50.0f},
                                                            {75.0f, 75.0f},
                                                            {125.0f, 100.0f},
                                                            {175.0f, 50.0f},
                                                            {225.0f, 0.0f},
                                                            {275.0f, 50.0f},
                                                            {325.0f, 75.0f},
                                                            {400.0f, 50.0f}});
        for (const auto &point : testPoints) {
            calculateBrightness(point.first);
            auto rampOut = 0.0f;
            for (int i = 0; i < cyclesPerRamp; ++i) {
                rampOut = brightnessRampOut();
            }
            INFO("Measurement:" << point.first << " Expected:" << point.second << " Actual:" << rampOut);
            CHECK(rampOut == point.second);
        }
    }
}