~aleteoryx/muditaos

4bd7b1acf44a1d6658bdd46554c4fd6249d4076b — Maciej-Mudita 2 years ago 157cea8
[MOS-275] Fix alarm rings on the low battery screen

When we had a critical battery level and the alarm clock rang,
it was impossible to turn it off.
30 files changed, 200 insertions(+), 76 deletions(-)

M module-services/service-evtmgr/EventManager.cpp
M module-services/service-evtmgr/WorkerEventCommon.cpp
M module-services/service-evtmgr/battery/BatteryController.cpp
M module-services/service-evtmgr/battery/BatteryController.hpp
M module-services/service-evtmgr/battery/BatteryState.cpp
M module-services/service-evtmgr/battery/BatteryState.hpp
M module-services/service-evtmgr/service-evtmgr/BatteryMessages.hpp
M module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp
M module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp
A module-services/service-evtmgr/service-evtmgr/include/EventManagerParams.hpp
M module-services/service-time/AlarmMessageHandler.cpp
M module-services/service-time/AlarmMessageHandler.hpp
M module-services/service-time/AlarmOperations.cpp
M module-services/service-time/AlarmOperations.hpp
M module-services/service-time/AlarmServiceAPI.cpp
M module-services/service-time/ServiceTime.cpp
M module-services/service-time/include/service-time/AlarmMessage.hpp
M module-services/service-time/include/service-time/AlarmServiceAPI.hpp
M module-sys/SystemManager/SystemManagerCommon.cpp
M module-utils/utility/Units.hpp
M products/BellHybrid/services/evtmgr/CMakeLists.txt
M products/BellHybrid/services/evtmgr/EventManager.cpp
A products/BellHybrid/services/evtmgr/include/evtmgr/battery/Thresholds.hpp
M products/PurePhone/services/evtmgr/CMakeLists.txt
M products/PurePhone/services/evtmgr/include/evtmgr/EventManager.hpp
A products/PurePhone/services/evtmgr/include/evtmgr/battery/Thresholds.hpp
M products/PurePhone/services/time/AlarmOperations.cpp
M products/PurePhone/services/time/include/time/AlarmOperations.hpp
M products/PurePhone/sys/SystemManager.cpp
M pure_changelog.md
M module-services/service-evtmgr/EventManager.cpp => module-services/service-evtmgr/EventManager.cpp +6 -4
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-evtmgr/BatteryMessages.hpp"


@@ 49,9 49,11 @@
#define debug_input_events(...)
#endif

EventManagerCommon::EventManagerCommon(LogDumpFunction logDumpFunction, const std::string &name)
EventManagerCommon::EventManagerCommon(LogDumpFunction logDumpFunction,
                                       EventManagerParams params,
                                       const std::string &name)
    : sys::Service(name, "", stackDepth), logDumpFunction(std::move(logDumpFunction)),
      settings(std::make_shared<settings::Settings>())
      settings(std::make_shared<settings::Settings>()), eventManagerParams(params)
{
    LOG_INFO("[%s] Initializing", name.c_str());
    alarmTimestamp = 0;


@@ 180,7 182,7 @@ sys::ReturnCodes EventManagerCommon::InitHandler()
    initProductEvents();

    EventWorker = createEventWorker();
    EventWorker->init(settings);
    EventWorker->init(settings, eventManagerParams);
    EventWorker->run();

    cpuSentinel                  = std::make_shared<sys::TimedCpuSentinel>(service::name::evt_manager, this);

M module-services/service-evtmgr/WorkerEventCommon.cpp => module-services/service-evtmgr/WorkerEventCommon.cpp +5 -5
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-evtmgr/EVMessages.hpp"


@@ 107,12 107,12 @@ bool WorkerEventCommon::initEventQueues()
    return Worker::init(queuesList);
}

