~aleteoryx/muditaos

d63d460133cbe0e4b3c1c1d00664f3f4bf7f8d98 — Dawid Wojtas 3 years ago 9b7d5be
[BH-1574] Add bedside lamp feature

To activate the bedside lamp the user needs to hold
the frontlight button for approximately 3 seconds.
The bedside lamp turns off after 10 minutes or
after pressing frontlight button.
M harmony_changelog.md => harmony_changelog.md +3 -0
@@ 13,6 13,9 @@
* New circular progress bar 
* Ringing bell image at the end of the Power Nap

#### General:
* Bedside lamp mode

## [1.6.0 2022-06-14]

### Added

M products/BellHybrid/services/evtmgr/CMakeLists.txt => products/BellHybrid/services/evtmgr/CMakeLists.txt +2 -0
@@ 17,6 17,8 @@ target_sources(evtmgr
        internal/key_sequences/AbstractKeySequence.hpp
        internal/key_sequences/KeySequenceMgr.hpp
        internal/key_sequences/PowerOffSequence.hpp
        internal/key_sequences/BedsideLampSequence.hpp
        internal/key_sequences/FrontlightSequence.hpp
        internal/key_sequences/AlarmActivateSequence.hpp
        internal/key_sequences/AlarmDeactivateSequence.hpp
        internal/key_sequences/ReleaseSequence.hpp

M products/BellHybrid/services/evtmgr/EventManager.cpp => products/BellHybrid/services/evtmgr/EventManager.cpp +10 -0
@@ 5,6 5,8 @@
#include "internal/StaticData.hpp"
#include "internal/key_sequences/KeySequenceMgr.hpp"
#include "internal/key_sequences/PowerOffSequence.hpp"
#include "internal/key_sequences/BedsideLampSequence.hpp"
#include "internal/key_sequences/FrontlightSequence.hpp"
#include "internal/key_sequences/AlarmActivateSequence.hpp"
#include "internal/key_sequences/AlarmDeactivateSequence.hpp"
#include "internal/key_sequences/ResetSequence.hpp"


@@ 145,6 147,14 @@ void EventManager::buildKeySequences()
{
    KeySequenceMgr::SequenceCollection collection;

    auto frontlightSeq      = std::make_unique<FrontlightSequence>(*this);
    frontlightSeq->onAction = [this]() { backlightHandler.handleScreenLight(backlight::Type::Frontlight); };
    collection.emplace_back(std::move(frontlightSeq));

    auto bedsideLampSeq      = std::make_unique<BedsideLampSequence>(*this);
    bedsideLampSeq->onAction = [this]() { backlightHandler.handleScreenLight(backlight::Type::BedsideLamp); };
    collection.emplace_back(std::move(bedsideLampSeq));

    auto powerOffSeq      = std::make_unique<PowerOffSequence>(*this);
    powerOffSeq->onAction = [this]() {
        app::manager::Controller::sendAction(

M products/BellHybrid/services/evtmgr/backlight-handler/BacklightHandler.cpp => products/BellHybrid/services/evtmgr/backlight-handler/BacklightHandler.cpp +43 -17
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <evtmgr/backlight-handler/BacklightHandler.hpp>


@@ 15,8 15,9 @@ namespace backlight
{
    namespace timers
    {
        constexpr auto screenLightTimerTimeout     = std::chrono::seconds(5);
        constexpr auto screenLightTimerHoldTimeout = std::chrono::seconds(10);
        constexpr auto screenLightTimerTimeout       = std::chrono::seconds(5);
        constexpr auto screenLightTimerHoldTimeout   = std::chrono::seconds(10);
        constexpr auto screenLightBedsideLampTimeout = std::chrono::minutes(10);
    } // namespace timers

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


@@ 25,6 26,9 @@ namespace backlight
                        parent,
                        [this](sys::Timer &t) {
                            if (this->screenLightController->isLightOn()) {
                                if (backlightType == Type::BedsideLamp) {
                                    backlightType = Type::Frontlight;
                                }
                                this->screenLightController->processRequest(screen_light_control::Action::turnOff);
                            }
                        })


@@ 53,19 57,7 @@ namespace backlight
        auto controller = getScreenLightControl();
        auto timer      = getScreenLightTimer();

        if (key == static_cast<int>(KeyMap::Frontlight)) {
            if (controller->isLightOn()) {
                setKeyPressedModeFrontlightOff();
                controller->processRequest(screen_light_control::Action::turnOff);
                timer->stop();
            }
            else {
                setKeyPressedModeFrontlightOn();
                controller->processRequest(screen_light_control::Action::turnOn);
                timer->restart(onDemandModeOn ? timers::screenLightTimerTimeout : timers::screenLightTimerHoldTimeout);
            }
        }
        else {
        if (key != static_cast<int>(KeyMap::Frontlight) && backlightType != Type::BedsideLamp) {
            if (controller->isLightOn()) {
                timer->restart(timers::screenLightTimerHoldTimeout);
            }


@@ 77,6 69,40 @@ namespace backlight
        }
    }

    void Handler::handleScreenLight(Type type)
    {
        const auto controller = getScreenLightControl();
        const auto timer      = getScreenLightTimer();

        auto lightTime = std::chrono::seconds(0);

        switch (type) {
        case Type::Frontlight:
            if (onDemandModeOn) {
                lightTime = timers::screenLightTimerTimeout;
            }
            else {
                lightTime = timers::screenLightTimerHoldTimeout;
            }
            break;
        case Type::BedsideLamp:
            lightTime = timers::screenLightBedsideLampTimeout;
            break;
        }

        if (controller->isLightOn() && type == Type::Frontlight) {
            setKeyPressedModeFrontlightOff();
            controller->processRequest(screen_light_control::Action::turnOff);
            timer->stop();
        }
        else if (!controller->isLightOn()) {
            setKeyPressedModeFrontlightOn();
            controller->processRequest(screen_light_control::Action::turnOn);
            timer->restart(lightTime);
        }
        backlightType = type;
    }

    void Handler::processScreenRequest(screen_light_control::Action action,
                                       const screen_light_control::Parameters &params)
    {


@@ 126,7 152,7 @@ namespace backlight

    void Handler::onScreenLightTurnedOn()
    {
        if (backlightMode == BacklightMode::WithTimer) {
        if (backlightMode == BacklightMode::WithTimer && backlightType != Type::BedsideLamp) {
            startScreenLightTimer();
        }
    }

M products/BellHybrid/services/evtmgr/include/evtmgr/backlight-handler/BacklightHandler.hpp => products/BellHybrid/services/evtmgr/include/evtmgr/backlight-handler/BacklightHandler.hpp +10 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 16,6 16,12 @@ namespace settings

namespace backlight
{
    enum class Type
    {
        Frontlight,
        BedsideLamp
    };

    enum class BacklightMode
    {
        WithTimer,


@@ 31,6 37,8 @@ namespace backlight

        void handleKeyPressed(int key = 0);

        void handleScreenLight(Type type);

        void processScreenRequest(screen_light_control::Action action,
                                  const screen_light_control::Parameters &params) override;



@@ 48,5 56,6 @@ namespace backlight
        bool ignoreKeypress         = false;
        bool onDemandModeOn         = true;
        BacklightMode backlightMode = BacklightMode::WithTimer;
        Type backlightType          = Type::Frontlight;
    };
} // namespace backlight

A products/BellHybrid/services/evtmgr/internal/key_sequences/BedsideLampSequence.hpp => products/BellHybrid/services/evtmgr/internal/key_sequences/BedsideLampSequence.hpp +16 -0
@@ 0,0 1,16 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "GenericLongPressSequence.hpp"
#include <Timers/TimerFactory.hpp>

class BedsideLampSequence : public GenericLongPressSequence<KeyMap::Frontlight>
{
  public:
    explicit BedsideLampSequence(sys::Service &service)
        : GenericLongPressSequence<KeyMap::Frontlight>{sys::TimerFactory::createSingleShotTimer(
              &service, "lampseq", std::chrono::milliseconds{3000}, [this](auto &) { handleTimer(); })}
    {}
};

A products/BellHybrid/services/evtmgr/internal/key_sequences/FrontlightSequence.hpp => products/BellHybrid/services/evtmgr/internal/key_sequences/FrontlightSequence.hpp +16 -0
@@ 0,0 1,16 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "GenericLongPressSequence.hpp"
#include <Timers/TimerFactory.hpp>

class FrontlightSequence : public GenericLongPressSequence<KeyMap::Frontlight>
{
  public:
    explicit FrontlightSequence(sys::Service &service)
        : GenericLongPressSequence<KeyMap::Frontlight>{sys::TimerFactory::createSingleShotTimer(
              &service, "frontseq", std::chrono::milliseconds{30}, [this](auto &) { handleTimer(); })}
    {}
};