From 323786c4d2cd22d91d1a966a231b866c75146b8b Mon Sep 17 00:00:00 2001 From: Wojtek Rzepecki Date: Tue, 9 Feb 2021 15:14:21 +0100 Subject: [PATCH] [EGD-4797] Battery bar as widget Battery bar now is present as a separate widget in top bar. Additionally refactored passing battery status. --- module-apps/Application.cpp | 36 +------ module-apps/Application.hpp | 3 +- module-apps/windows/AppWindow.cpp | 13 +-- module-apps/windows/AppWindow.hpp | 4 +- module-gui/gui/widgets/CMakeLists.txt | 1 + module-gui/gui/widgets/TopBar.cpp | 94 +------------------ module-gui/gui/widgets/TopBar.hpp | 12 +-- .../gui/widgets/TopBar/BatteryWidget.cpp | 67 +++++++++++++ .../gui/widgets/TopBar/BatteryWidget.hpp | 20 ++++ .../service-evtmgr/EventManager.cpp | 44 ++++----- .../service-evtmgr/WorkerEvent.cpp | 12 +-- .../doc/battery_status_notification.md | 4 + .../doc/battery_status_notification.puml | 24 +++++ .../doc/battery_status_notification.svg | 34 +++++++ .../service-evtmgr/BatteryMessages.hpp | 22 +---- module-sys/SystemManager/SystemManager.cpp | 12 +-- source/MessageType.hpp | 3 - 17 files changed, 199 insertions(+), 206 deletions(-) create mode 100644 module-gui/gui/widgets/TopBar/BatteryWidget.cpp create mode 100644 module-gui/gui/widgets/TopBar/BatteryWidget.hpp create mode 100644 module-services/service-evtmgr/doc/battery_status_notification.md create mode 100644 module-services/service-evtmgr/doc/battery_status_notification.puml create mode 100644 module-services/service-evtmgr/doc/battery_status_notification.svg diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index 871b30320bf9a1b0d7535446aa7a17a79a295973..cfbbd07a65c809b686f9e823bfaf935a947147b4 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -84,6 +84,8 @@ namespace app connect(typeid(AppRefreshMessage), [this](sys::Message *msg) -> sys::MessagePointer { return handleAppRefresh(msg); }); + + connect(sevm::BatteryStatusChangeMessage(), [&](sys::Message *) { return handleBatteryStatusChange(); }); } Application::~Application() noexcept @@ -129,12 +131,7 @@ namespace app // send drawing commands only when if application is in active and visible. if (state == State::ACTIVE_FORGROUND) { auto window = getCurrentWindow(); - if (Store::Battery::get().state == Store::Battery::State::Charging) { - window->updateBatteryCharger(true); - } - else { - window->updateBatteryLevel(Store::Battery::get().level); - } + window->updateBatteryStatus(); window->setSIM(); window->updateSignalStrength(); window->updateNetworkAccessTechnology(); @@ -216,12 +213,6 @@ namespace app else if (msgl->messageType == MessageType::KBDKeyEvent) { return handleKBDKeyEvent(msgl); } - else if (msgl->messageType == MessageType::EVMBatteryLevel) { - return handleBatteryLevel(msgl); - } - else if (msgl->messageType == MessageType::EVMChargerPlugged) { - return handleChargerPlugged(msgl); - } else if (msgl->messageType == MessageType::EVMMinuteUpdated) { return handleMinuteUpdated(msgl); } @@ -299,31 +290,14 @@ namespace app return msgHandled(); } - sys::MessagePointer Application::handleBatteryLevel(sys::Message *msgl) + sys::MessagePointer Application::handleBatteryStatusChange() { - auto msg = static_cast(msgl); - LOG_INFO("Battery level: %d", msg->levelPercents); - - if (getCurrentWindow()->updateBatteryLevel(msg->levelPercents)) { + if (getCurrentWindow()->updateBatteryStatus()) { refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); } return msgHandled(); } - sys::MessagePointer Application::handleChargerPlugged(sys::Message *msgl) - { - auto *msg = static_cast(msgl); - if (msg->plugged == true) { - LOG_INFO("Charger connected"); - } - else { - LOG_INFO("Charger disconnected"); - } - getCurrentWindow()->updateBatteryCharger(msg->plugged); - refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); - return msgHandled(); - } - sys::MessagePointer Application::handleMinuteUpdated(sys::Message *msgl) { auto *msg = static_cast(msgl); diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 68cc6fa245d743cc11f2583b82dfaef423668cc0..8ad83dd28d2236f8cbafdff5dff10f07ec5d3026 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -167,8 +167,7 @@ namespace app sys::MessagePointer handleNetworkAccessTechnologyUpdate(sys::Message *msgl); sys::MessagePointer handleInputEvent(sys::Message *msgl); sys::MessagePointer handleKBDKeyEvent(sys::Message *msgl); - sys::MessagePointer handleBatteryLevel(sys::Message *msgl); - sys::MessagePointer handleChargerPlugged(sys::Message *msgl); + sys::MessagePointer handleBatteryStatusChange(); sys::MessagePointer handleMinuteUpdated(sys::Message *msgl); sys::MessagePointer handleAction(sys::Message *msgl); sys::MessagePointer handleApplicationSwitch(sys::Message *msgl); diff --git a/module-apps/windows/AppWindow.cpp b/module-apps/windows/AppWindow.cpp index 829153477d3400a3b245c7f7e21f0f03bd5f7732..286b03af009ce6beda112240c3c84122ef1ccbd4 100644 --- a/module-apps/windows/AppWindow.cpp +++ b/module-apps/windows/AppWindow.cpp @@ -73,19 +73,10 @@ namespace gui return true; } - bool AppWindow::updateBatteryCharger(bool charging) + bool AppWindow::updateBatteryStatus() { - topBar->updateBattery(charging); - return true; - } - - // updates battery level in the window - bool AppWindow::updateBatteryLevel(uint32_t percentage) - { - // get old value of battery level, calcualte new level and comapre both - // if they are different make a change and return true, otherwise return false; if (topBar != nullptr) { - return topBar->updateBattery(percentage); + return topBar->updateBattery(); } return false; } diff --git a/module-apps/windows/AppWindow.hpp b/module-apps/windows/AppWindow.hpp index 15187e473ffd5a43aa5c60570b5cdea80f45c754..8f726351e2f92f97ed61e6b03602bd9c9961bd1b 100644 --- a/module-apps/windows/AppWindow.hpp +++ b/module-apps/windows/AppWindow.hpp @@ -62,11 +62,9 @@ namespace gui virtual bool onDatabaseMessage(sys::Message *msg); - bool updateBatteryCharger(bool charging); bool setSIM(); // updates battery level in the window - bool updateBatteryLevel(uint32_t percentage); - // updates battery level in the window + bool updateBatteryStatus(); bool updateSignalStrength(); bool updateNetworkAccessTechnology(); virtual bool updateTime(const UTF8 &timeStr); diff --git a/module-gui/gui/widgets/CMakeLists.txt b/module-gui/gui/widgets/CMakeLists.txt index e9fe59e6de6ba6d10f2d099099756fd8a8de1419..8b7381c0625e15a5a3a20e5e96e864e5391fc966 100644 --- a/module-gui/gui/widgets/CMakeLists.txt +++ b/module-gui/gui/widgets/CMakeLists.txt @@ -22,6 +22,7 @@ target_sources( ${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/BoxLayoutSizeStore.cpp" "${CMAKE_CURRENT_LIST_DIR}/TopBar.cpp" "${CMAKE_CURRENT_LIST_DIR}/TopBar/SIM.cpp" + "${CMAKE_CURRENT_LIST_DIR}/TopBar/BatteryWidget.cpp" "${CMAKE_CURRENT_LIST_DIR}/Text.cpp" "${CMAKE_CURRENT_LIST_DIR}/TextBlock.cpp" "${CMAKE_CURRENT_LIST_DIR}/TextDocument.cpp" diff --git a/module-gui/gui/widgets/TopBar.cpp b/module-gui/gui/widgets/TopBar.cpp index 8fd3dbc23d22604d2e8452179f6f3c1733a21373..6238e7f8ecdb0e01cf58f714f581ae523990ab4b 100644 --- a/module-gui/gui/widgets/TopBar.cpp +++ b/module-gui/gui/widgets/TopBar.cpp @@ -74,22 +74,6 @@ namespace gui::top_bar }; } - void TopBar::batteryShowBars(uint32_t val) - { - if (val > batteryBars.size()) { - LOG_ERROR("Trying to set battery level out of scope"); - val = batteryBars.size(); - } - for (unsigned int i = 0; i < batteryBars.size(); ++i) { - if (configuration.isEnabled(Indicator::Battery)) { - batteryBars[i]->setVisible(i == val); - } - else { - batteryBars[i]->setVisible(false); - } - } - } - void TopBar::prepareWidget() { signal[0] = new gui::Image(this, signalOffset, 17, 0, 0, "signal0"); @@ -100,24 +84,7 @@ namespace gui::top_bar signal[5] = new gui::Image(this, signalOffset, 17, 0, 0, "signal5"); updateSignalStrength(); - // icons for battery - batteryBars = { - new gui::Image(this, batteryOffset, 15, 0, 0, "battery_low_W_M"), - new gui::Image(this, batteryOffset, 15, 0, 0, "battery1_W_M"), - new gui::Image(this, batteryOffset, 15, 0, 0, "battery2_W_M"), - new gui::Image(this, batteryOffset, 15, 0, 0, "battery3_W_M"), - new gui::Image(this, batteryOffset, 15, 0, 0, "battery4_W_M"), - new gui::Image(this, batteryOffset, 15, 0, 0, "battery5_W_M"), - }; - batteryShowBars(0); - - batteryChargings[Store::Battery::State::Charging] = - new gui::Image(this, batteryOffset, 15, 0, 0, "battery_charging_W_M"); - batteryChargings[Store::Battery::State::PluggedNotCharging] = - new gui::Image(this, batteryOffset, 15, 0, 0, "battery_charging_ready_W_M"); - for (auto &el : batteryChargings) { - el.second->setVisible(false); - } + batteryWidget = new BatteryWidget(this, batteryOffset, 15); const auto design_sim_offset = 376; // this offset is not final, but it is pixel Purefect sim = new SIM(this, design_sim_offset, 12); @@ -181,7 +148,7 @@ namespace gui::top_bar } break; case Indicator::Battery: - showBattery(enabled); + batteryWidget->show(Store::Battery::get(), enabled); break; case Indicator::SimCard: showSim(enabled); @@ -192,65 +159,12 @@ namespace gui::top_bar } } - uint32_t TopBar::calculateBatteryBars(uint32_t percentage) + bool TopBar::updateBattery() { - uint32_t level = 0; - if (percentage <= 5) // level critical - level = 0; - else if (percentage <= 27) - level = 1; - else if (percentage <= 50) - level = 2; - else if (percentage <= 73) - level = 3; - else if (percentage <= 95) - level = 4; - else - level = 5; - - if (level >= batteryBarsCount) { - LOG_ERROR("Battery level calculations are done wrong!"); - return batteryBarsCount - 1; - } - return level; - } - - bool TopBar::updateBattery(uint32_t percent) - { - showBattery(configuration.isEnabled(Indicator::Battery)); + batteryWidget->show(Store::Battery::get(), configuration.isEnabled(Indicator::Battery)); return true; } - bool TopBar::updateBattery(bool plugged) - { - showBattery(configuration.isEnabled(Indicator::Battery)); - return true; - } - - void TopBar::showBattery(bool shown) - { - // hide battery bars icons - for (const auto &bars : batteryBars) { - bars->setVisible(false); - } - // hide battery charging icons - for (const auto &charging : batteryChargings) { - charging.second->setVisible(false); - } - - if (shown) { - switch (Store::Battery::get().state) { - case Store::Battery::State::Discharging: - batteryShowBars(calculateBatteryBars(Store::Battery::get().level)); - break; - case Store::Battery::State::Charging: - case Store::Battery::State::PluggedNotCharging: - batteryChargings[Store::Battery::get().state]->setVisible(true); - break; - } - } - } - void TopBar::showSim(bool enabled) { if (!enabled) { diff --git a/module-gui/gui/widgets/TopBar.hpp b/module-gui/gui/widgets/TopBar.hpp index 0172b3a75eb10275955917b397f4bd96bdcef3e8..d23bcd45fd45308b1c59cc9ea545571c38bfe029 100644 --- a/module-gui/gui/widgets/TopBar.hpp +++ b/module-gui/gui/widgets/TopBar.hpp @@ -7,6 +7,7 @@ #include "Label.hpp" #include "Rect.hpp" #include "TopBar/SIM.hpp" +#include "TopBar/BatteryWidget.hpp" #include #include @@ -82,18 +83,14 @@ namespace gui::top_bar std::map batteryChargings = { {Store::Battery::State::Charging, nullptr}, {Store::Battery::State::PluggedNotCharging, nullptr}}; gui::SIM *sim = nullptr; + gui::BatteryWidget *batteryWidget = nullptr; Configuration configuration; static TimeMode timeMode; void prepareWidget(); - /// show bars in number - 0 bars, 1 bar, 2 bars... - void batteryShowBars(uint32_t val); - void showBattery(bool shown); void showSim(bool enabled); - static uint32_t calculateBatteryBars(uint32_t percentage); - /** * Sets the status of the top bar indicator. * @param indicator Indicator @@ -111,12 +108,11 @@ namespace gui::top_bar [[nodiscard]] auto getConfiguration() const noexcept -> const Configuration &; /** - * @brief Sets charge level of the battery based on percent value. This will cause appropriate image to be + * @brief Sets charge level of the battery. This will cause appropriate image to be * displayed. * @return if display should be refreshed or not */ - bool updateBattery(uint32_t percent); - bool updateBattery(bool plugged); + bool updateBattery(); /** * @brief updates signal strength. This will cause appropriate image to be displayed. diff --git a/module-gui/gui/widgets/TopBar/BatteryWidget.cpp b/module-gui/gui/widgets/TopBar/BatteryWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d30996661079823175ffe591894209230effccfd --- /dev/null +++ b/module-gui/gui/widgets/TopBar/BatteryWidget.cpp @@ -0,0 +1,67 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BatteryWidget.hpp" + +namespace gui +{ + namespace + { + constexpr auto batteryLow = "battery_low_W_M"; + constexpr auto batteryCharging = "battery_charging_W_M"; + constexpr auto batteryChargingReady = "battery_charging_ready_W_M"; + constexpr auto battery1 = "battery1_W_M"; + constexpr auto battery2 = "battery2_W_M"; + constexpr auto battery3 = "battery3_W_M"; + constexpr auto battery4 = "battery4_W_M"; + constexpr auto battery5 = "battery5_W_M"; + + constexpr auto level1Threshold = 5; + constexpr auto level2Threshold = 27; + constexpr auto level3Threshold = 50; + constexpr auto level4Threshold = 73; + constexpr auto level5Threshold = 95; + } // namespace + + BatteryWidget::BatteryWidget(Item *parent, uint32_t x, uint32_t y) : Image(parent, x, y, 0, 0) + { + set(battery1); + } + + void BatteryWidget::show(const Store::Battery batteryContext, bool shown) + { + if (shown) { + switch (batteryContext.state) { + case Store::Battery::State::Discharging: + showBatteryBars(batteryContext.level); + break; + case Store::Battery::State::Charging: + set(batteryCharging); + break; + case Store::Battery::State::PluggedNotCharging: + set(batteryChargingReady); + break; + } + } + else { + setVisible(false); + } + } + + void BatteryWidget::showBatteryBars(std::uint32_t percentage) + { + if (percentage <= level1Threshold) + set(batteryLow); + else if (percentage <= level2Threshold) + set(battery1); + else if (percentage <= level3Threshold) + set(battery2); + else if (percentage <= level4Threshold) + set(battery3); + else if (percentage <= level5Threshold) + set(battery4); + else + set(battery5); + } + +} // namespace gui diff --git a/module-gui/gui/widgets/TopBar/BatteryWidget.hpp b/module-gui/gui/widgets/TopBar/BatteryWidget.hpp new file mode 100644 index 0000000000000000000000000000000000000000..050d06b775023458dc92bede6578a558b0fd658d --- /dev/null +++ b/module-gui/gui/widgets/TopBar/BatteryWidget.hpp @@ -0,0 +1,20 @@ +// 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 "../Image.hpp" +#include + +namespace gui +{ + class BatteryWidget : public Image + { + public: + BatteryWidget(Item *parent, uint32_t x, uint32_t y); + void show(const Store::Battery batteryContext, bool shown); + + private: + void showBatteryBars(std::uint32_t percentage); + }; +} // namespace gui diff --git a/module-services/service-evtmgr/EventManager.cpp b/module-services/service-evtmgr/EventManager.cpp index 56f9a53fcb3755650fa36e931a362d7046b7f024..be538a5f6537d299e73c16333e208145a4333eac 100644 --- a/module-services/service-evtmgr/EventManager.cpp +++ b/module-services/service-evtmgr/EventManager.cpp @@ -39,6 +39,7 @@ #include #include #include +#include EventManager::EventManager(const std::string &name) : sys::Service(name), screenLightControl(std::make_unique(this)) @@ -122,32 +123,6 @@ sys::MessagePointer EventManager::DataReceivedHandler(sys::DataMessage *msgl, sy LOG_INFO("Switching focus to %s", targetApplication.c_str()); } } - else if (msgl->messageType == MessageType::EVMBatteryLevel && msgl->sender == this->GetName()) { - auto *msg = static_cast(msgl); - - auto message = std::make_shared(msg->levelPercents, msg->fullyCharged); - - if (!targetApplication.empty()) { - bus.sendUnicast(message, targetApplication); - } - - handled = true; - } - else if (msgl->messageType == MessageType::EVMChargerPlugged && msgl->sender == this->GetName()) { - auto *msg = static_cast(msgl); - - auto message = std::make_shared(); - message->plugged = msg->plugged; - - if (!message->plugged) { - bus.sendUnicast(message, service::name::system_manager); - } - - if (!targetApplication.empty()) { - bus.sendUnicast(message, targetApplication); - } - handled = true; - } else if (msgl->messageType == MessageType::EVMMinuteUpdated && msgl->sender == this->GetName()) { HandleAlarmTrigger(msgl); @@ -287,6 +262,23 @@ sys::ReturnCodes EventManager::InitHandler() return msg; }); + connect(sevm::BatteryStatusChangeMessage(), [&](sys::Message *msgl) { + if (msgl->sender == this->GetName()) { + LOG_INFO("Battery level: %d , charging: %d", + Store::Battery::get().level, + Store::Battery::get().state == Store::Battery::State::Charging); + + if (Store::Battery::get().state == Store::Battery::State::Discharging) { + bus.sendUnicast(std::make_shared(), service::name::system_manager); + } + + if (!targetApplication.empty()) { + bus.sendUnicast(std::make_shared(), targetApplication); + } + } + return std::make_shared(); + }); + // initialize keyboard worker EventWorker = std::make_unique(this); diff --git a/module-services/service-evtmgr/WorkerEvent.cpp b/module-services/service-evtmgr/WorkerEvent.cpp index bb3a70363e7d9d2d66d5a029ed7cd7a818c60646..b36db2f4ec24c7e22f8c2956ad70d3b9bc34144d 100644 --- a/module-services/service-evtmgr/WorkerEvent.cpp +++ b/module-services/service-evtmgr/WorkerEvent.cpp @@ -93,8 +93,8 @@ bool WorkerEvent::handleMessage(uint32_t queueID) if (notification == static_cast(bsp::battery_charger::batteryIRQSource::INTB)) { auto topINT = bsp::battery_charger::getTopControllerINTSource(); if (topINT & static_cast(bsp::battery_charger::topControllerIRQsource::CHGR_INT)) { - auto message = std::make_shared(); - message->plugged = bsp::battery_charger::getChargeStatus(); + bsp::battery_charger::getChargeStatus(); + auto message = std::make_shared(); service->bus.sendUnicast(std::move(message), service::name::evt_manager); bsp::battery_charger::clearAllChargerIRQs(); } @@ -107,8 +107,8 @@ bool WorkerEvent::handleMessage(uint32_t queueID) if (status & static_cast(bsp::battery_charger::batteryINTBSource::SOCOnePercentChange)) { bsp::battery_charger::clearFuelGuageIRQ( static_cast(bsp::battery_charger::batteryINTBSource::SOCOnePercentChange)); - bsp::battery_charger::StateOfCharge battLevel = bsp::battery_charger::getBatteryLevel(); - auto message = std::make_shared(battLevel, false); + bsp::battery_charger::getBatteryLevel(); + auto message = std::make_shared(); service->bus.sendUnicast(std::move(message), service::name::evt_manager); battery_level_check::checkBatteryLevelCritical(); } @@ -118,8 +118,8 @@ bool WorkerEvent::handleMessage(uint32_t queueID) static_cast(bsp::battery_charger::batteryINTBSource::maxTemp) | static_cast(bsp::battery_charger::batteryINTBSource::minTemp)); bsp::battery_charger::checkTemperatureRange(); - auto message = std::make_shared(); - message->plugged = bsp::battery_charger::getChargeStatus(); + bsp::battery_charger::getChargeStatus(); + auto message = std::make_shared(); service->bus.sendUnicast(std::move(message), service::name::evt_manager); } } diff --git a/module-services/service-evtmgr/doc/battery_status_notification.md b/module-services/service-evtmgr/doc/battery_status_notification.md new file mode 100644 index 0000000000000000000000000000000000000000..a0109785196046db93b8e1ff9d55a9eb022ac684 --- /dev/null +++ b/module-services/service-evtmgr/doc/battery_status_notification.md @@ -0,0 +1,4 @@ +# Battery Status propagation in system + +Battery status information is propagated according to following diagram: +![](battery_status_notification.svg) \ No newline at end of file diff --git a/module-services/service-evtmgr/doc/battery_status_notification.puml b/module-services/service-evtmgr/doc/battery_status_notification.puml new file mode 100644 index 0000000000000000000000000000000000000000..6da9d687ea9476287ddaa3620f9ba165e494d782 --- /dev/null +++ b/module-services/service-evtmgr/doc/battery_status_notification.puml @@ -0,0 +1,24 @@ +@startuml +participant "Battery Charger" as bc +participant "Worker Event" as we +participant "Event Manager" as evm +participant "System Manager" as sm +participant "Current application" as ca +participant "TopBar" as tb +participant "Battery Widget" as bw +participant "Event Store\nBattery" as es + +bc -> we : Interrupt +we -> bc : Store status to EventStore +bc -> es : modify() +we -> evm : BatteryStatusChangeMessage +group If Discharging + evm -> sm : BatteryStatusChangeMessage + sm -> sm : If State::ShutdownReady:\n state = State:Shutdown +end +evm -> ca : BatteryStatusChangeMessage +ca -> tb : updateBattery() +tb <-> es : get() +tb -> bw : show(batteryContext) + +@enduml diff --git a/module-services/service-evtmgr/doc/battery_status_notification.svg b/module-services/service-evtmgr/doc/battery_status_notification.svg new file mode 100644 index 0000000000000000000000000000000000000000..251836dd38cf2725eb2d191cb71cbc839a7673d7 --- /dev/null +++ b/module-services/service-evtmgr/doc/battery_status_notification.svg @@ -0,0 +1,34 @@ +Battery ChargerBattery ChargerWorker EventWorker EventEvent ManagerEvent ManagerSystem ManagerSystem ManagerCurrent applicationCurrent applicationTopBarTopBarBattery WidgetBattery WidgetEvent StoreBatteryEvent StoreBatteryInterruptStore status to EventStoremodify()BatteryStatusChangeMessageIf DischargingBatteryStatusChangeMessageIf State::ShutdownReady:state = State:ShutdownBatteryStatusChangeMessageupdateBattery()get()show(batteryContext) \ No newline at end of file diff --git a/module-services/service-evtmgr/service-evtmgr/BatteryMessages.hpp b/module-services/service-evtmgr/service-evtmgr/BatteryMessages.hpp index c080398fdea36caca777593922f5853715d704fe..429733e900bfbb3f2a54f90f724883b76a916fd8 100644 --- a/module-services/service-evtmgr/service-evtmgr/BatteryMessages.hpp +++ b/module-services/service-evtmgr/service-evtmgr/BatteryMessages.hpp @@ -9,27 +9,9 @@ namespace sevm { - class BatteryLevelMessage : public Message - { - public: - BatteryLevelMessage(uint8_t levelPercents, bool fullyCharged) - : Message(MessageType::EVMBatteryLevel), levelPercents(levelPercents), fullyCharged(fullyCharged) - { - type = Type::Data; - } - uint8_t levelPercents = 0; - bool fullyCharged = false; - }; + class BatteryStatusChangeMessage : public sys::Message + {}; - class BatteryPlugMessage : public Message - { - public: - BatteryPlugMessage() : Message(MessageType::EVMChargerPlugged) - { - type = Type::Data; - } - bool plugged = false; - }; class BatterySetCriticalLevel : public sys::Message { public: diff --git a/module-sys/SystemManager/SystemManager.cpp b/module-sys/SystemManager/SystemManager.cpp index 6af7e9b4b30b7d1ddf3a12f29e35b0b9553bc6fb..dc7f58207e8776ae8d04e85d11841352e183a591 100644 --- a/module-sys/SystemManager/SystemManager.cpp +++ b/module-sys/SystemManager/SystemManager.cpp @@ -286,17 +286,17 @@ namespace sys return MessageNone{}; }); - connect(sevm::KbdMessage(), [&](Message *) { - // we are in shutdown mode - we received that there was red key pressed -> we need to reboot - if (state == State::Shutdown) { - set(State::Reboot); + connect(sevm::BatteryStatusChangeMessage(), [&](Message *) { + if ((state == State::Shutdown) && (Store::Battery::get().state == Store::Battery::State::Discharging)) { + set(State::ShutdownReady); } return MessageNone{}; }); - connect(sevm::BatteryPlugMessage(), [&](Message *) { + connect(sevm::KbdMessage(), [&](Message *) { + // we are in shutdown mode - we received that there was red key pressed -> we need to reboot if (state == State::Shutdown) { - set(State::ShutdownReady); + set(State::Reboot); } return MessageNone{}; }); diff --git a/source/MessageType.hpp b/source/MessageType.hpp index 6204086df588065efdd5888c3a0c289557c2397c..43e0046311126dd9bcd473c444673be2fe71ea60 100644 --- a/source/MessageType.hpp +++ b/source/MessageType.hpp @@ -173,9 +173,6 @@ enum class MessageType SystemManagerCpuFrequency, SystemManagerRegistration, - // battery charger messages - EVMBatteryLevel, - EVMChargerPlugged, // rtc messages EVMMinuteUpdated, ///< This message is send to current focused application on every minute time change. EVMTimeUpdated, ///< This message is send on every time update.