~aleteoryx/muditaos

39be35722da1bb602b537ae415af82fb795c5ea8 — Mateusz Grzegorzek 5 years ago 03e5f8d
[EGD-6505] Implement “On when active” Keypad light functionality

Implement “On when active” Keypad light functionality
M image/user/db/settings_v2_002.sql => image/user/db/settings_v2_002.sql +2 -3
@@ 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');

M module-apps/Application.cpp => module-apps/Application.cpp +0 -1
@@ 901,5 901,4 @@ namespace app
    {
        return lockScreenPasscodeIsOn;
    }

} /* namespace app */

M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +8 -21
@@ 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<sevm::KeypadBacklightMessage>(bsp::keypad_backlight::Action::checkState),
                            service::name::evt_manager,
                            timeout);

        if (response.first == sys::ReturnCodes::Success) {
            auto msgState = dynamic_cast<sevm::KeypadBacklightResponseMessage *>(response.second.get());
            if (msgState == nullptr) {
                return false;
            }

            return msgState->success;
        }
        return false;
        return static_cast<bsp::keypad_backlight::State>(utils::getNumericValue<int>(
            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<sevm::KeypadBacklightMessage>(
                            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<int>(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;

M module-apps/application-settings-new/ApplicationSettings.hpp => module-apps/application-settings-new/ApplicationSettings.hpp +6 -5
@@ 6,6 6,7 @@
#include "Application.hpp"

#include <bsp/common.hpp>
#include <bsp/keypad_backlight/keypad_backlight.hpp>
#include <module-services/service-evtmgr/screen-light-control/ScreenLightControl.hpp>
#include <common_data/EventStore.hpp>



@@ 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;

M module-apps/application-settings-new/windows/KeypadLightWindow.cpp => module-apps/application-settings-new/windows/KeypadLightWindow.cpp +22 -7
@@ 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 <application-settings-new/ApplicationSettings.hpp>
#include <OptionSetting.hpp>

#include <bsp/keypad_backlight/keypad_backlight.hpp>
#include <i18n/i18n.hpp>

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<gui::Option>

M module-bsp/bsp/keypad_backlight/keypad_backlight.hpp => module-bsp/bsp/keypad_backlight/keypad_backlight.hpp +9 -1
@@ 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();

M module-services/service-appmgr/model/ApplicationManager.cpp => module-services/service-appmgr/model/ApplicationManager.cpp +26 -1
@@ 21,6 21,7 @@
#include <log/log.hpp>
#include <service-appmgr/messages/Message.hpp>
#include <service-evtmgr/EventManager.hpp>
#include <service-evtmgr/EVMessages.hpp>
#include <service-gui/ServiceGUI.hpp>
#include <service-eink/ServiceEink.hpp>
#include <service-gui/Common.hpp>


@@ 30,7 31,6 @@
#include <algorithm>
#include <limits>
#include <utility>

#include <module-utils/Utils.hpp>
#include <module-utils/time/DateAndTimeSettings.hpp>
#include <module-services/service-db/agents/settings/SystemSettings.hpp>


@@ 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<bsp::keypad_backlight::State>(utils::getNumericValue<int>(value));
                processKeypadBacklightState(keypadLightState);
            },
            ::settings::SettingsScope::Global);

        startBackgroundApplications();
        bus.sendUnicast(std::make_unique<CheckIfStartAllowedMessage>(), service::name::system_manager);



@@ 1018,4 1027,20 @@ namespace app::manager
        return std::make_shared<sys::ResponseMessage>(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<sevm::KeypadBacklightMessage>(action), service::name::evt_manager);
    }
} // namespace app::manager

M module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp => module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +3 -0
@@ 10,6 10,7 @@
#include <module-apps/Application.hpp>
#include <module-apps/ApplicationLauncher.hpp>

#include <bsp/keypad_backlight/keypad_backlight.hpp>
#include <service-appmgr/messages/Message.hpp>
#include <Service/Common.hpp>
#include <Service/Message.hpp>


@@ 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


M module-services/service-db/agents/settings/SystemSettings.hpp => module-services/service-db/agents/settings/SystemSettings.hpp +4 -0
@@ 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

M module-services/service-evtmgr/EventManager.cpp => module-services/service-evtmgr/EventManager.cpp +28 -2
@@ 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<sys::PhoneModeRequest>(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) {

M module-services/service-evtmgr/service-evtmgr/EventManager.hpp => module-services/service-evtmgr/service-evtmgr/EventManager.hpp +7 -1
@@ 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::Settings> 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<WorkerEvent> EventWorker;