~aleteoryx/muditaos

01d1c84f25dffd88b2757c1216d2d7c731c9b7e6 — Wojtek Rzepecki 5 years ago d4d7c1c
[EGD-5390] Add keypad backlight to GUI

Added demo connection to keypad light
GUI window.
M module-apps/application-settings-new/ApplicationSettings.cpp => module-apps/application-settings-new/ApplicationSettings.cpp +32 -1
@@ 51,6 51,7 @@
#include <i18n/i18n.hpp>
#include <module-services/service-evtmgr/service-evtmgr/ScreenLightControlMessage.hpp>
#include <module-services/service-evtmgr/service-evtmgr/Constants.hpp>
#include <module-services/service-evtmgr/service-evtmgr/EVMessages.hpp>
#include <module-services/service-appmgr/service-appmgr/messages/Message.hpp>
#include <module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp>



@@ 219,7 220,7 @@ namespace app
            return std::make_unique<gui::LockedScreenWindow>(app);
        });
        windowsFactory.attach(gui::window::name::keypad_light, [](Application *app, const std::string &name) {
            return std::make_unique<gui::KeypadLightWindow>(app);
            return std::make_unique<gui::KeypadLightWindow>(app, static_cast<ApplicationSettingsNew *>(app));
        });
        windowsFactory.attach(gui::window::name::font_size, [](Application *app, const std::string &name) {
            return std::make_unique<gui::FontSizeWindow>(app);


@@ 389,4 390,34 @@ namespace app
            this);
    }

    auto ApplicationSettingsNew::isKeypadBacklightOn() -> bool
    {
        constexpr int timeout = pdMS_TO_TICKS(1500);

        auto response = sys::Bus::SendUnicast(
            std::make_shared<sevm::KeypadBacklightMessage>(bsp::keypad_backlight::Action::checkState),
            service::name::evt_manager,
            this,
            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;
    }

    void ApplicationSettingsNew::setKeypadBacklightState(bool newState)
    {
        sys::Bus::SendUnicast(
            std::make_shared<sevm::KeypadBacklightMessage>(newState ? bsp::keypad_backlight::Action::turnOn
                                                                    : bsp::keypad_backlight::Action::turnOff),
            service::name::evt_manager,
            this);
    }

} /* namespace app */

