~aleteoryx/muditaos

f16a18d9357699fef061bfa6a00206195bc4ea8e — Marcin Smoczyński 4 years ago 91da023
[BH-860] Decouple charger driver from system

Remove system dependency from charger driver implementation. Remove
circular, lambda driven dependency between charger and brownout
detector. Remove event manager dependency in driver as well.
Encapsulate some of charger logic in introduced battery controller.

Extract path configuration to the separate target to decouple charger
from vfs middleware.

Signed-off-by: Marcin Smoczyński <smoczynski.marcin@gmail.com>
M module-bsp/CMakeLists.txt => module-bsp/CMakeLists.txt +1 -0
@@ 77,6 77,7 @@ target_link_libraries(${PROJECT_NAME}
        magic_enum
        ${TARGET_LIBRARIES}
    PRIVATE
        purefs-paths
        time-constants
)


M module-bsp/board/linux/hal/battery_charger/BatteryCharger.cpp => module-bsp/board/linux/hal/battery_charger/BatteryCharger.cpp +16 -18
@@ 3,23 3,17 @@

#include "BatteryCharger.hpp"

#include <sys/stat.h>
#include <fcntl.h>
#include <EventStore.hpp>
#include <hal/GenericFactory.hpp>
#include <service-evtmgr/battery-level-check/BatteryLevelCheck.hpp>
#include <service-evtmgr/BatteryMessages.hpp>
#include <service-evtmgr/EventManagerCommon.hpp>
#include <magic_enum.hpp>

#include <algorithm>

#include <sys/stat.h>
#include <fcntl.h>

namespace hal::battery
{
    std::shared_ptr<AbstractBatteryCharger> AbstractBatteryCharger::Factory::create(sys::Service *service)
    {
        return hal::impl::factory<LinuxBatteryCharger, AbstractBatteryCharger>(service);
    }

    namespace
    {


@@ 36,7 30,8 @@ namespace hal::battery
        constexpr auto queueTimeoutTicks    = 100;
        constexpr auto taskDelay            = 50;

        constexpr unsigned fullBattery = 100;
        constexpr auto fullBattery              = 100U;
        constexpr auto dummyBatteryVoltageLevel = 3700;

