~aleteoryx/muditaos

9ae8d0f1566ef358cf29289a75825a1a4c4e8b8c — Pawel.Paprocki 4 years ago d066f87
[EGD-6313] Fix Display backlight settings are not presistent

Add global scope to settings db function calls
M image/user/db/settings_v2_002.sql => image/user/db/settings_v2_002.sql +3 -0
@@ 33,4 33,7 @@ INSERT OR IGNORE INTO settings_tab (path, value) VALUES
    ('off_connection_frequency', '0'),
    ('off_notifications_when_locked', '0'),
    ('off_calls_from_favorites', '0'),
    ('br_state', '0'),
    ('br_auto_mode', '0'),
    ('br_level', '50.0f'),
    ('keypad_light_state', '0');

M module-services/service-evtmgr/screen-light-control/ScreenLightControl.cpp => module-services/service-evtmgr/screen-light-control/ScreenLightControl.cpp +30 -44
@@ 10,28 10,6 @@

namespace screen_light_control
{
    namespace
    {
        auto from_string(const std::string &str, bool def) -> bool
        {
            try {
                return std::stoi(str) == 0;
            }
            catch (std::exception &) {
                return def;
            }
        }

        auto from_string(const std::string &str, float def) -> float
        {
            try {
                return std::stof(str);
            }
            catch (std::exception &) {
                return def;
            }
        }
    } // namespace

    ScreenLightControl::ScreenLightControl(std::shared_ptr<settings::Settings> settings, sys::Service *parent)
        : settings(settings)


@@ 54,26 32,34 @@ namespace screen_light_control

    void ScreenLightControl::initFromSettings()
    {
        settings->registerValueChange(settings::Brightness::brightnessLevel,
                                      [&](const std::string &value) { setBrightnessLevel(from_string(value, 0.0f)); });

        settings->registerValueChange(settings::Brightness::autoMode, [&](const std::string &value) {
            if (from_string(value, false)) {
                enableAutomaticMode();
            }
            else {
                disableAutomaticMode();
            }
        });

        settings->registerValueChange(settings::Brightness::autoMode, [&](const std::string &value) {
            if (from_string(value, false)) {
                turnOn();
            }
            else {
                turnOff();
            }
        });
        settings->registerValueChange(
            settings::Brightness::brightnessLevel,
            [&](const std::string &value) { setBrightnessLevel(utils::getNumericValue<float>(value)); },
            settings::SettingsScope::Global);

        settings->registerValueChange(
            settings::Brightness::autoMode,
            [&](const std::string &value) {
                if (utils::getNumericValue<bool>(value)) {
                    enableAutomaticMode();
                }
                else {
                    disableAutomaticMode();
                }
            },
            settings::SettingsScope::Global);

        settings->registerValueChange(
            settings::Brightness::state,
            [&](const std::string &value) {
                if (utils::getNumericValue<bool>(value)) {
                    turnOn();
                }
                else {
                    turnOff();
                }
            },
            settings::SettingsScope::Global);
    }

    void ScreenLightControl::processRequest(Action action, const Parameters &params)


@@ 89,11 75,11 @@ namespace screen_light_control
            break;
        case Action::enableAutomaticMode:
            enableAutomaticMode();
            setScreenLightSettings(settings::Brightness::autoMode, automaticMode);
            setScreenLightSettings(settings::Brightness::autoMode, automaticMode == ScreenLightMode::Automatic);
            break;
        case Action::disableAutomaticMode:
            disableAutomaticMode();
            setScreenLightSettings(settings::Brightness::autoMode, automaticMode);
            setScreenLightSettings(settings::Brightness::autoMode, automaticMode == ScreenLightMode::Automatic);
            break;
        case Action::setManualModeBrightness:
            setBrightnessLevel(params.manualModeBrightness);

M module-services/service-evtmgr/screen-light-control/ScreenLightControl.hpp => module-services/service-evtmgr/screen-light-control/ScreenLightControl.hpp +1 -1
@@ 80,7 80,7 @@ namespace screen_light_control

        template <class T> void setScreenLightSettings(const std::string &varName, T value)
        {
            settings->setValue(varName, utils::to_string(value));
            settings->setValue(varName, utils::to_string(value), settings::SettingsScope::Global);
        }
        void initFromSettings();