From 39be35722da1bb602b537ae415af82fb795c5ea8 Mon Sep 17 00:00:00 2001 From: Mateusz Grzegorzek Date: Tue, 13 Apr 2021 16:01:25 +0200 Subject: [PATCH] =?UTF-8?q?[EGD-6505]=20Implement=20=E2=80=9COn=20when=20a?= =?UTF-8?q?ctive=E2=80=9D=20Keypad=20light=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement “On when active” Keypad light functionality --- image/user/db/settings_v2_002.sql | 5 ++-- module-apps/Application.cpp | 1 - .../ApplicationSettings.cpp | 29 +++++------------- .../ApplicationSettings.hpp | 11 +++---- .../windows/KeypadLightWindow.cpp | 29 +++++++++++++----- .../bsp/keypad_backlight/keypad_backlight.hpp | 10 ++++++- .../model/ApplicationManager.cpp | 27 ++++++++++++++++- .../model/ApplicationManager.hpp | 3 ++ .../agents/settings/SystemSettings.hpp | 4 +++ .../service-evtmgr/EventManager.cpp | 30 +++++++++++++++++-- .../service-evtmgr/EventManager.hpp | 8 ++++- 11 files changed, 115 insertions(+), 42 deletions(-) diff --git a/image/user/db/settings_v2_002.sql b/image/user/db/settings_v2_002.sql index 576ead733c5f074ce10224564659f6b8025dc64e..445a4c79af456d4102e01bd9bd75c7af400aefcb 100644 --- a/image/user/db/settings_v2_002.sql +++ b/image/user/db/settings_v2_002.sql @@ -32,6 +32,5 @@ INSERT OR IGNORE INTO settings_tab (path, value) VALUES ('cl_offline_mode', '0'), ('off_connection_frequency', '0'), ('off_notifications_when_locked', '0'), - ('off_calls_from_favorites', '0'); - - + ('off_calls_from_favorites', '0'), + ('keypad_light_state', '0'); diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index c43d5e0e16ce93a9d37a2b5c45e49f70b1754a4b..298607b134f146781816d7250334850048aa1b77 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -901,5 +901,4 @@ namespace app { return lockScreenPasscodeIsOn; } - } /* namespace app */ diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index e3bc8b0032a0b222fb89c704770cf9335004c815..e8bc65c66ca6c42ca49477a828351167699f554e 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -662,31 +662,17 @@ namespace app service::name::evt_manager); } - auto ApplicationSettingsNew::isKeypadBacklightOn() -> bool + auto ApplicationSettingsNew::getKeypadBacklightState() -> bsp::keypad_backlight::State { - constexpr int timeout = pdMS_TO_TICKS(1500); - - auto response = - bus.sendUnicast(std::make_shared(bsp::keypad_backlight::Action::checkState), - service::name::evt_manager, - timeout); - - if (response.first == sys::ReturnCodes::Success) { - auto msgState = dynamic_cast(response.second.get()); - if (msgState == nullptr) { - return false; - } - - return msgState->success; - } - return false; + return static_cast(utils::getNumericValue( + settings->getValue(::settings::KeypadLight::state, ::settings::SettingsScope::Global))); } - void ApplicationSettingsNew::setKeypadBacklightState(bool newState) + void ApplicationSettingsNew::setKeypadBacklightState(bsp::keypad_backlight::State keypadLightState) { - bus.sendUnicast(std::make_shared( - newState ? bsp::keypad_backlight::Action::turnOn : bsp::keypad_backlight::Action::turnOff), - service::name::evt_manager); + settings->setValue(::settings::KeypadLight::state, + std::to_string(static_cast(keypadLightState)), + ::settings::SettingsScope::Global); } bool ApplicationSettingsNew::isUSBSecured() const @@ -711,6 +697,7 @@ namespace app settings->setValue( ::settings::Offline::notificationsWhenLocked, std::to_string(on), ::settings::SettingsScope::Global); } + auto ApplicationSettingsNew::getCallsFromFavourite() const noexcept -> bool { return callsFromFavorites; diff --git a/module-apps/application-settings-new/ApplicationSettings.hpp b/module-apps/application-settings-new/ApplicationSettings.hpp index 4fa67acd65a0ddf14de08dddc32d63c472e6713d..5cd2f155c4436394bc5d13f7820508d606c508bd 100644 --- a/module-apps/application-settings-new/ApplicationSettings.hpp +++ b/module-apps/application-settings-new/ApplicationSettings.hpp @@ -6,6 +6,7 @@ #include "Application.hpp" #include +#include #include #include @@ -124,9 +125,9 @@ namespace app class KeypdBacklightSettings { public: - virtual ~KeypdBacklightSettings() = default; - virtual auto isKeypadBacklightOn() -> bool = 0; - virtual void setKeypadBacklightState(bool newState) = 0; + virtual ~KeypdBacklightSettings() = default; + virtual auto getKeypadBacklightState() -> bsp::keypad_backlight::State = 0; + virtual void setKeypadBacklightState(bsp::keypad_backlight::State state) = 0; }; class SecuritySettings @@ -216,8 +217,8 @@ namespace app void setStatus(bool isDisplayLightSwitchOn) override; void setBrightnessFunction() override; - auto isKeypadBacklightOn() -> bool override; - void setKeypadBacklightState(bool newState) override; + auto getKeypadBacklightState() -> bsp::keypad_backlight::State override; + void setKeypadBacklightState(bsp::keypad_backlight::State keypadLightState) override; auto isUSBSecured() const -> bool override; void setUSBSecurity(bool security) override; diff --git a/module-apps/application-settings-new/windows/KeypadLightWindow.cpp b/module-apps/application-settings-new/windows/KeypadLightWindow.cpp index 9a1f9f95ef3482e7e087d46de7cab3a39d4f414d..2ace33e14f3a95f5cf1f6f726cf6b6dcf1268bfe 100644 --- a/module-apps/application-settings-new/windows/KeypadLightWindow.cpp +++ b/module-apps/application-settings-new/windows/KeypadLightWindow.cpp @@ -1,11 +1,12 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "KeypadLightWindow.hpp" -#include "application-settings-new/ApplicationSettings.hpp" -#include "OptionSetting.hpp" +#include +#include +#include #include namespace gui @@ -15,11 +16,17 @@ namespace gui app::settingsInterface::KeypdBacklightSettings *settings) : BaseSettingsWindow(app, window::name::keypad_light), keypadLightSettings(settings) { - if (keypadLightSettings->isKeypadBacklightOn()) { + const auto keypadBacklightState = keypadLightSettings->getKeypadBacklightState(); + switch (keypadBacklightState) { + case bsp::keypad_backlight::State::on: isAlwaysOnSwitchOn = true; - } - else { + break; + case bsp::keypad_backlight::State::activeMode: + isActiveSwitchOn = true; + break; + case bsp::keypad_backlight::State::off: isOffSwitchOn = true; + break; } setTitle(utils::localize.get("app_settings_display_keypad_light")); @@ -32,7 +39,15 @@ namespace gui isAlwaysOnSwitchOn = false; toggleSwitch = !toggleSwitch; rebuildOptionList(); - keypadLightSettings->setKeypadBacklightState(isAlwaysOnSwitchOn); + if (isAlwaysOnSwitchOn) { + keypadLightSettings->setKeypadBacklightState(bsp::keypad_backlight::State::on); + } + else if (isActiveSwitchOn) { + keypadLightSettings->setKeypadBacklightState(bsp::keypad_backlight::State::activeMode); + } + else { + keypadLightSettings->setKeypadBacklightState(bsp::keypad_backlight::State::off); + } } auto KeypadLightWindow::buildOptionsList() -> std::list diff --git a/module-bsp/bsp/keypad_backlight/keypad_backlight.hpp b/module-bsp/bsp/keypad_backlight/keypad_backlight.hpp index 147376814569065764641098380469196d4bfc37..d260858290d28927339aa57ddd612069ac553332 100644 --- a/module-bsp/bsp/keypad_backlight/keypad_backlight.hpp +++ b/module-bsp/bsp/keypad_backlight/keypad_backlight.hpp @@ -9,11 +9,19 @@ namespace bsp::keypad_backlight { enum class Action { - turnOn, turnOff, + turnOnActiveMode, + turnOn, checkState, }; + enum class State + { + off, + activeMode, + on + }; + using DiodeIntensity = float; std::int32_t init(); diff --git a/module-services/service-appmgr/model/ApplicationManager.cpp b/module-services/service-appmgr/model/ApplicationManager.cpp index aeb45b32c941d68a18d92de2013908fc64e6df03..680067546b8416afbaf5bfbf75d613698b6b1b6b 100644 --- a/module-services/service-appmgr/model/ApplicationManager.cpp +++ b/module-services/service-appmgr/model/ApplicationManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include #include #include - #include #include #include @@ -184,6 +184,15 @@ namespace app::manager }, ::settings::SettingsScope::Global); + settings->registerValueChange( + ::settings::KeypadLight::state, + [this](const std::string &value) { + const auto keypadLightState = + static_cast(utils::getNumericValue(value)); + processKeypadBacklightState(keypadLightState); + }, + ::settings::SettingsScope::Global); + startBackgroundApplications(); bus.sendUnicast(std::make_unique(), service::name::system_manager); @@ -1018,4 +1027,20 @@ namespace app::manager return std::make_shared(sys::ReturnCodes::Unresolved); } + void ApplicationManager::processKeypadBacklightState(bsp::keypad_backlight::State keypadLightState) + { + auto action = bsp::keypad_backlight::Action::turnOff; + switch (keypadLightState) { + case bsp::keypad_backlight::State::on: + action = bsp::keypad_backlight::Action::turnOn; + break; + case bsp::keypad_backlight::State::activeMode: + action = bsp::keypad_backlight::Action::turnOnActiveMode; + break; + case bsp::keypad_backlight::State::off: + action = bsp::keypad_backlight::Action::turnOff; + break; + } + bus.sendUnicast(std::make_shared(action), service::name::evt_manager); + } } // namespace app::manager diff --git a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp index 4f0819171b60753532f0b935a01533f1cd90a899..a2efb9449d894447e4d406ad84c8589d43caac0a 100644 --- a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +++ b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -177,6 +178,8 @@ namespace app::manager void displayLanguageChanged(std::string value); void lockTimeChanged(std::string value); void inputLanguageChanged(std::string value); + + void processKeypadBacklightState(bsp::keypad_backlight::State keypadLightState); }; } // namespace app::manager diff --git a/module-services/service-db/agents/settings/SystemSettings.hpp b/module-services/service-db/agents/settings/SystemSettings.hpp index 1812be84ed892d99be3b4acc56f0138df2d28800..8f25b66d975a9272a8f00a5cc4c08112dacd8a26 100644 --- a/module-services/service-db/agents/settings/SystemSettings.hpp +++ b/module-services/service-db/agents/settings/SystemSettings.hpp @@ -59,4 +59,8 @@ namespace settings constexpr inline auto callsFromFavorites = "off_calls_from_favorites"; } // namespace Offline + namespace KeypadLight + { + constexpr inline auto state = "keypad_light_state"; + } // namespace KeypadLight }; // namespace settings diff --git a/module-services/service-evtmgr/EventManager.cpp b/module-services/service-evtmgr/EventManager.cpp index 94eb37fd8473a73dcfe212414f77fe93a554c94c..e3aaea9729deb5499e12f1981e2feaa288cfe9c6 100644 --- a/module-services/service-evtmgr/EventManager.cpp +++ b/module-services/service-evtmgr/EventManager.cpp @@ -125,6 +125,10 @@ sys::MessagePointer EventManager::DataReceivedHandler(sys::DataMessage *msgl, sy const auto mode = sys::SystemManager::translateSliderState(message->key); bus.sendUnicast(std::make_shared(mode), service::name::system_manager); } + if (keypadLightState == bsp::keypad_backlight::State::activeMode) { + bsp::keypad_backlight::turnOnAll(); + startKeypadLightTimer(); + } } // send key to focused application @@ -379,23 +383,45 @@ void EventManager::handleMinuteUpdate(time_t timestamp) } } -bool EventManager::processKeypadBacklightRequest(bsp::keypad_backlight::Action act) +bool EventManager::processKeypadBacklightRequest(bsp::keypad_backlight::Action action) { bool response = false; - switch (act) { + switch (action) { case bsp::keypad_backlight::Action::turnOn: + if (keypadLightState == bsp::keypad_backlight::State::activeMode) { + keypadLightTimer.stop(); + } + keypadLightState = bsp::keypad_backlight::State::on; response = bsp::keypad_backlight::turnOnAll(); break; case bsp::keypad_backlight::Action::turnOff: + if (keypadLightState == bsp::keypad_backlight::State::activeMode) { + keypadLightTimer.stop(); + } + keypadLightState = bsp::keypad_backlight::State::off; response = bsp::keypad_backlight::shutdown(); break; case bsp::keypad_backlight::Action::checkState: response = bsp::keypad_backlight::checkState(); break; + case bsp::keypad_backlight::Action::turnOnActiveMode: + keypadLightState = bsp::keypad_backlight::State::activeMode; + response = bsp::keypad_backlight::turnOnAll(); + startKeypadLightTimer(); + break; } return response; } +void EventManager::startKeypadLightTimer() +{ + keypadLightTimer = sys::TimerFactory::createSingleShotTimer( + this, keypadLightTimerName, keypadLightTimerTimeout, [this](sys::Timer &) { + bsp::keypad_backlight::shutdown(); + }); + keypadLightTimer.start(); +} + bool EventManager::processVibraRequest(bsp::vibrator::Action act, std::chrono::milliseconds RepetitionTime) { switch (act) { diff --git a/module-services/service-evtmgr/service-evtmgr/EventManager.hpp b/module-services/service-evtmgr/service-evtmgr/EventManager.hpp index c550f81293d5d53afd1dbc6051d17e5d6bc9dc4b..800ee8d48cf17a182ac5434070a2e4359d4f74ce 100644 --- a/module-services/service-evtmgr/service-evtmgr/EventManager.hpp +++ b/module-services/service-evtmgr/service-evtmgr/EventManager.hpp @@ -30,7 +30,8 @@ class EventManager : public sys::Service private: static constexpr auto stackDepth = 4096; void handleMinuteUpdate(time_t timestamp); - bool processKeypadBacklightRequest(bsp::keypad_backlight::Action act); + bool processKeypadBacklightRequest(bsp::keypad_backlight::Action action); + void startKeypadLightTimer(); bool processVibraRequest(bsp::vibrator::Action act, std::chrono::milliseconds RepetitionTime = std::chrono::milliseconds{1000}); void toggleTorchOnOff(); @@ -38,6 +39,11 @@ class EventManager : public sys::Service std::shared_ptr settings; sys::TimerHandle loggerTimer; + sys::TimerHandle keypadLightTimer; + bsp::keypad_backlight::State keypadLightState{bsp::keypad_backlight::State::off}; + + static constexpr auto keypadLightTimerName = "KeypadLightTimer"; + static constexpr auto keypadLightTimerTimeout = std::chrono::seconds(5); protected: std::unique_ptr EventWorker;