        constexpr auto chargerPlugStateChange = 'p';
        constexpr auto batteryLevelUp         = ']';


@@ 101,10 96,11 @@ namespace hal::battery
        }
    } // namespace

    LinuxBatteryCharger::LinuxBatteryCharger(sys::Service *service) : service{service}
    BatteryCharger::BatteryCharger(AbstractBatteryCharger::BatteryChargerEvents &eventsHandler)
        : eventsHandler(eventsHandler)
    {}

    void LinuxBatteryCharger::init(xQueueHandle irqQueueHandle, xQueueHandle dcdQueueHandle)
    void BatteryCharger::init(xQueueHandle irqQueueHandle, xQueueHandle dcdQueueHandle)
    {
        IRQQueueHandle = irqQueueHandle;
        DCDQueueHandle = dcdQueueHandle;


@@ 113,14 109,14 @@ namespace hal::battery
        Store::Battery::modify().level = batteryLevel;
    }

    void LinuxBatteryCharger::deinit()
    void BatteryCharger::deinit()
    {
        IRQQueueHandle = nullptr;
        DCDQueueHandle = nullptr;
        vTaskDelete(batteryWorkerHandle);
    }

    void LinuxBatteryCharger::processStateChangeNotification(std::uint8_t notification)
    void BatteryCharger::processStateChangeNotification(std::uint8_t notification)
    {
        if (isPlugged) {
            if (batteryLevel > fullBattery) {


@@ 137,13 133,15 @@ namespace hal::battery
        }
        batteryLevel                   = std::clamp(batteryLevel, unsigned{0}, fullBattery);
        Store::Battery::modify().level = batteryLevel;
        battery_level_check::checkBatteryLevel();
        eventsHandler.onStatusChanged();
    }

        auto message = std::make_shared<sevm::BatteryStatusChangeMessage>();
        service->bus.sendUnicast(std::move(message), service::name::evt_manager);
    int BatteryCharger::getBatteryVoltage()
    {
        return dummyBatteryVoltageLevel;
    }

    void LinuxBatteryCharger::setChargingCurrentLimit(std::uint8_t usbType)
    void BatteryCharger::setChargingCurrentLimit(std::uint8_t usbType)
    {
        auto usbTypeStr = magic_enum::enum_name(static_cast<USBSourceType>(usbType));
        LOG_INFO("Setup charging current for usb source type: %s", usbTypeStr.data());

M module-bsp/board/linux/hal/battery_charger/BatteryCharger.hpp => module-bsp/board/linux/hal/battery_charger/BatteryCharger.hpp +5 -6
@@ 3,22 3,21 @@

#pragma once

#include <module-bsp/hal/battery_charger/AbstractBatteryCharger.hpp>

#include <memory>
#include <hal/battery_charger/AbstractBatteryCharger.hpp>

namespace hal::battery
{
    class LinuxBatteryCharger : public AbstractBatteryCharger
    class BatteryCharger : public AbstractBatteryCharger
    {
      public:
        explicit LinuxBatteryCharger(sys::Service *service);
        explicit BatteryCharger(AbstractBatteryCharger::BatteryChargerEvents &eventsHandler);
        void init(xQueueHandle irqQueueHandle, xQueueHandle dcdQueueHandle) final;
        void deinit() final;
        void processStateChangeNotification(std::uint8_t notification) final;
        void setChargingCurrentLimit(std::uint8_t usbType) final;
        int getBatteryVoltage() final;

      private:
        sys::Service *service;
        AbstractBatteryCharger::BatteryChargerEvents &eventsHandler;
    };
} // namespace hal::battery

M module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.cpp => module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.cpp +11 -12
@@ 5,26 5,25 @@

#include <hal/GenericFactory.hpp>
#include <EventStore.hpp>
#include <service-evtmgr/battery-level-check/BatteryLevelCheck.hpp>
#include <service-evtmgr/BatteryMessages.hpp>
#include <service-evtmgr/EventManagerCommon.hpp>

namespace hal::battery
{
    std::shared_ptr<AbstractBatteryCharger> AbstractBatteryCharger::Factory::create(sys::Service *service)
    {
        return hal::impl::factory<BatteryCharger, AbstractBatteryCharger>(service);
    }

    BatteryCharger::BatteryCharger(sys::Service *service) : service{service}
    BatteryCharger::BatteryCharger(AbstractBatteryCharger::BatteryChargerEvents &eventsHandler)
        : eventsHandler(eventsHandler)
    {}

    void BatteryCharger::init(xQueueHandle queueBatteryHandle, xQueueHandle)
    {
        // Mocking initial state to make system run
        Store::Battery::modify().state = Store::Battery::State::Discharging;
        Store::Battery::modify().level = 100;
        auto message                   = std::make_shared<sevm::BatteryStatusChangeMessage>();
        service->bus.sendUnicast(std::move(message), service::name::evt_manager);
        Store::Battery::modify().level = getBatteryVoltage();
        eventsHandler.onStatusChanged();
    }

    int BatteryCharger::getBatteryVoltage()
    {
        constexpr auto dummyBatteryLevel = 100;
        return dummyBatteryLevel;
    }

    void BatteryCharger::BatteryCharger::deinit()

M module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.hpp => module-bsp/board/rt1051/bellpx/hal/battery_charger/BatteryCharger.hpp +4 -5
@@ 3,22 3,21 @@

#pragma once

#include <module-bsp/hal/battery_charger/AbstractBatteryCharger.hpp>

#include <memory>
#include <hal/battery_charger/AbstractBatteryCharger.hpp>

namespace hal::battery
{
    class BatteryCharger : public AbstractBatteryCharger
    {
      public:
        explicit BatteryCharger(sys::Service *);
        explicit BatteryCharger(AbstractBatteryCharger::BatteryChargerEvents &eventsHandler);
        void init(xQueueHandle queueBatteryHandle, xQueueHandle) final;
        void deinit() final;
        void processStateChangeNotification(std::uint8_t notification) final;
        void setChargingCurrentLimit(std::uint8_t) final;
        int getBatteryVoltage() final;

      private:
        sys::Service *service;
        AbstractBatteryCharger::BatteryChargerEvents &eventsHandler;
    };
} // namespace hal::battery

M module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.cpp => module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.cpp +16 -30
@@ 3,30 3,13 @@

#include "BatteryCharger.hpp"

#include <hal/GenericFactory.hpp>

#include <bsp/battery_charger/battery_charger.hpp>
#include <service-evtmgr/battery-level-check/BatteryLevelCheck.hpp>
#include <service-evtmgr/BatteryMessages.hpp>
#include <SystemManager/SystemManagerCommon.hpp>
#include <service-evtmgr/EventManagerCommon.hpp>
#include <hal/GenericFactory.hpp>

namespace hal::battery
{
    std::shared_ptr<AbstractBatteryCharger> AbstractBatteryCharger::Factory::create(sys::Service *service)
    {
        return hal::impl::factory<BatteryCharger, AbstractBatteryCharger>(service);
    }

    BatteryCharger::BatteryCharger(sys::Service *service)
        : service{service}, batteryBrownoutDetector{
                                service,
                                []() { return bsp::battery_charger::getVoltageFilteredMeasurement(); },
                                [service]() {
                                    auto messageBrownout = std::make_shared<sevm::BatteryBrownoutMessage>();
                                    service->bus.sendUnicast(std::move(messageBrownout), service::name::system_manager);
                                },
                                [this]() { checkBatteryChargerInterrupts(); }}
    BatteryCharger::BatteryCharger(AbstractBatteryCharger::BatteryChargerEvents &eventsHandler)
        : eventsHandler(eventsHandler)
    {}

    void BatteryCharger::init(xQueueHandle queueBatteryHandle, xQueueHandle queueChargerDetect)


@@ 46,6 29,11 @@ namespace hal::battery
        }
    }

    int BatteryCharger::getBatteryVoltage()
    {
        return bsp::battery_charger::getVoltageFilteredMeasurement();
    }

    void BatteryCharger::setChargingCurrentLimit(std::uint8_t chargerType)
    {
        using namespace bsp::battery_charger;


@@ 74,26 62,25 @@ namespace hal::battery
        if (topINT & static_cast<std::uint8_t>(bsp::battery_charger::topControllerIRQsource::CHGR_INT)) {
            bsp::battery_charger::getChargeStatus();
            bsp::battery_charger::actionIfChargerUnplugged();
            auto message = std::make_shared<sevm::BatteryStatusChangeMessage>();
            service->bus.sendUnicast(std::move(message), service::name::evt_manager);
            battery_level_check::checkBatteryLevel();
            bsp::battery_charger::clearAllChargerIRQs();

            eventsHandler.onStatusChanged();
        }
        if (topINT & static_cast<std::uint8_t>(bsp::battery_charger::topControllerIRQsource::FG_INT)) {
            const auto status = bsp::battery_charger::getStatusRegister();
            if (status & static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::minVAlert)) {
                batteryBrownoutDetector.startDetection();
                bsp::battery_charger::clearFuelGuageIRQ(
                    static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::minVAlert));

                eventsHandler.onBrownout();
            }
            if (status & static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::SOCOnePercentChange)) {
                bsp::battery_charger::printFuelGaugeInfo();
                bsp::battery_charger::clearFuelGuageIRQ(
                    static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::SOCOnePercentChange));
                bsp::battery_charger::getBatteryLevel();
                auto message = std::make_shared<sevm::BatteryStatusChangeMessage>();
                service->bus.sendUnicast(std::move(message), service::name::evt_manager);
                battery_level_check::checkBatteryLevel();

                eventsHandler.onStatusChanged();
            }
            if (status & static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::maxTemp) ||
                status & static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::minTemp)) {


@@ 102,9 89,8 @@ namespace hal::battery
                    static_cast<std::uint16_t>(bsp::battery_charger::batteryINTBSource::minTemp));
                bsp::battery_charger::checkTemperatureRange();
                bsp::battery_charger::getChargeStatus();
                auto message = std::make_shared<sevm::BatteryStatusChangeMessage>();
                service->bus.sendUnicast(std::move(message), service::name::evt_manager);
                battery_level_check::checkBatteryLevel();

                eventsHandler.onStatusChanged();
            }
            // Clear other unsupported IRQ sources just in case
            bsp::battery_charger::clearFuelGuageIRQ(

M module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.hpp => module-bsp/board/rt1051/puretx/hal/battery_charger/BatteryCharger.hpp +4 -7
@@ 3,26 3,23 @@

#pragma once

#include <module-bsp/hal/battery_charger/AbstractBatteryCharger.hpp>
#include <service-evtmgr/battery-brownout-detector/BatteryBrownoutDetector.hpp>

#include <memory>
#include <hal/battery_charger/AbstractBatteryCharger.hpp>

namespace hal::battery
{
    class BatteryCharger : public AbstractBatteryCharger
    {
      public:
        explicit BatteryCharger(sys::Service *service);
        explicit BatteryCharger(AbstractBatteryCharger::BatteryChargerEvents &eventsHandler);
        void init(xQueueHandle queueBatteryHandle, xQueueHandle queueChargerDetect) final;
        void deinit() final;
        void processStateChangeNotification(std::uint8_t notification) final;
        void setChargingCurrentLimit(std::uint8_t chargerType) final;
        int getBatteryVoltage() final;

      private:
        void checkBatteryChargerInterrupts();

        sys::Service *service;
        BatteryBrownoutDetector batteryBrownoutDetector;
        AbstractBatteryCharger::BatteryChargerEvents &eventsHandler;
    };
} // namespace hal::battery

M module-bsp/hal/GenericFactory.hpp => module-bsp/hal/GenericFactory.hpp +1 -1
@@ 16,7 16,7 @@ namespace hal::impl
        static std::weak_ptr<TDerived> singleton;
        auto inst = singleton.lock();
        if (not inst) {
            inst      = std::make_shared<TDerived>(args...);
            inst      = std::make_shared<TDerived>(std::forward<Args>(args)...);
            singleton = inst;
        }
        return inst;

M module-bsp/hal/battery_charger/AbstractBatteryCharger.hpp => module-bsp/hal/battery_charger/AbstractBatteryCharger.hpp +7 -2
@@ 14,9 14,13 @@ namespace hal::battery
    class AbstractBatteryCharger
    {
      public:
        struct Factory
        class BatteryChargerEvents
        {
            static std::shared_ptr<AbstractBatteryCharger> create(sys::Service *service);
          public:
            virtual ~BatteryChargerEvents() = default;

            virtual void onBrownout()      = 0;
            virtual void onStatusChanged() = 0;
        };

        virtual ~AbstractBatteryCharger() = default;


@@ 25,6 29,7 @@ namespace hal::battery
        virtual void deinit()                                     = 0;
        virtual void processStateChangeNotification(std::uint8_t) = 0;
        virtual void setChargingCurrentLimit(std::uint8_t)        = 0;
        virtual int getBatteryVoltage()                           = 0;
    };

    BaseType_t IRQHandler();

M module-services/service-evtmgr/CMakeLists.txt => module-services/service-evtmgr/CMakeLists.txt +5 -2
@@ 1,11 1,12 @@
project(service-evtmgr)
message( "${PROJECT_NAME}  ${CMAKE_CURRENT_LIST_DIR}" )

set(SOURCES
        EventManager.cpp
        WorkerEventCommon.cpp
        api/EventManagerServiceAPI.cpp
        api/torch.cpp
        battery/BatteryController.cpp
        battery/BatteryController.hpp
        battery-level-check/BatteryLevelCheck.cpp
        backlight-handler/BacklightHandler.cpp
        battery-brownout-detector/BatteryBrownoutDetector.cpp


@@ 14,7 15,9 @@ set(SOURCES
        vibra/Vibra.cpp
)

add_library(${PROJECT_NAME} STATIC ${SOURCES})
add_library(service-evtmgr STATIC)

target_sources(service-evtmgr PRIVATE ${SOURCES})

target_include_directories(${PROJECT_NAME}
    PUBLIC

M module-services/service-evtmgr/WorkerEventCommon.cpp => module-services/service-evtmgr/WorkerEventCommon.cpp +9 -7
@@ 6,6 6,7 @@
#include "service-evtmgr/Constants.hpp"
#include "service-evtmgr/WorkerEventCommon.hpp"
#include "battery-level-check/BatteryLevelCheck.hpp"
#include "battery/BatteryController.hpp"

#include <Audio/AudioCommon.hpp>
#include <MessageType.hpp>


@@ 45,8 46,8 @@ extern "C"

WorkerEventCommon::WorkerEventCommon(sys::Service *service)
    : sys::Worker(service, stackDepthBytes),
      service(service), batteryCharger{hal::battery::AbstractBatteryCharger::Factory::create(service)},
      keyInput{hal::key_input::AbstractKeyInput::Factory::create()}
      service(service), keyInput{hal::key_input::AbstractKeyInput::Factory::create()},
      batteryController(std::make_shared<sevm::battery::BatteryController>(service))
{}

bool WorkerEventCommon::handleMessage(uint32_t queueID)


@@ 78,7 79,8 @@ bool WorkerEventCommon::handleMessage(uint32_t queueID)
        if (!queue->Dequeue(&notification, 0)) {
            return false;
        }
        batteryCharger->processStateChangeNotification(notification);

        batteryController->handleBatteryNotification(notification);
    }

    if (queueID == static_cast<uint32_t>(WorkerEventQueues::queueChargerDetect)) {


@@ 86,8 88,9 @@ bool WorkerEventCommon::handleMessage(uint32_t queueID)
        if (!queue->Dequeue(&notification, 0)) {
            return false;
        }

        LOG_DEBUG("USB charger type: %d", notification);
        batteryCharger->setChargingCurrentLimit(notification);
        batteryController->handleChargerNotification(notification);
    }

    if (queueID == static_cast<uint32_t>(WorkerEventQueues::queueRTC)) {


@@ 105,7 108,6 @@ bool WorkerEventCommon::handleMessage(uint32_t queueID)
        service->bus.sendUnicast(message, service::name::evt_manager);
    }


    return true;
}



@@ 138,7 140,7 @@ bool WorkerEventCommon::initCommonHardwareComponents()
    keyInput->init(queues[static_cast<int32_t>(WorkerEventQueues::queueKeyboardIRQ)]->GetQueueHandle());
    auto queueBatteryHandle = queues[static_cast<int32_t>(WorkerEventQueues::queueBattery)]->GetQueueHandle();
    auto queueChargerDetect = queues[static_cast<int32_t>(WorkerEventQueues::queueChargerDetect)]->GetQueueHandle();
    batteryCharger->init(queueBatteryHandle, queueChargerDetect);
    batteryController->init(queueBatteryHandle, queueChargerDetect);
    bsp::rtc::init(queues[static_cast<int32_t>(WorkerEventQueues::queueRTC)]->GetQueueHandle());

    time_t timestamp;


@@ 172,7 174,7 @@ bool WorkerEventCommon::deinit(void)
    deinitProductHardware();

    keyInput->deinit();
    batteryCharger->deinit();
    batteryController->deinit();
    battery_level_check::deinit();

    return true;

M module-services/service-evtmgr/battery-brownout-detector/BatteryBrownoutDetector.cpp => module-services/service-evtmgr/battery-brownout-detector/BatteryBrownoutDetector.cpp +14 -11
@@ 2,6 2,9 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BatteryBrownoutDetector.hpp"

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

namespace


@@ 13,14 16,12 @@ namespace
} // namespace

