From 86e8369781919bcbf7b555f283141ec18c52b69b Mon Sep 17 00:00:00 2001 From: "Pawel.Paprocki" Date: Tue, 23 Mar 2021 19:29:06 +0100 Subject: [PATCH] [EGD-6263] Add automatic linear brightness Linear automatic backlight controller - part1 --- .../ApplicationSettings.cpp | 9 ++++++++ .../ApplicationSettings.hpp | 2 ++ .../windows/DisplayLightWindow.cpp | 22 ++++++++++++------- .../windows/DisplayLightWindow.hpp | 4 +++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index 7f8d752c7aedae29601a28900a271a0457594b1e..cde3dcb2741d400d49e9902d9a14a1580e78a169 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -597,6 +597,15 @@ namespace app : screen_light_control::Action::turnOff), service::name::evt_manager); } + void ApplicationSettingsNew::setBrightnessFunction() + { + screen_light_control::Parameters parameters; + parameters.functionPoints = + screen_light_control::functions::BrightnessFunction({{0.0f, 0.0f}, {1000.0f, 100.0f}}); + bus.sendUnicast(std::make_shared( + screen_light_control::Action::setAutomaticModeParameters, parameters), + service::name::evt_manager); + } auto ApplicationSettingsNew::isKeypadBacklightOn() -> bool { diff --git a/module-apps/application-settings-new/ApplicationSettings.hpp b/module-apps/application-settings-new/ApplicationSettings.hpp index 524777c0d7f651a53dddc32058e8a5c1ffe3b2ad..b2b8bdfe7e6e4a92384ecef9df9c7ec20ffd5546 100644 --- a/module-apps/application-settings-new/ApplicationSettings.hpp +++ b/module-apps/application-settings-new/ApplicationSettings.hpp @@ -111,6 +111,7 @@ namespace app virtual void setBrightness(float brigtnessValue) = 0; virtual void setMode(bool isAutoLightSwitchOn) = 0; virtual void setStatus(bool isDisplayLightSwitchOn) = 0; + virtual void setBrightnessFunction() = 0; }; class KeypdBacklightSettings @@ -204,6 +205,7 @@ namespace app void setBrightness(float brigtnessValue) override; void setMode(bool isAutoLightSwitchOn) override; void setStatus(bool isDisplayLightSwitchOn) override; + void setBrightnessFunction() override; auto isKeypadBacklightOn() -> bool override; void setKeypadBacklightState(bool newState) override; diff --git a/module-apps/application-settings-new/windows/DisplayLightWindow.cpp b/module-apps/application-settings-new/windows/DisplayLightWindow.cpp index a4ea591947cce3ab088f4b54dfaf7024406d8773..49467b7060a26090a02bfa32b5d75bd55e342e81 100644 --- a/module-apps/application-settings-new/windows/DisplayLightWindow.cpp +++ b/module-apps/application-settings-new/windows/DisplayLightWindow.cpp @@ -23,6 +23,8 @@ namespace gui setTitle(utils::localize.get("app_settings_display_display_light")); + screenLightSettings->setBrightnessFunction(); + timerCallback = [this](Item &it, sys::Timer &task) { return onTimerTimeout(it, task); }; timerTask = app::GuiTimerFactory::createPeriodicTimer( application, this, "AmbientLightTimer", std::chrono::milliseconds{gui::lighting::AMBIENT_LIGHT_TIMER_MS}); @@ -39,6 +41,8 @@ namespace gui auto DisplayLightWindow::onTimerTimeout(Item &self, sys::Timer &task) -> bool { ambientLight = bsp::light_sensor::readout(); + auto values = screenLightSettings->getCurrentValues(); + brightnessValue = values.parameters.manualModeBrightness; refreshOptionsList(); application->refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); @@ -82,6 +86,11 @@ namespace gui text, nullptr, nullptr, this, gui::option::SettingRightItem::Disabled)); }; + auto addBrightnessValue = [&](UTF8 text) { + optionsList.emplace_back(std::make_unique( + text, nullptr, nullptr, this, gui::option::SettingRightItem::Disabled)); + }; + addOnOffOoption(utils::translateI18("app_settings_display_light_main"), isDisplayLightSwitchOn); if (isDisplayLightSwitchOn) { addOnOffOoption(utils::translateI18("app_settings_display_light_auto"), isAutoLightSwitchOn); @@ -92,6 +101,8 @@ namespace gui } addDisplayLight("Light intensity = " + utils::to_string(ambientLight)); + addBrightnessValue("Manual brightness = " + utils::to_string(brightnessValue) + "%"); + return optionsList; } @@ -110,8 +121,8 @@ namespace gui }; auto spinner = std::make_unique( - utils::translateI18("app_settings_display_light_brightness") + " " + utils::to_string(brightnessStep), - brightnessValue * brightnessStep, + utils::translateI18("app_settings_display_light_brightness"), + std::ceil(brightnessValue / brightnessStep), std::ceil(screen_light_control::Parameters::MAX_BRIGHTNESS / brightnessStep), setBrightness, setBottomBarOnSpinnerFocus); @@ -121,11 +132,6 @@ namespace gui void DisplayLightWindow::addBrightnessOption(std::list &options) { - /* - * We are adding 4 brightness widgets to easily check what is the best step for setting screen brightness. - */ - for (auto step : {10, 15, 20, 25}) { - options.emplace_back(createBrightnessOption(step)); - } + options.emplace_back(createBrightnessOption(lighting::LIGHT_CONTROL_STEP)); } } // namespace gui diff --git a/module-apps/application-settings-new/windows/DisplayLightWindow.hpp b/module-apps/application-settings-new/windows/DisplayLightWindow.hpp index e997585dbd53f16713221d6c1aae72bdf4fd9ff7..3e606378633473faaf71c76fbe17de311ee81976 100644 --- a/module-apps/application-settings-new/windows/DisplayLightWindow.hpp +++ b/module-apps/application-settings-new/windows/DisplayLightWindow.hpp @@ -15,6 +15,7 @@ namespace gui namespace lighting { constexpr inline auto AMBIENT_LIGHT_TIMER_MS = 2000; + constexpr inline auto LIGHT_CONTROL_STEP = 10; } class DisplayLightWindow : public BaseSettingsWindow @@ -31,7 +32,8 @@ namespace gui auto createBrightnessOption(int step) -> std::unique_ptr; bool isDisplayLightSwitchOn = false; bool isAutoLightSwitchOn = false; - std::uint8_t brightnessValue = 0; + bsp::eink_frontlight::BrightnessPercentage brightnessValue = 0.0; + app::settingsInterface::ScreenLightSettings *screenLightSettings = nullptr; float ambientLight = 0.0; sys::TimerHandle timerTask;