~aleteoryx/muditaos

ref: b3f228878dcebeb519d2206c9d333091abe650d0 muditaos/module-services/service-evtmgr/battery/BatteryController.cpp -rw-r--r-- 1.3 KiB
b3f22887 — GravisZro [EGD-7254] Fix submodule update script 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
43
44
45
46
47
48
49
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BatteryController.hpp"

#include <battery-level-check/BatteryLevelCheck.hpp>

#include <service-evtmgr/BatteryMessages.hpp>
#include <service-evtmgr/Constants.hpp>

using sevm::battery::BatteryController;

BatteryController::BatteryController(sys::Service *service)
    : service(service), charger{std::make_shared<hal::battery::BatteryCharger>(*this)},
      brownoutDetector(service, charger)
{}

void BatteryController::handleChargerNotification(std::uint8_t notification)
{
    charger->setChargingCurrentLimit(notification);
}

void BatteryController::handleBatteryNotification(std::uint8_t notification)
{
    charger->processStateChangeNotification(notification);
}

void BatteryController::init(xQueueHandle queueBatteryHandle, xQueueHandle queueChargerDetect)
{
    charger->init(queueBatteryHandle, queueChargerDetect);
}

void BatteryController::deinit()
{
    charger->deinit();
}

void BatteryController::onBrownout()
{
    brownoutDetector.startDetection();
}

void BatteryController::onStatusChanged()
{
    battery_level_check::checkBatteryLevel();

    auto message = std::make_shared<sevm::BatteryStatusChangeMessage>();
    service->bus.sendUnicast(std::move(message), service::name::evt_manager);
}