bool WorkerEventCommon::initCommonHardwareComponents()
bool WorkerEventCommon::initCommonHardwareComponents(EventManagerParams params)
{
    keyInput->init(queues[static_cast<int32_t>(WorkerEventQueues::queueKeyboardIRQ)]->GetQueueHandle());
    auto queueBatteryHandle = queues[static_cast<int32_t>(WorkerEventQueues::queueBatteryController)]->GetQueueHandle();

    batteryController = std::make_shared<sevm::battery::BatteryController>(service, queueBatteryHandle);
    batteryController = std::make_shared<sevm::battery::BatteryController>(service, queueBatteryHandle, params.battery);
    bsp::rtc::init(queues[static_cast<int32_t>(WorkerEventQueues::queueRTC)]->GetQueueHandle());

    time_t timestamp;


@@ 131,10 131,10 @@ bool WorkerEventCommon::initCommonHardwareComponents()
    return true;
}

void WorkerEventCommon::init(std::shared_ptr<settings::Settings> settings)
void WorkerEventCommon::init(std::shared_ptr<settings::Settings> settings, EventManagerParams params)
{
    initEventQueues();
    initCommonHardwareComponents();
    initCommonHardwareComponents(params);
}

bool WorkerEventCommon::deinit(void)

M module-services/service-evtmgr/battery/BatteryController.cpp => module-services/service-evtmgr/battery/BatteryController.cpp +11 -6
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BatteryController.hpp"


@@ 75,14 75,19 @@ namespace
    }
} // namespace

BatteryController::BatteryController(sys::Service *service, xQueueHandle notificationChannel)
BatteryController::BatteryController(sys::Service *service,
                                     xQueueHandle notificationChannel,
                                     BatteryState::Thresholds thresholds)
    : service{service}, charger{hal::battery::AbstractBatteryCharger::Factory::create(notificationChannel)},
      brownoutDetector(service, *charger),
      batteryState{service, [this](const auto state) {
      batteryState{service,
                   [this](const auto state) {
                       Store::Battery::modify().levelState = transformBatteryState(state);
                       auto stateChangeMessage             = std::make_shared<sevm::BatteryStateChangeMessage>();
                       this->service->bus.sendUnicast(std::move(stateChangeMessage), service::name::system_manager);
                   }}
                       auto stateChangeMessage             = std::make_shared<sevm::BatteryStateChangeMessage>(state);
                       this->service->bus.sendMulticast(std::move(stateChangeMessage),
                                                        sys::BusChannel::ServiceEvtmgrNotifications);
                   },
                   thresholds}
{
    updateSoC();
    Store::Battery::modify().state = transformChargingState(charger->getChargingStatus());

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

#pragma once


@@ 20,7 20,7 @@ namespace sevm::battery
      public:
        using Events          = hal::battery::AbstractBatteryCharger::Events;
        using ChargerPresence = hal::battery::AbstractBatteryCharger::ChargerPresence;
        explicit BatteryController(sys::Service *service, xQueueHandle notificationChannel);
        BatteryController(sys::Service *service, xQueueHandle notificationChannel, BatteryState::Thresholds thresholds);

        void poll();


M module-services/service-evtmgr/battery/BatteryState.cpp => module-services/service-evtmgr/battery/BatteryState.cpp +7 -8
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "BatteryState.hpp"


@@ 128,22 128,21 @@ class BatteryState::Pimpl
    friend BatteryState;

  public:
    explicit Pimpl(NotifyStateChangedCallback notifyCallback) : notifyCallback{std::move(notifyCallback)}
    Pimpl(NotifyStateChangedCallback notifyCallback, Thresholds thresholds)
        : thresholds(thresholds), notifyCallback{std::move(notifyCallback)}
    {}

  private:
    const Thresholds thresholds;
    NotifyStateChangedCallback notifyCallback;
    sml::sm<StateMachine, NotifyStateChangedCallback> sm{notifyCallback};

    static constexpr auto criticalThreshold = 10; // %
    static constexpr auto shutdownThreshold = 1;  // %
};

