~aleteoryx/muditaos

738f50216423f018c6f98b94c7a38a246dd36977 — Lukasz Skrzypczak 4 years ago 1194558
[BH-934] Frontlight intensity live change

Added live frontlight brightness setting
M products/BellHybrid/apps/application-bell-settings/models/FrontlightModel.cpp => products/BellHybrid/apps/application-bell-settings/models/FrontlightModel.cpp +15 -2
@@ 45,8 45,7 @@ namespace app::bell_settings

    void FrontlightModel::createData()
    {
        frontlightSetSpinner =
            new gui::Spinner(fmtSpinnerMin, fmtSpinnerMax, fmtSpinnerStep, gui::Boundaries::Continuous);
        frontlightSetSpinner = new gui::Spinner(fmtSpinnerMin, fmtSpinnerMax, fmtSpinnerStep, gui::Boundaries::Fixed);
        frontlightSetSpinner->setMaximumSize(style::bell_base_layout::w, style::bell_base_layout::h);
        frontlightSetSpinner->setFont(gui::bell_settings_style::time_fmt_set_list_item::font);



@@ 55,6 54,7 @@ namespace app::bell_settings
        frontlightSetSpinner->setFixedFieldWidth(2);
        frontlightSetSpinner->setEdges(gui::RectangleEdge::None);
        frontlightSetSpinner->setCurrentValue(fmtSpinnerMin);
        frontlightSetSpinner->setFixedFieldWidth(0);
        frontlightSetSpinner->setFocusEdges(gui::RectangleEdge::None);
    }



@@ 72,6 72,19 @@ namespace app::bell_settings
        bsp::eink_frontlight::BrightnessPercentage brightnessValue =
            utils::getNumericValue<float>(settings.getValue(brightnessLevel, settings::SettingsScope::Global));
        LOG_DEBUG("Reading frontlight value %0.1f", brightnessValue);
        // prevent showing spinner value less than minimum when database empty
        if (static_cast<unsigned int>(brightnessValue) < fmtSpinnerMin) {
            brightnessValue = static_cast<bsp::eink_frontlight::BrightnessPercentage>(fmtSpinnerMin);
        }
        frontlightSetSpinner->setCurrentValue(static_cast<int>(brightnessValue / 10));
    }

    void FrontlightModel::setLiveBrightness(const int value)
    {
        screenLightSettings->setStatus(true);
        if ((value < static_cast<int>(fmtSpinnerMin)) || (value > static_cast<int>(fmtSpinnerMax))) {
            return;
        }
        screenLightSettings->setBrightness(static_cast<float>(value * 10));
    }
} // namespace app::bell_settings

M products/BellHybrid/apps/application-bell-settings/models/FrontlightModel.hpp => products/BellHybrid/apps/application-bell-settings/models/FrontlightModel.hpp +1 -0
@@ 24,6 24,7 @@ namespace app::bell_settings
        auto createData() -> void;

        [[nodiscard]] auto getSpinner() -> gui::Spinner *;
        auto setLiveBrightness(const int value) -> void;

      private:
        app::ApplicationCommon *application                                  = nullptr;

M products/BellHybrid/apps/application-bell-settings/windows/BellSettingsFrontlight.cpp => products/BellHybrid/apps/application-bell-settings/windows/BellSettingsFrontlight.cpp +11 -0
@@ 59,6 59,17 @@ namespace gui

    bool BellSettingsFrontlightWindow::onInput(const gui::InputEvent &inputEvent)
    {
        // this has to be first because body->oninput() catches those keycodes for itself
        // also because of body->oninput() sends keypresses to spinner, it's value is updated *after* frontlight
        // brightness set so proper +1 -1 has to be added to to set brightness level corresponding to screen indicator
        if (inputEvent.isShortRelease(KeyCode::KEY_UP)) {
            auto value = presenter->getPagesProvider()->getSpinner()->getCurrentValue();
            presenter->getPagesProvider()->setLiveBrightness(value + 1);
        }
        else if (inputEvent.isShortRelease(KeyCode::KEY_DOWN)) {
            auto value = presenter->getPagesProvider()->getSpinner()->getCurrentValue();
            presenter->getPagesProvider()->setLiveBrightness(value - 1);
        }
        if (body->onInput(inputEvent)) {
            return true;
        }

M products/BellHybrid/services/evtmgr/EventManager.cpp => products/BellHybrid/services/evtmgr/EventManager.cpp +1 -1
@@ 52,7 52,7 @@ void EventManager::handleKeyEvent(sys::Message *msg)
    }

    if (kbdMessage->key.state == RawKey::State::Pressed) {
        backlightHandler.handleKeyPressed(static_cast<int>(static_cast<gui::KeyCode>(kbdMessage->key.keyCode)));
        backlightHandler.handleKeyPressed(static_cast<int>(mapKey(static_cast<gui::KeyCode>(kbdMessage->key.keyCode))));
    }

    keySequenceMgr->process(kbdMessage->key);