~aleteoryx/muditaos

ref: master muditaos/module-services/service-evtmgr/battery/BatteryController.hpp -rw-r--r-- 1.7 KiB
2cd0e472 — Lefucjusz [BH-000] Update Harmony 2.10.0 changelog 2 months 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <hal/battery_charger/AbstractBatteryCharger.hpp>
#include "EventManagerParams.hpp"
#include "BatteryBrownoutDetector.hpp"
#include "BatteryState.hpp"
#include "EventStore.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;
        BatteryController(sys::Service *service, xQueueHandle notificationChannel, EventManagerParams params);

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

      private:
        void update();
        void updateSoc();
        void printCurrentState();
        void checkChargerPresence();
        void sendChargingNotification(const Store::Battery::State &lastState,
                                      const Store::Battery::State &currentState);
        units::Voltage getVoltage();

        sys::Service *service{nullptr};
        std::unique_ptr<hal::battery::AbstractBatteryCharger> charger;
        BatteryBrownoutDetector brownoutDetector;
        BatteryState batteryState;
        ChargerPresence chargerPresence{ChargerPresence::Undefined};
        bool isFirstUpdateDone{false};
    };
}; // namespace sevm::battery