void BatteryState::check(const ChargingState state, const float soc)
{
    pimpl->sm.process_event(events::Check{soc, state, Pimpl::criticalThreshold, Pimpl::shutdownThreshold});
    pimpl->sm.process_event(events::Check{soc, state, pimpl->thresholds.critical, pimpl->thresholds.shutdown});
}

BatteryState::BatteryState(sys::Service *service, NotifyStateChangedCallback notifyCallback)
    : pimpl{std::make_shared<Pimpl>(notifyCallback)}
BatteryState::BatteryState(sys::Service *service, NotifyStateChangedCallback notifyCallback, Thresholds thresholds)
    : pimpl{std::make_shared<Pimpl>(notifyCallback, thresholds)}
{}

M module-services/service-evtmgr/battery/BatteryState.hpp => module-services/service-evtmgr/battery/BatteryState.hpp +9 -2
@@ 1,10 1,11 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <functional>
#include <Units.hpp>

namespace sys
{


@@ 30,9 31,15 @@ class BatteryState
        CriticalNotCharging
    };

    struct Thresholds
    {
        units::Percent critical;
        units::Percent shutdown;
    };

    using NotifyStateChangedCallback = std::function<void(State)>;

    BatteryState(sys::Service *service, NotifyStateChangedCallback notifyCallback);
    BatteryState(sys::Service *service, NotifyStateChangedCallback notifyCallback, Thresholds thresholds);

    void check(ChargingState state, float soc);


M module-services/service-evtmgr/service-evtmgr/BatteryMessages.hpp => module-services/service-evtmgr/service-evtmgr/BatteryMessages.hpp +12 -10
@@ 1,27 1,29 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Service/Message.hpp"

#include <module-bsp/bsp/torch/torch.hpp>
#include <battery/BatteryState.hpp>

namespace sevm
{
    class BatteryStatusChangeMessage : public sys::DataMessage
    {};

    class BatterySetCriticalLevel : public sys::DataMessage
    class BatteryStateChangeMessage : public sys::DataMessage
    {
      public:
        BatterySetCriticalLevel(std::uint8_t level) : criticalLevel(level)
        {}
        const unsigned int criticalLevel = 0;
    };
        explicit BatteryStateChangeMessage(BatteryState::State state) : state{state} {};

    class BatteryStateChangeMessage : public sys::DataMessage
    {};
        [[nodiscard]] BatteryState::State getState() const
        {
            return state;
        }

      private:
        BatteryState::State state{BatteryState::State::Normal};
    };

    class BatteryBrownoutMessage : public sys::DataMessage
    {};

M module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp => module-services/service-evtmgr/service-evtmgr/EventManagerCommon.hpp +6 -2
@@ 1,9 1,10 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Constants.hpp"
#include "EventManagerParams.hpp"

#include <hal/key_input/RawKey.hpp>
#include <MessageType.hpp>


@@ 28,7 29,9 @@ class EventManagerCommon : public sys::Service
  public:
    using LogDumpFunction = std::function<int()>;

    explicit EventManagerCommon(LogDumpFunction logDumpFunction, const std::string &name = service::name::evt_manager);
    EventManagerCommon(LogDumpFunction logDumpFunction,
                       EventManagerParams params,
                       const std::string &name = service::name::evt_manager);
    ~EventManagerCommon() override;

    sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override;


@@ 79,4 82,5 @@ class EventManagerCommon : public sys::Service
    uint32_t alarmTimestamp;
    // ID of alarm waiting to trigger
    uint32_t alarmID;
    const EventManagerParams eventManagerParams;
};

M module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp => module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp +4 -3
@@ 1,9 1,10 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "EventManagerCommon.hpp"
#include "EventManagerParams.hpp"

#include <Service/Message.hpp>
#include <Service/Service.hpp>


