~aleteoryx/muditaos

ref: dd12853503ae14476b711060679b5f481f643e0e muditaos/module-bsp/board/rt1051/puretx/hal/battery_charger/CurrentMeasurementScope.cpp -rw-r--r-- 1.2 KiB
dd128535 — Adam Dobrowolski [MOS-226] Moved algorithms and their data to separate classes 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CurrentMeasurementScope.hpp"

extern "C"
{
#include "FreeRTOS.h"
}
#include <timers.h>
#include <battery_charger/battery_charger.hpp>
#include <ticks.hpp>

#include <chrono>

namespace hal::battery::CurrentMeasurementScope
{
    namespace
    {
        using namespace std::chrono_literals;
        constexpr auto samplingTime = 100ms;
        TimerHandle_t samplingTimerHandle;

        static void getSample(TimerHandle_t xTimer)
        {
            LOG_DEBUG("[scope]: { \"timestamp\" : %ld, \"current\" : %d, \"current_filtered\" : %d  }",
                      cpp_freertos::Ticks::TicksToMs(cpp_freertos::Ticks::GetTicks()),
                      bsp::battery_charger::getCurrentMeasurement(),
                      bsp::battery_charger::getAvgCurrent());
        }
    } // namespace

    void start()
    {
        if (samplingTimerHandle == nullptr) {
            samplingTimerHandle =
                xTimerCreate("samplingTimer", pdMS_TO_TICKS(samplingTime.count()), true, nullptr, getSample);
        }
        xTimerStart(samplingTimerHandle, 0);
    }

} // namespace hal::battery::CurrentMeasurementScope