BatteryBrownoutDetector::BatteryBrownoutDetector(sys::Service *service,
                                                 std::function<int()> getMeasurementCallback,
                                                 std::function<void()> positiveResultCallback,
                                                 std::function<void()> negativeResultCallback)
    : parentService(service), getMeasurementCallback(std::move(getMeasurementCallback)),
      positiveResultCallback(std::move(positiveResultCallback)),
      negativeResultCallback(std::move(negativeResultCallback)), detectionOngoing{false}, measurementCount{0},
      measurementTick{sys::TimerFactory::createSingleShotTimer(
          service, measurementTickName, measurementTickTime, [this](sys::Timer &) { checkBrownout(); })}
                                                 std::shared_ptr<hal::battery::AbstractBatteryCharger> charger)
    : parentService(service),
      charger(std::move(charger)), measurementTick{sys::TimerFactory::createSingleShotTimer(
                                       service, measurementTickName, measurementTickTime, [this](sys::Timer &) {
                                           checkBrownout();
                                       })}
{}

void BatteryBrownoutDetector::startDetection()


@@ 36,9 37,12 @@ void BatteryBrownoutDetector::startDetection()

void BatteryBrownoutDetector::checkBrownout()
{
    if (getMeasurementCallback() < brownoutLevelVoltage) {
    if (charger->getBatteryVoltage() < brownoutLevelVoltage) {
        LOG_DEBUG("Battery Brownout detected");
        positiveResultCallback();

        auto messageBrownout = std::make_shared<sevm::BatteryBrownoutMessage>();
        parentService->bus.sendUnicast(std::move(messageBrownout), service::name::system_manager);

        return;
    }



@@ 49,6 53,5 @@ void BatteryBrownoutDetector::checkBrownout()
    else {
        LOG_DEBUG("Battery Brownout detection window finish with negative result");
        detectionOngoing = false;
        negativeResultCallback();
    }
}

M module-services/service-evtmgr/battery-brownout-detector/BatteryBrownoutDetector.hpp => module-services/service-evtmgr/battery-brownout-detector/BatteryBrownoutDetector.hpp +8 -9
@@ 3,9 3,12 @@

#pragma once

#include <hal/battery_charger/AbstractBatteryCharger.hpp>
#include <Service/Service.hpp>
#include <Timers/TimerHandle.hpp>

#include <memory>

namespace sys
{
    class Service;


@@ 14,20 17,16 @@ namespace sys
class BatteryBrownoutDetector
{
  public:
    BatteryBrownoutDetector(sys::Service *service,
                            std::function<int()> getMeasurementCallback,
                            std::function<void()> positiveResultCallback,
                            std::function<void()> negativeResultCallback);
    BatteryBrownoutDetector(sys::Service *service, std::shared_ptr<hal::battery::AbstractBatteryCharger> charger);
    void startDetection();

  private:
    void checkBrownout();

    sys::Service *parentService;
    const std::function<int()> getMeasurementCallback;
    const std::function<void()> positiveResultCallback;
    const std::function<void()> negativeResultCallback;
    bool detectionOngoing;
    unsigned measurementCount;
    std::shared_ptr<hal::battery::AbstractBatteryCharger> charger;

    bool detectionOngoing     = false;
    unsigned measurementCount = 0;
    sys::TimerHandle measurementTick;
};

A module-services/service-evtmgr/battery/BatteryController.cpp => module-services/service-evtmgr/battery/BatteryController.cpp +49 -0
@@ 0,0 1,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);
}