@@ 67,7 68,7 @@ class WorkerEventCommon : public sys::Worker
     */
    void updateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency);
    bool initEventQueues();
    bool initCommonHardwareComponents();
    bool initCommonHardwareComponents(EventManagerParams params);
    void sendKeyUnicast(RawKey const &key);

    /**


@@ 83,7 84,7 @@ class WorkerEventCommon : public sys::Worker
  public:
    explicit WorkerEventCommon(sys::Service *service);

    void init(std::shared_ptr<settings::Settings> settings);
    void init(std::shared_ptr<settings::Settings> settings, EventManagerParams params);
    virtual void deinitProductHardware();
    virtual bool deinit() override;


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

#pragma once

#include <battery/BatteryController.hpp>

struct EventManagerParams
{
    BatteryState::Thresholds battery;
};

M module-services/service-time/AlarmMessageHandler.cpp => module-services/service-time/AlarmMessageHandler.cpp +15 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "AlarmMessageHandler.hpp"


@@ 172,6 172,20 @@ namespace alarms
            });
    }

    auto AlarmMessageHandler::handleBatteryStateChange(sevm::BatteryStateChangeMessage *request) -> void
    {
        switch (request->getState()) {
        case BatteryState::State::Normal:
            alarmOperations->handleNormalBatteryLevel();
            break;
        case BatteryState::State::Shutdown:
        case BatteryState::State::CriticalCharging:
        case BatteryState::State::CriticalNotCharging:
            alarmOperations->handleCriticalBatteryLevel();
            break;
        }
    }

    template <class RequestType, class ResponseType, class CallbackParamType>
    auto AlarmMessageHandler::handleWithCallback(
        RequestType *request,

M module-services/service-time/AlarmMessageHandler.hpp => module-services/service-time/AlarmMessageHandler.hpp +3 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 6,7 6,7 @@
#include "AlarmOperations.hpp"

#include <service-time/AlarmMessage.hpp>

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

namespace stm


@@ 47,6 47,7 @@ namespace alarms
        auto handleToggleAll(AlarmToggleAllRequestMessage *request) -> std::shared_ptr<AlarmToggleAllResponseMessage>;
        auto handleGetSnoozedAlarms(GetSnoozedAlarmsRequestMessage *request)
            -> std::shared_ptr<GetSnoozedAlarmsResponseMessage>;
        auto handleBatteryStateChange(sevm::BatteryStateChangeMessage *request) -> void;

      private:
        stm::ServiceTime *service = nullptr;

M module-services/service-time/AlarmOperations.cpp => module-services/service-time/AlarmOperations.cpp +34 -4
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "AlarmOperations.hpp"


@@ 345,9 345,9 @@ namespace alarms
    auto AlarmOperationsCommon::processNextEventsQueue(const TimePoint now) -> void
    {
        if (nextSingleEvents.front()->startDate <= now) {
            ongoingSingleEvents.insert(ongoingSingleEvents.end(),
                                       std::make_move_iterator(nextSingleEvents.begin()),
                                       std::make_move_iterator(nextSingleEvents.end()));
            if (!isCriticalBatteryLevel) {
                triggerAlarm();
            }
            nextSingleEvents.clear();
            updateEventsCache(now);
        }


@@ 373,6 373,24 @@ namespace alarms
        handleActiveAlarmsCountChange();
    }

    auto AlarmOperationsCommon::stopAllRingingAlarms() -> void
    {
        if (!ongoingSingleEvents.empty()) {
            for (auto &event : ongoingSingleEvents) {
                switchAlarmExecution(*event, false);
            }
            ongoingSingleEvents.clear();
            handleActiveAlarmsCountChange();
        }
    }

    void AlarmOperationsCommon::triggerAlarm()
    {
        ongoingSingleEvents.insert(ongoingSingleEvents.end(),
                                   std::make_move_iterator(nextSingleEvents.begin()),
                                   std::make_move_iterator(nextSingleEvents.end()));
    }

    void AlarmOperationsCommon::toggleAll(bool toggle, OnToggleAll callback)
    {
        OnToggleAll repoCallback = [&, callback](bool success) mutable {


@@ 433,6 451,18 @@ namespace alarms
        callback(std::move(snoozedEvents));
    }

    void AlarmOperationsCommon::handleCriticalBatteryLevel()
    {
        isCriticalBatteryLevel = true;
        stopAllRingingAlarms();
        stopAllSnoozedAlarms();
    }

    void AlarmOperationsCommon::handleNormalBatteryLevel()
    {
        isCriticalBatteryLevel = false;
    }

    auto findSingleEventById(std::vector<std::unique_ptr<SingleEventRecord>> &events, const std::uint32_t id)
        -> std::vector<std::unique_ptr<SingleEventRecord>>::iterator
    {

M module-services/service-time/AlarmOperations.hpp => module-services/service-time/AlarmOperations.hpp +8 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 64,6 64,8 @@ namespace alarms
        virtual void addActiveAlarmCountChangeCallback(OnActiveAlarmCountChange)                             = 0;
        virtual void toggleAll(bool toggle, OnToggleAll callback)                                            = 0;
        virtual void getSnoozedAlarms(OnGetSnoozedAlarms callback)                                           = 0;
        virtual void handleCriticalBatteryLevel()                                                            = 0;
        virtual void handleNormalBatteryLevel()                                                              = 0;
    };

    class IAlarmOperationsFactory


@@ 108,6 110,8 @@ namespace alarms
        void addActiveAlarmCountChangeCallback(OnActiveAlarmCountChange callback) override;
        void toggleAll(bool toggle, OnToggleAll callback) override;
        void getSnoozedAlarms(OnGetSnoozedAlarms callback) override;
        void handleCriticalBatteryLevel() override;
        void handleNormalBatteryLevel() override;

      protected:
        std::unique_ptr<AbstractAlarmEventsRepository> alarmEventsRepo;


@@ 124,6 128,7 @@ namespace alarms
                                      bool newStateOn);

      private:
        bool isCriticalBatteryLevel{false};
        GetCurrentTime getCurrentTimeCallback;
        OnSnoozedAlarmsCountChange onSnoozedAlarmsCountChangeCallback = nullptr;
        OnActiveAlarmCountChange onActiveAlarmCountChangeCallback     = nullptr;


@@ 144,6 149,8 @@ namespace alarms
        void processOngoingEvents();
        void processNextEventsQueue(const TimePoint now);
        void processSnoozedEventsQueue(const TimePoint now);
        void stopAllRingingAlarms();
        void triggerAlarm();
        virtual void onAlarmTurnedOff(const std::shared_ptr<AlarmEventRecord> &event, alarms::AlarmType alarmType);

        TimePoint getCurrentTime();

M module-services/service-time/AlarmServiceAPI.cpp => module-services/service-time/AlarmServiceAPI.cpp +1 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Constants.hpp"

M module-services/service-time/ServiceTime.cpp => module-services/service-time/ServiceTime.cpp +6 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ServiceTime.hpp"


@@ 185,6 185,11 @@ namespace stm
            auto message = static_cast<alarms::GetSnoozedAlarmsRequestMessage *>(request);
            return alarmMessageHandler->handleGetSnoozedAlarms(message);
        });
        connect(typeid(sevm::BatteryStateChangeMessage), [&](sys::Message *request) -> sys::MessagePointer {
            auto message = static_cast<sevm::BatteryStateChangeMessage *>(request);
            alarmMessageHandler->handleBatteryStateChange(message);
            return std::make_shared<sys::ResponseMessage>();
        });
    }

    auto ServiceTime::handleSetAutomaticDateAndTimeRequest(sys::Message *request)

M module-services/service-time/include/service-time/AlarmMessage.hpp => module-services/service-time/include/service-time/AlarmMessage.hpp +1 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

M module-services/service-time/include/service-time/AlarmServiceAPI.hpp => module-services/service-time/include/service-time/AlarmServiceAPI.hpp +1 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

M module-sys/SystemManager/SystemManagerCommon.cpp => module-sys/SystemManager/SystemManagerCommon.cpp +10 -9
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <SystemManager/SystemManagerCommon.hpp>


@@ 112,7 112,7 @@ namespace sys
        : Service(service::name::system_manager, "", systemManagerStack), systemServiceCreators{std::move(creators)}
    {
        // Specify list of channels which System Manager is registered to
        bus.channels            = {BusChannel::SystemManagerRequests};
        bus.channels            = {BusChannel::SystemManagerRequests, BusChannel::ServiceEvtmgrNotifications};
        lowBatteryShutdownDelay = sys::TimerFactory::createPeriodicTimer(
            this, "lowBatteryShutdownDelay", lowBatteryShutdownDelayTime, [this](sys::Timer &) {
                CloseSystemHandler(CloseReason::LowBattery);


@@ 510,22 510,23 @@ namespace sys

    void SystemManagerCommon::postStartRoutine()
    {
        connect(sevm::BatteryStateChangeMessage(), [&](Message *) {
            switch (Store::Battery::get().levelState) {
            case Store::Battery::LevelState::Normal:
        connect(typeid(sevm::BatteryStateChangeMessage), [this](sys::Message *message) -> sys::MessagePointer {
            auto msg = static_cast<sevm::BatteryStateChangeMessage *>(message);
            switch (msg->getState()) {
            case BatteryState::State::Normal:
                batteryNormalLevelAction();
                break;
            case Store::Battery::LevelState::Shutdown:
            case BatteryState::State::Shutdown:
                batteryShutdownLevelAction();
                break;
            case Store::Battery::LevelState::CriticalCharging:
            case BatteryState::State::CriticalCharging:
                batteryCriticalLevelAction(true);
                break;
            case Store::Battery::LevelState::CriticalNotCharging:
            case BatteryState::State::CriticalNotCharging:
                batteryCriticalLevelAction(false);
                break;
            }
            return MessageNone{};
            return sys::MessageNone{};
        });
    }


M module-utils/utility/Units.hpp => module-utils/utility/Units.hpp +2 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 10,4 10,5 @@ namespace units
    using Voltage     = std::uint32_t; /// mV
    using SOC         = std::uint8_t;  /// 0-100%
    using Temperature = float;
    using Percent     = float;
} // namespace units

M products/BellHybrid/services/evtmgr/CMakeLists.txt => products/BellHybrid/services/evtmgr/CMakeLists.txt +1 -0
@@ 30,6 30,7 @@ target_sources(evtmgr
        include/evtmgr/api/TemperatureApi.hpp
        include/evtmgr/backlight-handler/BacklightHandler.hpp
        include/evtmgr/user-activity-handler/UserActivityHandler.hpp
        include/evtmgr/battery/Thresholds.hpp
)

target_include_directories(evtmgr

M products/BellHybrid/services/evtmgr/EventManager.cpp => products/BellHybrid/services/evtmgr/EventManager.cpp +6 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "WorkerEvent.hpp"


@@ 14,6 14,7 @@
#include <appmgr/messages/PowerOffPopupRequestParams.hpp>
#include <appmgr/messages/RebootPopupRequestParams.hpp>
#include <evtmgr/EventManager.hpp>
#include <evtmgr/battery/Thresholds.hpp>
#include <service-appmgr/Controller.hpp>
#include <hal/temperature_source/TemperatureSource.hpp>
#include <system/Constants.hpp>


@@ 38,8 39,10 @@ namespace
}

EventManager::EventManager(LogDumpFunction logDumpFunction, const std::string &name)
    : EventManagerCommon(logDumpFunction, name), backlightHandler(settings, this),
      userActivityHandler(std::make_shared<sys::CpuSentinel>(name, this), this)
    : EventManagerCommon(logDumpFunction,
                         {.battery{.critical = constants::criticalThreshold, .shutdown = constants::shutdownThreshold}},
                         name),
      backlightHandler(settings, this), userActivityHandler(std::make_shared<sys::CpuSentinel>(name, this), this)
{
    buildKeySequences();


A products/BellHybrid/services/evtmgr/include/evtmgr/battery/Thresholds.hpp => products/BellHybrid/services/evtmgr/include/evtmgr/battery/Thresholds.hpp +12 -0
@@ 0,0 1,12 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <Units.hpp>

namespace constants
{
    static constexpr units::Percent criticalThreshold = 1;
    static constexpr units::Percent shutdownThreshold = 1;
} // namespace constants

M products/PurePhone/services/evtmgr/CMakeLists.txt => products/PurePhone/services/evtmgr/CMakeLists.txt +1 -0
@@ 11,6 11,7 @@ target_sources(evtmgr
    PUBLIC
        include/evtmgr/EVMessages.hpp
        include/evtmgr/EventManager.hpp
        include/evtmgr/battery/Thresholds.hpp
)

target_include_directories(evtmgr

M products/PurePhone/services/evtmgr/include/evtmgr/EventManager.hpp => products/PurePhone/services/evtmgr/include/evtmgr/EventManager.hpp +8 -4
@@ 1,10 1,10 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <service-evtmgr/EventManagerCommon.hpp>

#include <evtmgr/battery/Thresholds.hpp>
#include "BacklightHandler.hpp"
#include "UserActivityHandler.hpp"
#include <bsp/vibrator/vibrator.hpp>


@@ 15,8 15,12 @@ class EventManager : public EventManagerCommon
  public:
    explicit EventManager(LogDumpFunction logDumpFunction = nullptr,
                          const std::string &name         = service::name::evt_manager)
        : EventManagerCommon(logDumpFunction, name), vibrator(std::make_unique<vibra_handle::Vibra>(this)),
          backlightHandler(settings, this), userActivityHandler(std::make_shared<sys::CpuSentinel>(name, this), this)
        : EventManagerCommon(
              logDumpFunction,
              {.battery{.critical = constants::criticalThreshold, .shutdown = constants::shutdownThreshold}},
              name),
          vibrator(std::make_unique<vibra_handle::Vibra>(this)), backlightHandler(settings, this),
          userActivityHandler(std::make_shared<sys::CpuSentinel>(name, this), this)
    {}

  private:

A products/PurePhone/services/evtmgr/include/evtmgr/battery/Thresholds.hpp => products/PurePhone/services/evtmgr/include/evtmgr/battery/Thresholds.hpp +12 -0
@@ 0,0 1,12 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <Units.hpp>

namespace constants
{
    static constexpr units::Percent criticalThreshold = 10;
    static constexpr units::Percent shutdownThreshold = 1;
} // namespace constants

M products/PurePhone/services/time/AlarmOperations.cpp => products/PurePhone/services/time/AlarmOperations.cpp +2 -2
@@ 1,7 1,7 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <time/AlarmOperations.hpp>
#include "include/time/AlarmOperations.hpp"

#include <PureAlarmHandler.hpp>


M products/PurePhone/services/time/include/time/AlarmOperations.hpp => products/PurePhone/services/time/include/time/AlarmOperations.hpp +2 -2
@@ 1,9 1,9 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <AlarmOperations.hpp>
#include <service-time/AlarmOperations.hpp>

namespace alarms
{

M products/PurePhone/sys/SystemManager.cpp => products/PurePhone/sys/SystemManager.cpp +1 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <sys/SystemManager.hpp>

M pure_changelog.md => pure_changelog.md +1 -0
@@ 32,6 32,7 @@
* Fixed no sound when Bluetooth audio device connected/disconnected during call
* Fixed full filesystem path displayed in music player for invalid files instead of just filename
* Fixed problem with track info not being displayed correctly
* Fixed alarm rings on the low battery screen

### Added