~aleteoryx/muditaos

379d5130c3f251f6ef69d261f2dec0e271117872 — Lukasz Skrzypczak 4 years ago 0409529
[BH-1071] Latch detect on startup

Added latch pressed detection
M module-bsp/CMakeLists.txt => module-bsp/CMakeLists.txt +1 -0
@@ 60,6 60,7 @@ target_include_directories(${PROJECT_NAME}
            ${CMAKE_CURRENT_SOURCE_DIR}/bsp/headset
            ${CMAKE_CURRENT_SOURCE_DIR}/drivers/gpio
            ${CMAKE_CURRENT_SOURCE_DIR}/drivers/i2c
            ${CMAKE_CURRENT_SOURCE_DIR}/bsp
        >
)


M module-bsp/board/linux/board.cpp => module-bsp/board/linux/board.cpp +9 -1
@@ 7,4 7,12 @@ namespace bsp
    {
        // dummy
    }
} // namespace bsp
\ No newline at end of file
} // namespace bsp

namespace bsp::bell_switches
{
    bool isLatchPressed()
    {
        return false;
    }
} // namespace bsp::bell_switches

M module-bsp/board/rt1051/bellpx/bsp/switches/switches.cpp => module-bsp/board/rt1051/bellpx/bsp/switches/switches.cpp +13 -0
@@ 12,6 12,7 @@
#include <board/BoardDefinitions.hpp>
#include <board.h>
#include <fsl_common.h>
#include <switches/LatchState.hpp>

#include <chrono>
#include <stdio.h>


@@ 250,6 251,13 @@ namespace bsp::bell_switches
        addDebounceTimer(DebounceTimerState{
            DebounceTimerId::wakeup, NotificationSource::wakeupEvent, gpio_wakeup, BoardDefinitions::BELL_WAKEUP});

        if (getLatchState() == KeyEvents::Pressed) {
            latchEventFlag.setPressed();
            auto timerState = static_cast<DebounceTimerState *>(
                pvTimerGetTimerID(debounceTimers[DebounceTimerId::latchSwitch].timer));
            timerState->lastState = KeyEvents::Released;
        }

        enableIRQ();

        return kStatus_Success;


@@ 404,4 412,9 @@ namespace bsp::bell_switches
        return out;
    }

    bool isLatchPressed()
    {
        return latchEventFlag.isPressed();
    }

} // namespace bsp::bell_switches

A module-bsp/bsp/switches/LatchState.hpp => module-bsp/bsp/switches/LatchState.hpp +9 -0
@@ 0,0 1,9 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

namespace bsp::bell_switches
{
    bool isLatchPressed();
} // namespace bsp::bell_switches

A module-bsp/bsp/switches/LatchStatusRequest.hpp => module-bsp/bsp/switches/LatchStatusRequest.hpp +36 -0
@@ 0,0 1,36 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <Service/Message.hpp>

namespace sevm
{
    enum class LatchStatus
    {
        PRESSED,
        RELEASED
    };

    class LatchStatusRequest : public sys::DataMessage
    {
      public:
        LatchStatusRequest() : sys::DataMessage(MessageType::LatchStateMessage)
        {}
    };

    class LatchStatusResponse : public sys::ResponseMessage
    {
        LatchStatus status = LatchStatus::RELEASED;

      public:
        LatchStatusResponse(LatchStatus status) : status(status)
        {}

        [[nodiscard]] auto getStatus() const noexcept -> LatchStatus
        {
            return status;
        }
    };
} // namespace sevm

M products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp => products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp +24 -1
@@ 12,6 12,8 @@
#include <Timers/TimerFactory.hpp>
#include <time/time_constants.hpp>
#include <service-db/DBNotificationMessage.hpp>
#include <service-evtmgr/Constants.hpp>
#include <switches/LatchStatusRequest.hpp>

