~aleteoryx/muditaos

ref: 3cbbeff551230786ae13c23a7bf4fa8c50099896 muditaos/module-bsp/board/linux/torch/torch.cpp -rw-r--r-- 1.6 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
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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "bsp/torch/torch.hpp"
#include <log/log.hpp>

namespace bsp
{
    namespace torch
    {
        State state_simulated               = State::off;
        ColourTemperature currentColourTemp = ColourTemperature::warmest;

        std::int32_t init()
        {
            state_simulated = State::off;
            return 1;
        }

        void deinit()
        {}

        bool isPresent(void)
        {
            return true;
        }

        bool turn(State state, ColourTemperature colourTemp)
        {
            state_simulated = state;
            if (colourTemp != ColourTemperature::noChange) {
                currentColourTemp = colourTemp;
            }

            if (state == State::on) {
                LOG_INFO("Torch is ON \U0001f526 (%s)",
                         currentColourTemp == ColourTemperature::warmest ? "warm \U0001f987" : "cold \U0001f535");
            }
            else {
                LOG_INFO("Torch is OFF");
            }
            return true;
        }

        State getState()
        {
            return state_simulated;
        }

        ColourTemperature getColorTemp()
        {
            return currentColourTemp;
        }

        bool toggle()
        {
            return turn(getState() == State::off ? State::on : State::off);
        };

        bool setCurrent(const unsigned short mA)
        {
            return true;
        }
    } // namespace torch
} // namespace bsp