~aleteoryx/muditaos

ref: 90543e264fc1857ec7b13b3fd0be8095e472cb42 muditaos/module-services/service-evtmgr/battery/BatteryController.hpp -rw-r--r-- 1.4 KiB
90543e26 — Maciej Gibowicz [MOS-648] Fix USB connection/disconnection detection 3 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <hal/battery_charger/AbstractBatteryCharger.hpp>
#include "BatteryBrownoutDetector.hpp"
#include "BatteryState.hpp"

#include <queue.hpp>
#include <memory>
#include <cstdint>

namespace sevm::battery
{
    /// Battery controller class that glues various submodules together. It does not perform any logic by itself but
    /// just routes notifications and messages received from corresponding submodules.
    class BatteryController
    {
      public:
        using Events = hal::battery::AbstractBatteryCharger::Events;
        using ChargerPresence = hal::battery::AbstractBatteryCharger::ChargerPresence;
        explicit BatteryController(sys::Service *service, xQueueHandle notificationChannel);

        void poll();

        /// Handler for incoming async notifications from the back-end
        void handleNotification(Events);

      private:
        void update();
        void updateSoC();
        void printCurrentState();
        void checkChargerPresence();
        sys::Service *service{nullptr};
        std::unique_ptr<hal::battery::AbstractBatteryCharger> charger;
        BatteryBrownoutDetector brownoutDetector;
        BatteryState batteryState;
        ChargerPresence chargerPresence{ChargerPresence::Undefined};
    };
}; // namespace sevm::battery