M module-apps/application-settings-new/ApplicationSettings.hpp => module-apps/application-settings-new/ApplicationSettings.hpp +14 -1
@@ 99,12 99,22 @@ namespace app
            virtual void setMode(bool isAutoLightSwitchOn)      = 0;
            virtual void setStatus(bool isDisplayLightSwitchOn) = 0;
        };

        class KeypdBacklightSettings
        {
          public:
            virtual ~KeypdBacklightSettings()                   = default;
            virtual auto isKeypadBacklightOn() -> bool          = 0;
            virtual void setKeypadBacklightState(bool newState) = 0;
        };

    }; // namespace settingsInterface

    class ApplicationSettingsNew : public app::Application,
                                   public settingsInterface::SimParams,
                                   public settingsInterface::OperatorsSettings,
                                   public settingsInterface::ScreenLightSettings
                                   public settingsInterface::ScreenLightSettings,
                                   public settingsInterface::KeypdBacklightSettings
    {
      public:
        ApplicationSettingsNew(std::string name                    = name_settings_new,


@@ 142,6 152,9 @@ namespace app
        void setMode(bool isAutoLightSwitchOn) override;
        void setStatus(bool isDisplayLightSwitchOn) override;

        auto isKeypadBacklightOn() -> bool override;
        void setKeypadBacklightState(bool newState) override;

      private:
        void attachQuotesWindows();


M module-apps/application-settings-new/windows/KeypadLightWindow.cpp => module-apps/application-settings-new/windows/KeypadLightWindow.cpp +11 -2
@@ 11,8 11,17 @@
namespace gui
{

    KeypadLightWindow::KeypadLightWindow(app::Application *app) : BaseSettingsWindow(app, window::name::keypad_light)
    KeypadLightWindow::KeypadLightWindow(app::Application *app,
                                         app::settingsInterface::KeypdBacklightSettings *settings)
        : BaseSettingsWindow(app, window::name::keypad_light), keypadLightSettings(settings)
    {
        if (keypadLightSettings->isKeypadBacklightOn()) {
            isAlwaysOnSwitchOn = true;
        }
        else {
            isOffSwitchOn = true;
        }

        setTitle(utils::localize.get("app_settings_display_keypad_light"));
    }



@@ 21,9 30,9 @@ namespace gui
        isActiveSwitchOn   = false;
        isOffSwitchOn      = false;
        isAlwaysOnSwitchOn = false;

        toggleSwitch = !toggleSwitch;
        rebuildOptionList();
        keypadLightSettings->setKeypadBacklightState(isAlwaysOnSwitchOn);
    }

    auto KeypadLightWindow::buildOptionsList() -> std::list<gui::Option>

M module-apps/application-settings-new/windows/KeypadLightWindow.hpp => module-apps/application-settings-new/windows/KeypadLightWindow.hpp +3 -1
@@ 4,15 4,17 @@
#pragma once

#include "BaseSettingsWindow.hpp"
#include <module-apps/application-settings-new/ApplicationSettings.hpp>

namespace gui
{
    class KeypadLightWindow : public BaseSettingsWindow
    {
      public:
        KeypadLightWindow(app::Application *app);
        KeypadLightWindow(app::Application *app, app::settingsInterface::KeypdBacklightSettings *settings);

      private:
        app::settingsInterface::KeypdBacklightSettings *keypadLightSettings;
        void switchHandler(bool &onOffSwitch);
        std::list<Option> buildOptionsList() override;


M module-bsp/board/rt1051/bsp/keypad_backlight/keypad_backlight.cpp => module-bsp/board/rt1051/bsp/keypad_backlight/keypad_backlight.cpp +50 -6
@@ 9,6 9,7 @@

#include "fsl_common.h"
#include <array>
#include <cmath>

extern "C"
{


@@ 26,10 27,41 @@ namespace bsp::keypad_backlight

        drivers::I2CAddress addr = {.deviceAddress = static_cast<uint32_t>(LP55281_DEVICE_ADDR), .subAddressSize = 1};

        constexpr std::array<LP55281_Registers, 4> usedOutputs = {LP55281_Registers::RED2,    // Red right button
                                                                  LP55281_Registers::GREEN3,  // Green left button
                                                                  LP55281_Registers::RED4,    // Keypad right side
                                                                  LP55281_Registers::GREEN4}; // Keypad left side
        constexpr auto rgbChannelsNum = 3;

        constexpr std::array<LP55281_Registers, 8> usedChannels = {LP55281_Registers::RED2,
                                                                   LP55281_Registers::GREEN2,
                                                                   LP55281_Registers::BLUE2,
                                                                   LP55281_Registers::RED2,
                                                                   LP55281_Registers::GREEN2,
                                                                   LP55281_Registers::BLUE2,
                                                                   LP55281_Registers::RED4,
                                                                   LP55281_Registers::GREEN4};

        constexpr std::array<LP55281_Registers, 2> usedSingleOutputs = {LP55281_Registers::RED4,    // Keypad right side
                                                                        LP55281_Registers::GREEN4}; // Keypad left side

        constexpr auto gammaFactor = 2.8f;
        constexpr DiodeIntensity gammaCorrection(std::uint8_t brightness8bit)
        {
            float brightness = static_cast<float>(brightness8bit) / 255.0f;
            std::clamp(brightness, 0.0f, 1.0f);
            return std::pow(brightness, gammaFactor);
        }

        using SingleDiode = std::pair<LP55281_Registers, DiodeIntensity>;
        using RGBdiode    = std::array<SingleDiode, rgbChannelsNum>;

        // Channels intesivity according to design specification
        constexpr RGBdiode rightRed = {
            std::make_pair(LP55281_Registers::RED2, gammaCorrection(255)), // Red right button
            std::make_pair(LP55281_Registers::GREEN2, gammaCorrection(68)),
            std::make_pair(LP55281_Registers::BLUE2, gammaCorrection(90))};

        constexpr RGBdiode leftGreen = {
            std::make_pair(LP55281_Registers::RED3, gammaCorrection(47)), // Green left button
            std::make_pair(LP55281_Registers::GREEN3, gammaCorrection(255)),
            std::make_pair(LP55281_Registers::BLUE3, gammaCorrection(137))};

        bool writeSingleRegister(std::uint32_t address, std::uint8_t *to_send)
        {


@@ 84,12 116,24 @@ namespace bsp::keypad_backlight
        wakeup();
        configureModule();

        for (auto &diode : usedOutputs) {
        for (auto &diode : usedSingleOutputs) {
            std::uint32_t address = static_cast<std::uint32_t>(diode);
            if (!writeSingleRegister(address, reinterpret_cast<std::uint8_t *>(&diode_reg))) {
                return false;
            }
        }

        std::vector<const RGBdiode *> rgbDiodes = {&rightRed, &leftGreen};
        for (const auto &diodes : rgbDiodes) {
            for (const auto &diode : *diodes) {
                std::uint32_t address = static_cast<std::uint32_t>(diode.first);
                diode_reg.current     = encode_diode_brightness_to_6bits(diode.second);
                if (!writeSingleRegister(address, reinterpret_cast<std::uint8_t *>(&diode_reg))) {
                    return false;
                }
            }
        }

        return true;
    }



@@ 129,7 173,7 @@ namespace bsp::keypad_backlight
    bool checkState()
    {
        std::uint8_t value = 0;
        for (const auto diode : usedOutputs) {
        for (const auto diode : usedChannels) {
            value = static_cast<std::uint8_t>(diode) | EN_LED_TEST;

            if (!writeSingleRegister(static_cast<std::uint32_t>(LP55281_Registers::LED_TEST), &value)) {

M module-services/service-evtmgr/EventManager.cpp => module-services/service-evtmgr/EventManager.cpp +1 -1
@@ 257,7 257,7 @@ sys::ReturnCodes EventManager::InitHandler()
        return std::make_shared<sys::ResponseMessage>();
    });

    connect(sevm::KeypadBacklightMessage(), [&](sys::Message *msgl) {
    connect(sevm::KeypadBacklightMessage(bsp::keypad_backlight::Action::turnOff), [&](sys::Message *msgl) {
        auto request      = static_cast<sevm::KeypadBacklightMessage *>(msgl);
        auto response     = std::make_shared<sevm::KeypadBacklightResponseMessage>();
        response->success = processKeypadBacklightRequest(request->action);

M module-services/service-evtmgr/service-evtmgr/EVMessages.hpp => module-services/service-evtmgr/service-evtmgr/EVMessages.hpp +4 -4
@@ 125,19 125,19 @@ namespace sevm
        bool success = false;
    };

    class KeypadBacklightMessage : public Message
    class KeypadBacklightMessage : public sys::Message
    {
      public:
        KeypadBacklightMessage() : Message(MessageType::EVMKeypadBacklightMessage)
        explicit KeypadBacklightMessage(bsp::keypad_backlight::Action action) : action(action)
        {}

        bsp::keypad_backlight::Action action;
    };

    class KeypadBacklightResponseMessage : public KeypadBacklightMessage
    class KeypadBacklightResponseMessage : public sys::Message
    {
      public:
        KeypadBacklightResponseMessage() : KeypadBacklightMessage()
        KeypadBacklightResponseMessage()
        {}
        bool success;
    };

M source/MessageType.hpp => source/MessageType.hpp +0 -2
@@ 175,8 175,6 @@ enum class MessageType
    EVMTimeUpdated,   ///< This message is send on every time update.
    // Torch messages
    EVMTorchStateMessage,
    // Keypad backlight control messages
    EVMKeypadBacklightMessage,

    // cellular messages
    EVMGetBoard,