~aleteoryx/muditaos

ref: 25a5d90f4e12ee5d33f4202170f18b59e16a9564 muditaos/module-bluetooth/Bluetooth/command/BatteryLevel.hpp -rw-r--r-- 1.4 KiB
25a5d90f — rrandomsky [CP-2156] Fixed no response when editing a contact to have the same number as another 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
namespace bluetooth
{

    class BatteryLevel
    {
        static constexpr auto batteryLowValue = 0;
        static constexpr auto batteryMaxValue = 100;

      public:
        explicit BatteryLevel(unsigned int level) : level(level){};
        BatteryLevel() = default;
        auto getBatteryLevel() const -> unsigned int
        {
            return std::clamp<unsigned int>(level, batteryLowValue, batteryMaxValue);
        }
        auto getBatteryLevelBars() const -> unsigned int
        {
            constexpr auto level1Threshold = 15;
            constexpr auto level2Threshold = 35;
            constexpr auto level3Threshold = 55;
            constexpr auto level4Threshold = 75;
            constexpr auto level5Threshold = 95;

            if (level < level1Threshold) {
                return 0;
            }
            else if (level < level2Threshold) {
                return 1;
            }
            else if (level < level3Threshold) {
                return 2;
            }
            else if (level < level4Threshold) {
                return 3;
            }
            else if (level < level5Threshold) {
                return 4;
            }
            else {
                return 5;
            }
        }

      private:
        unsigned int level = 0;
    };
} // namespace bluetooth