From f388b77cc61ec7d433c7d26af06997f5e978faf5 Mon Sep 17 00:00:00 2001 From: Maciej Gibowicz Date: Thu, 22 Feb 2024 08:58:36 +0100 Subject: [PATCH] [BH-1882] Fix display of "Connected" label on home screen The "connected" label did not appear on the home screen if the USB was connected during onboarding. --- module-apps/apps-common/ApplicationCommon.cpp | 3 -- module-apps/apps-common/ApplicationCommon.hpp | 2 - .../service-desktop/WorkerDesktop.cpp | 43 +++++++++++++------ .../service-desktop/WorkerDesktop.hpp | 6 ++- module-utils/EventStore/EventStore.cpp | 14 +++++- module-utils/EventStore/EventStore.hpp | 20 ++++++++- .../ApplicationBellMain.cpp | 5 --- .../models/UsbStatusModel.cpp | 6 +-- .../models/UsbStatusModel.hpp | 10 +---- 9 files changed, 71 insertions(+), 38 deletions(-) diff --git a/module-apps/apps-common/ApplicationCommon.cpp b/module-apps/apps-common/ApplicationCommon.cpp index 4b63647706b2a37be4cdc4635e392877a7973e26..a5e80c58329372e0fb3b2234c187dbc279d9a922 100644 --- a/module-apps/apps-common/ApplicationCommon.cpp +++ b/module-apps/apps-common/ApplicationCommon.cpp @@ -115,9 +115,6 @@ namespace app connect(typeid(sdesktop::usb::USBConnected), [&](sys::Message *msg) -> sys::MessagePointer { return handleUsbStatusChange(); }); connect(typeid(sdesktop::usb::USBDisconnected), [&](sys::Message *msg) -> sys::MessagePointer { - if (onUsbDisconnected != nullptr) { - onUsbDisconnected(); - } return handleUsbStatusChange(); }); diff --git a/module-apps/apps-common/ApplicationCommon.hpp b/module-apps/apps-common/ApplicationCommon.hpp index 78d46aa5c1284ef9e2e3aeaa06aa9fbaaf3257c8..f380d15c1622646f6b42d8c441e8d033cbe6ad94 100644 --- a/module-apps/apps-common/ApplicationCommon.hpp +++ b/module-apps/apps-common/ApplicationCommon.hpp @@ -176,8 +176,6 @@ namespace app using OnActionReceived = std::function; protected: - std::function onUsbDisconnected; - virtual sys::MessagePointer handleKBDKeyEvent(sys::Message *msgl); virtual sys::MessagePointer handleApplicationSwitch(sys::Message *msgl); virtual sys::MessagePointer handleAppClose(sys::Message *msgl); diff --git a/module-services/service-desktop/WorkerDesktop.cpp b/module-services/service-desktop/WorkerDesktop.cpp index 7afb29c91244a4b1890f28af6013114391ada91f..f4690b1d6526392fa64a12bab53c747e77c6931b 100644 --- a/module-services/service-desktop/WorkerDesktop.cpp +++ b/module-services/service-desktop/WorkerDesktop.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "service-desktop/ServiceDesktop.hpp" @@ -15,7 +15,8 @@ #include #include -#include "system/messages/SentinelRegistrationMessage.hpp" +#include +#include WorkerDesktop::WorkerDesktop(sys::Service *ownerServicePtr, std::function messageProcessedCallback, @@ -216,23 +217,15 @@ bool WorkerDesktop::handleIrqQueueMessage(std::shared_ptr &que switch (notification) { case bsp::USBDeviceStatus::Connected: - LOG_DEBUG("USB status: Connected"); - ownerService->bus.sendMulticast(std::make_shared(), - sys::BusChannel::USBNotifications); + handleUsbConnected(); break; case bsp::USBDeviceStatus::Configured: - LOG_DEBUG("USB status: Configured"); - ownerService->bus.sendMulticast(std::make_shared(), - sys::BusChannel::USBNotifications); - configured = true; + handleUsbConfigured(); break; case bsp::USBDeviceStatus::Disconnected: - LOG_DEBUG("USB status: Disconnected"); - ownerService->bus.sendMulticast(std::make_shared(), - sys::BusChannel::USBNotifications); - configured = false; + handleUsbDisconnected(); break; case bsp::USBDeviceStatus::DataReceived: @@ -254,6 +247,30 @@ bool WorkerDesktop::handleIrqQueueMessage(std::shared_ptr &que return true; } +void WorkerDesktop::handleUsbConnected() +{ + LOG_DEBUG("USB status: Connected"); + ownerService->bus.sendMulticast(std::make_shared(), sys::BusChannel::USBNotifications); +} + +void WorkerDesktop::handleUsbDisconnected() +{ + LOG_DEBUG("USB status: Disconnected"); + Store::Usb::modify().status = Store::Usb::Status::NotConfigured; + ownerService->bus.sendMulticast(std::make_shared(), + sys::BusChannel::USBNotifications); + configured = false; +} + +void WorkerDesktop::handleUsbConfigured() +{ + LOG_DEBUG("USB status: Configured"); + Store::Usb::modify().status = Store::Usb::Status::Configured; + ownerService->bus.sendMulticast(std::make_shared(), + sys::BusChannel::USBNotifications); + configured = true; +} + bool WorkerDesktop::handleSignallingQueueMessage(std::shared_ptr &queue) { if (!initialized) { diff --git a/module-services/service-desktop/WorkerDesktop.hpp b/module-services/service-desktop/WorkerDesktop.hpp index 38a5ea0b817765db7bb02c42974a2517ceaee893..8f5794e2543f89cd68e670f1e8c931b5cacaa7d4 100644 --- a/module-services/service-desktop/WorkerDesktop.hpp +++ b/module-services/service-desktop/WorkerDesktop.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -46,6 +46,10 @@ class WorkerDesktop : public sys::Worker bool handleIrqQueueMessage(std::shared_ptr &queue); bool handleSignallingQueueMessage(std::shared_ptr &queue); + void handleUsbConnected(); + void handleUsbDisconnected(); + void handleUsbConfigured(); + std::atomic initialized = false; std::atomic configured = false; diff --git a/module-utils/EventStore/EventStore.cpp b/module-utils/EventStore/EventStore.cpp index 10e3cc6a10ecfa7a1b61488cfa168f61c04e5134..2d8255745980ec87f9e295a8d3fa48cead055ffc 100644 --- a/module-utils/EventStore/EventStore.cpp +++ b/module-utils/EventStore/EventStore.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "EventStore.hpp" @@ -38,6 +38,18 @@ namespace Store return false; } + Usb usb; + + const Usb &Usb::get() + { + return usb; + } + + Usb &Usb::modify() + { + return usb; + } + cpp_freertos::MutexStandard GSM::mutex; GSM *GSM::get() diff --git a/module-utils/EventStore/EventStore.hpp b/module-utils/EventStore/EventStore.hpp index 4b1998aed759f6050b93c8c43aa68ea537b45648..b92c08e25503d39421d5db521307f55a9bf845d1 100644 --- a/module-utils/EventStore/EventStore.hpp +++ b/module-utils/EventStore/EventStore.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -65,6 +65,24 @@ namespace Store static bool takeUpdated(); }; + struct Usb + { + public: + enum class Status : bool + { + NotConfigured, + Configured + } status = Status::NotConfigured; + + /// @brief Returns const reference to Usb instance, used to read Usb status + /// @return const Usb& + static const Usb &get(); + + /// @brief Returns reference to Usb instance, used to change Usb status + /// @return Usb& + static Usb &modify(); + }; + enum class RssiBar : size_t { zero = 0, diff --git a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp index 9da2910308f0a60f86b7eaf0e6c1c4d286fdf78f..97147026d6671eacee23fa3aaf513842276ec19d 100644 --- a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp +++ b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp @@ -82,7 +82,6 @@ namespace app }); connect(typeid(sdesktop::usb::USBConfigured), [&](sys::Message *msg) -> sys::MessagePointer { - usbStatusModel->setUsbStatus(app::AbstractUsbStatusModel::UsbStatus::Connected); if (getCurrentWindow()->getName() == gui::name::window::main_window) { homeScreenPresenter->updateUsbStatus(); } @@ -98,10 +97,6 @@ namespace app alarmModel->activateAlarm(true); return sys::msgHandled(); }); - - onUsbDisconnected = [this]() { - usbStatusModel->setUsbStatus(app::AbstractUsbStatusModel::UsbStatus::Disconnected); - }; } sys::ReturnCodes ApplicationBellMain::InitHandler() diff --git a/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.cpp b/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.cpp index ba8f79451ee598810efe80730cf28a673b01439a..b52006959ec1f13319742c41329d755083cf3003 100644 --- a/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.cpp +++ b/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.cpp @@ -7,11 +7,11 @@ namespace app { bool UsbStatusModel::isUsbConnected(const Store::Battery::State &state) const { - return ((usbConnected == UsbStatus::Connected) && (state == Store::Battery::State::PluggedNotCharging)); + return (isUsbConfigured() && (state == Store::Battery::State::PluggedNotCharging)); } - void UsbStatusModel::setUsbStatus(UsbStatus status) + bool UsbStatusModel::isUsbConfigured() const { - usbConnected = status; + return Store::Usb::get().status == Store::Usb::Status::Configured; } } // namespace app diff --git a/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.hpp b/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.hpp index 48ce63b5872694e25a95e60650751d3aff25231d..6cbd2db48d67bca6e8e97d47afe9b19bfd3800e7 100644 --- a/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.hpp +++ b/products/BellHybrid/apps/application-bell-main/models/UsbStatusModel.hpp @@ -10,25 +10,17 @@ namespace app class AbstractUsbStatusModel { public: - enum class UsbStatus : bool - { - Disconnected, - Connected - }; - virtual ~AbstractUsbStatusModel() noexcept = default; virtual bool isUsbConnected(const Store::Battery::State &state) const = 0; - virtual void setUsbStatus(UsbStatus status) = 0; }; class UsbStatusModel : public AbstractUsbStatusModel { public: bool isUsbConnected(const Store::Battery::State &state) const override; - void setUsbStatus(UsbStatus status) override; private: - UsbStatus usbConnected{UsbStatus::Disconnected}; + bool isUsbConfigured() const; }; } // namespace app