A module-services/service-evtmgr/battery/BatteryController.hpp => module-services/service-evtmgr/battery/BatteryController.hpp +36 -0
@@ 0,0 1,36 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <hal/battery_charger/BatteryCharger.hpp>
#include <battery-brownout-detector/BatteryBrownoutDetector.hpp>
#include <Service/Service.hpp>
#include <queue.hpp>

#include <memory>

#include <cstdint>

namespace sevm::battery
{
    class BatteryController : public hal::battery::AbstractBatteryCharger::BatteryChargerEvents,
                              public std::enable_shared_from_this<BatteryController>
    {
      public:
        explicit BatteryController(sys::Service *service);

        void onBrownout() final;
        void onStatusChanged() final;

        void init(xQueueHandle queueBatteryHandle, xQueueHandle queueChargerDetect);
        void deinit();
        void handleChargerNotification(std::uint8_t notification);
        void handleBatteryNotification(std::uint8_t notification);

      private:
        sys::Service *service = nullptr;
        std::shared_ptr<hal::battery::AbstractBatteryCharger> charger;
        BatteryBrownoutDetector brownoutDetector;
    };
}; // namespace sevm::battery

M module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp => module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp +2 -1
@@ 12,6 12,7 @@
#include <Service/CpuSentinel.hpp>
#include <hal/battery_charger/AbstractBatteryCharger.hpp>
#include <hal/key_input/AbstractKeyInput.hpp>
#include <battery/BatteryController.hpp>