namespace app::home_screen
{


@@ 22,7 24,23 @@ namespace app::home_screen
                                             std::unique_ptr<AbstractTimeModel> timeModel)
        : app{app}, alarmModel{std::move(alarmModel)}, batteryModel{std::move(batteryModel)},
          temperatureModel{std::move(temperatureModel)}, timeModel{std::move(timeModel)}
    {}
    {
        constexpr int timeout = pdMS_TO_TICKS(1500);

        auto response =
            app->bus.sendUnicastSync(std::make_shared<sevm::LatchStatusRequest>(), service::name::evt_manager, timeout);

        if (response.first == sys::ReturnCodes::Success) {
            auto msgState = dynamic_cast<sevm::LatchStatusResponse *>(response.second.get());
            if (msgState == nullptr) {
                return;
            }

            if (msgState->getStatus() == sevm::LatchStatus::PRESSED) {
                latchPressed = true;
            }
        }
    }

    void HomeScreenPresenter::handleUpdateTimeEvent()
    {


@@ 122,4 140,9 @@ namespace app::home_screen
    {
        return batteryModel->getLevelState().state == Store::Battery::State::Charging;
    }

    bool HomeScreenPresenter::isStartupDeepPress()
    {
        return latchPressed;
    }
} // namespace app::home_screen

M products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.hpp => products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.hpp +3 -0
@@ 98,6 98,7 @@ namespace app::home_screen
        virtual void restartSnoozeTimer(std::chrono::seconds snoozeDuration)                     = 0;
        virtual std::uint32_t getBatteryLvl() const                                              = 0;
        virtual bool isBatteryCharging() const                                                   = 0;
        virtual bool isStartupDeepPress()                                                        = 0;

        static constexpr auto defaultTimeout = std::chrono::milliseconds{5000};
    };


@@ 135,6 136,7 @@ namespace app::home_screen
        void restartSnoozeTimer(std::chrono::seconds snoozeDuration);
        std::uint32_t getBatteryLvl() const override;
        bool isBatteryCharging() const override;
        bool isStartupDeepPress() override;

      private:
        ApplicationCommon *app;


@@ 145,6 147,7 @@ namespace app::home_screen
        std::unique_ptr<AbstractTimeModel> timeModel;
        std::shared_ptr<AbstractController> stateController;
        std::unique_ptr<ProgressTimerWithSnoozeTimer> snoozeTimer;
        bool latchPressed = false;

        static constexpr auto timerName = "HS_timer";
        static constexpr auto snoozeTick = std::chrono::seconds(1);

M products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp => products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp +2 -0
@@ 83,6 83,7 @@ namespace app::home_screen
                alarmModel.setDefaultAlarmTime();
                view.setAlarmTime(alarmModel.getAlarmTime());
            };
            auto isDeepPress = [](AbstractPresenter &presenter) -> bool { return presenter.isStartupDeepPress(); };
        } // namespace Helpers

        namespace Events


@@ 288,6 289,7 @@ namespace app::home_screen

                                             "Deactivated"_s + sml::on_entry<_> / Deactivated::entry,
                                             "Deactivated"_s + event<Events::Reset> = "Init"_s,
                                             "Deactivated"_s [Helpers::isDeepPress] = "DeactivatedWait"_s,
                                             "Deactivated"_s + event<Events::LightPress>/ Helpers::switchToMenu,
                                             "Deactivated"_s + event<Events::RotateLeftPress> / Helpers::makeAlarmEditable = "DeactivatedEdit"_s,
                                             "Deactivated"_s + event<Events::RotateRightPress> / Helpers::makeAlarmEditable = "DeactivatedEdit"_s,

M products/BellHybrid/services/evtmgr/EventManager.cpp => products/BellHybrid/services/evtmgr/EventManager.cpp +9 -0
@@ 20,6 20,8 @@
#include <service-evtmgr/ScreenLightControlMessage.hpp>
#include <service-evtmgr/WorkerEventCommon.hpp>
#include <sys/messages/AlarmActivationStatusChangeRequest.hpp>
#include <switches/LatchStatusRequest.hpp>
#include <switches/LatchState.hpp>

namespace
{


@@ 100,6 102,13 @@ void EventManager::initProductEvents()
            backlightHandler.getScreenLightState(), backlightHandler.getScreenAutoModeState(), params);
        return msg;
    });

    connect(sevm::LatchStatusRequest(), [&](sys::Message *msgl) {
        sevm::LatchStatus state =
            bsp::bell_switches::isLatchPressed() ? sevm::LatchStatus::PRESSED : sevm::LatchStatus::RELEASED;
        auto msg = std::make_shared<sevm::LatchStatusResponse>(state);
        return msg;
    });
}

sys::MessagePointer EventManager::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)

M source/MessageType.hpp => source/MessageType.hpp +3 -1
@@ 161,6 161,8 @@ enum class MessageType
    Quotes,

    // Alarm messages
    AlarmMessage
    AlarmMessage,

    // Bell Latch state message
    LatchStateMessage
};