~aleteoryx/muditaos

7519663b9af6c2d7c18c97a0098014f1fe236ac5 — pawpMudita 5 years ago 6befeb5
[EGD-5315] Add ambient light gauge to DisplayLightWindow

Temprary solution to make an experiment.
Ambient light level displayed each 2 seconds in order
to measure lighting curve.
M module-apps/application-settings-new/windows/DisplayLightWindow.cpp => module-apps/application-settings-new/windows/DisplayLightWindow.cpp +28 -0
@@ 6,6 6,7 @@
#include "OptionSetting.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "OptionSetting.hpp"
#include "GuiTimer.hpp"

#include <service-evtmgr/screen-light-control/ScreenLightControl.hpp>
#include <i18n/i18n.hpp>


@@ 23,6 24,27 @@ namespace gui
        brightnessValue        = values.parameters.manualModeBrightness;

        setTitle(utils::localize.get("app_settings_display_display_light"));

        timerTask = std::make_unique<app::GuiTimer>(
            "AmbientLightTimer", application, gui::lighting::AMBIENT_LIGHT_TIMER_MS, Timer::Type::Continous);
        timerCallback = [this](Item &it, Timer &task) { return onTimerTimeout(it, task); };
        timerTask->start();
        application->connect(std::move(timerTask), this);
    }

    DisplayLightWindow::~DisplayLightWindow()
    {
        if (timerTask != nullptr) {
            timerTask->stop();
        }
    }

    auto DisplayLightWindow::onTimerTimeout(Item &self, Timer &task) -> bool
    {
        ambientLight = bsp::light_sensor::readout();
        rebuildOptionList();
        application->refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
        return true;
    }

    void DisplayLightWindow::switchHandler(bool &onOffSwitch)


@@ 57,6 79,11 @@ namespace gui
                toggle ? gui::option::SettingRightItem::On : gui::option::SettingRightItem::Off));
        };

        auto addDisplayLight = [&](UTF8 text) {
            optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                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);


@@ 66,6 93,7 @@ namespace gui
            addBrightnessOption(optionsList);
        }

        addDisplayLight("Light intensity = " + utils::to_string(ambientLight));
        return optionsList;
    }


M module-apps/application-settings-new/windows/DisplayLightWindow.hpp => module-apps/application-settings-new/windows/DisplayLightWindow.hpp +9 -1
@@ 11,10 11,16 @@

namespace gui
{
    namespace lighting
    {
        constexpr inline auto AMBIENT_LIGHT_TIMER_MS = 2000;
    }

    class DisplayLightWindow : public BaseSettingsWindow
    {
      public:
        DisplayLightWindow(app::Application *app, app::settingsInterface::ScreenLightSettings *screenLightSettings);
        ~DisplayLightWindow();

      private:
        auto buildOptionsList() -> std::list<Option> override;


@@ 22,10 28,12 @@ namespace gui

        void addBrightnessOption(std::list<Option> &);
        auto createBrightnessOption(int step) -> std::unique_ptr<SpinBoxOptionSettings>;

        bool isDisplayLightSwitchOn                                      = false;
        bool isAutoLightSwitchOn                                         = false;
        std::uint8_t brightnessValue                                     = 0;
        app::settingsInterface::ScreenLightSettings *screenLightSettings = nullptr;
        float ambientLight                                               = 0.0;
        std::unique_ptr<app::GuiTimer> timerTask;
        [[nodiscard]] auto onTimerTimeout(Item &self, Timer &task) -> bool;
    };
} // namespace gui