#include <cstdint>
#include <list>


@@ 80,8 81,8 @@ class WorkerEventCommon : public sys::Worker
    bsp::KeyEvents lastState  = bsp::KeyEvents::Released;
    bsp::KeyCodes lastPressed = static_cast<bsp::KeyCodes>(0);
    std::shared_ptr<sys::CpuSentinel> cpuSentinel;
    std::shared_ptr<hal::battery::AbstractBatteryCharger> batteryCharger;
    std::shared_ptr<hal::key_input::AbstractKeyInput> keyInput;
    std::shared_ptr<sevm::battery::BatteryController> batteryController;

  public:
    explicit WorkerEventCommon(sys::Service *service);

M module-vfs/CMakeLists.txt => module-vfs/CMakeLists.txt +3 -2
@@ 2,6 2,8 @@ add_library(module-vfs STATIC)

module_is_test_entity()

add_subdirectory(paths)

target_sources(module-vfs
    PRIVATE
        $<$<STREQUAL:${PROJECT_TARGET},TARGET_RT1051>:


@@ 39,7 41,6 @@ target_sources(module-vfs
        src/purefs/blkdev/disk_manager.cpp
        src/purefs/blkdev/disk.cpp
        src/purefs/blkdev/partition_parser.cpp
        src/purefs/filesystem_paths.cpp
        src/purefs/fs/filesystem_cwd.cpp
        src/purefs/fs/filesystem_operations.cpp
        src/purefs/fs/filesystem_syscalls.cpp


@@ 54,7 55,6 @@ target_sources(module-vfs
        include/user/purefs/blkdev/disk_manager.hpp
        include/user/purefs/blkdev/disk.hpp
        include/user/purefs/blkdev/partition.hpp
        include/user/purefs/filesystem_paths.hpp
        include/user/purefs/fs/directory_handle.hpp
        include/user/purefs/fs/file_handle.hpp
        include/user/purefs/fs/filesystem_operations.hpp


@@ 99,6 99,7 @@ target_link_libraries(module-vfs
        module-os
        module-utils
    PUBLIC 
        purefs-paths
        module-sys
)


A module-vfs/paths/CMakeLists.txt => module-vfs/paths/CMakeLists.txt +12 -0
@@ 0,0 1,12 @@
add_library(purefs-paths STATIC)

target_sources(purefs-paths
    PRIVATE
        filesystem_paths.cpp
        include/purefs/filesystem_paths.hpp
)

target_include_directories(purefs-paths
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
)

R module-vfs/src/purefs/filesystem_paths.cpp => module-vfs/paths/filesystem_paths.cpp +0 -0
R module-vfs/include/user/purefs/filesystem_paths.hpp => module-vfs/paths/include/purefs/filesystem_paths.hpp +0 -0
M products/BellHybrid/alarms/src/actions/PlayToneAction.cpp => products/BellHybrid/alarms/src/actions/PlayToneAction.cpp +1 -1
@@ 2,7 2,7 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PlayToneAction.hpp"
#include <module-vfs/include/user/purefs/filesystem_paths.hpp>
#include <purefs/filesystem_paths.hpp>
#include <service-audio/AudioServiceAPI.hpp>
#include <service-time/ServiceTime.hpp>
#include <db/SystemSettings.hpp>