From 317baa04e949a32ef1e72b2dd2b61c1e7a97ca25 Mon Sep 17 00:00:00 2001 From: Wojtek Rzepecki Date: Thu, 7 Oct 2021 10:28:30 +0200 Subject: [PATCH] [BH-872] Fix encoder hadnling interrupt driven encoder handling --- module-bsp/board/linux/CMakeLists.txt | 1 - .../linux/rotary_encoder/rotary_encoder.cpp | 20 --- .../rt1051/bellpx/bsp/KeyInputCommon.hpp | 23 ++++ .../bsp/rotary_encoder/rotary_encoder.cpp | 89 ++++++------- .../bsp/rotary_encoder/rotary_encoder.hpp | 23 ++++ .../rt1051/bellpx/bsp/switches/switches.cpp | 119 ++++++++---------- .../rt1051/bellpx/bsp/switches/switches.hpp | 3 +- .../rt1051/bellpx/hal/key_input/KeyInput.cpp | 20 ++- module-bsp/board/rt1051/bellpx/irq_gpio.cpp | 19 +++ .../bsp/rotary_encoder/rotary_encoder.hpp | 23 ---- module-gui/gui/input/Translator.cpp | 6 +- .../services/evtmgr/WorkerEvent.cpp | 36 +----- .../services/evtmgr/WorkerEvent.hpp | 6 - 13 files changed, 188 insertions(+), 200 deletions(-) delete mode 100644 module-bsp/board/linux/rotary_encoder/rotary_encoder.cpp create mode 100644 module-bsp/board/rt1051/bellpx/bsp/KeyInputCommon.hpp create mode 100644 module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.hpp delete mode 100644 module-bsp/bsp/rotary_encoder/rotary_encoder.hpp diff --git a/module-bsp/board/linux/CMakeLists.txt b/module-bsp/board/linux/CMakeLists.txt index 6b92d79afa62d0f33f572304a95ccfdc518886ad..7bd2d8470f0af36f59328082de575435dbdf45e8 100644 --- a/module-bsp/board/linux/CMakeLists.txt +++ b/module-bsp/board/linux/CMakeLists.txt @@ -25,7 +25,6 @@ target_sources(module-bsp hal/battery_charger/BatteryCharger.cpp hal/key_input/KeyInput.cpp bell_temp_sensor/bell_temp_sensor.cpp - rotary_encoder/rotary_encoder.cpp ${CMAKE_CURRENT_BINARY_DIR}/eink-config.h ) diff --git a/module-bsp/board/linux/rotary_encoder/rotary_encoder.cpp b/module-bsp/board/linux/rotary_encoder/rotary_encoder.cpp deleted file mode 100644 index 3cdcf60b66b012f7f7a251fab8f7eaa287e57dc4..0000000000000000000000000000000000000000 --- a/module-bsp/board/linux/rotary_encoder/rotary_encoder.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include - -namespace bsp::rotary_encoder -{ - int init(xQueueHandle qHandle) - { - return 1; - } - void deinit() - {} - - std::optional WorkerEventHandler() - { - return std::nullopt; - } - -} // namespace bsp::rotary_encoder diff --git a/module-bsp/board/rt1051/bellpx/bsp/KeyInputCommon.hpp b/module-bsp/board/rt1051/bellpx/bsp/KeyInputCommon.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d934f97aaa12e2bb2157a0fefd805a77abf604ce --- /dev/null +++ b/module-bsp/board/rt1051/bellpx/bsp/KeyInputCommon.hpp @@ -0,0 +1,23 @@ +// 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 +{ + enum class NotificationSource : uint8_t + { + leftSideKeyPress = 1, + leftSideKeyRelease, + rightSideKeyPress, + rightSideKeyRelease, + lightCenterKeyPress, + lightCenterKeyRelease, + latchKeyPress, + latchKeyRelease, + wakeupEvent, + wakeupEventRelease, + rotaryEncoder, + Invalid = 0xFF + }; +} // namespace bsp diff --git a/module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.cpp b/module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.cpp index 5bc7d99f3e03a816e4ba32fac7e3943faa769fb3..9b34bda548cb3339114571795df41a0715569f92 100644 --- a/module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.cpp +++ b/module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.cpp @@ -1,7 +1,8 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include +#include "rotary_encoder.hpp" +#include #include #include #include @@ -15,18 +16,23 @@ namespace bsp::rotary_encoder { namespace { - constexpr auto POLL_INTERVAL_MS = 100U; - constexpr uint16_t MAX_PER_100MS = 100U; + enum class Direction + { + forward = 0x01, + backward = 0x02, + undefined = 0xFF + }; + constexpr auto MAX_PER_CHECK = 100; constexpr auto PRIMARY_SOURCE = kQTMR_ClockCounter0InputPin; constexpr auto BOARD_QTMR_ENC_CHANNEL = kQTMR_Channel_0; constexpr auto SECONDARY_SOURCE = kQTMR_Counter1InputPin; + constexpr auto INTERRUPT_MODE = kQTMR_EdgeInterruptEnable; auto BOARD_QTMR_ID = TMR3; xQueueHandle gHandleIrq; - TimerHandle_t gTimerHandle; uint32_t encCounter; } // namespace - int init(xQueueHandle qHandle) + void init(xQueueHandle qHandle) { gHandleIrq = qHandle; qtmr_config_t timerCfg; @@ -34,63 +40,60 @@ namespace bsp::rotary_encoder timerCfg.primarySource = PRIMARY_SOURCE; timerCfg.secondarySource = SECONDARY_SOURCE; QTMR_Init(BOARD_QTMR_ID, BOARD_QTMR_ENC_CHANNEL, &timerCfg); + QTMR_SetupInputCapture( + BOARD_QTMR_ID, BOARD_QTMR_ENC_CHANNEL, SECONDARY_SOURCE, false, false, kQTMR_RisingAndFallingEdge); + QTMR_EnableInterrupts(BOARD_QTMR_ID, BOARD_QTMR_ENC_CHANNEL, INTERRUPT_MODE); QTMR_StartTimer(BOARD_QTMR_ID, BOARD_QTMR_ENC_CHANNEL, kQTMR_QuadCountMode); - if (!gTimerHandle) { - gTimerHandle = - xTimerCreate("RotEncTimer", pdMS_TO_TICKS(POLL_INTERVAL_MS), true, nullptr, [](TimerHandle_t) { - if (gHandleIrq) { - uint8_t val{0x01}; - xQueueSend(gHandleIrq, &val, 0); - } - }); - } - if (xTimerStart(gTimerHandle, 0) != pdPASS) { - LOG_ERROR("Couldn't start encoder timer"); - } + LOG_DEBUG("Init rotary encoder driver"); - const auto ret = (gTimerHandle && gHandleIrq) ? (kStatus_Success) : (kStatus_Fail); - LOG_DEBUG("Init rotary encoder driver status %i", ret); - return ret; } void deinit() { - xTimerDelete(gTimerHandle, 50); - gTimerHandle = nullptr; gHandleIrq = nullptr; + QTMR_DisableInterrupts(BOARD_QTMR_ID, BOARD_QTMR_ENC_CHANNEL, INTERRUPT_MODE); QTMR_Deinit(BOARD_QTMR_ID, BOARD_QTMR_ENC_CHANNEL); } - std::optional WorkerEventHandler() + std::vector getKeyEvents() { uint16_t tmp = QTMR_GetCurrentTimerCount(BOARD_QTMR_ID, BOARD_QTMR_ENC_CHANNEL); - std::optional ret; + auto direction = Direction::undefined; + std::vector out; - if (tmp != encCounter && encCounter >= 0xFFFFU - MAX_PER_100MS && encCounter <= 0xFFFFU) { - if (tmp <= MAX_PER_100MS || tmp > encCounter) { - ret = type::forward; - } - else { - ret = type::backward; - } + int difference = tmp - encCounter; + if (difference > MAX_PER_CHECK) { + direction = Direction::backward; } - else if (tmp != encCounter && encCounter <= MAX_PER_100MS) { - if ((tmp >= 0xFFFFU - MAX_PER_100MS) || tmp < encCounter) { - ret = type::backward; - } - else { - ret = type::forward; - } + else if (difference < -MAX_PER_CHECK) { + direction = Direction::forward; } - else if (tmp < encCounter) { - ret = type::backward; + else if (difference > 0) { + direction = Direction::forward; } - else if (tmp > encCounter) { - ret = type::forward; + else if (difference < 0) { + direction = Direction::backward; } encCounter = tmp; - return ret; + if (direction == Direction::forward) { + out.push_back({KeyCodes::JoystickUp, KeyEvents::Moved}); + } + else if (direction == Direction::backward) { + out.push_back({KeyCodes::JoystickDown, KeyEvents::Moved}); + } + + return out; + } + + BaseType_t IRQHandler(uint32_t mask) + { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + if (gHandleIrq != nullptr) { + std::uint8_t val = static_cast(NotificationSource::rotaryEncoder); + xQueueSendFromISR(gHandleIrq, &val, &xHigherPriorityTaskWoken); + } + return xHigherPriorityTaskWoken; } } // namespace bsp::rotary_encoder diff --git a/module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.hpp b/module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9e72ec30d7cedb46dbbf30279ea98f96008242ab --- /dev/null +++ b/module-bsp/board/rt1051/bellpx/bsp/rotary_encoder/rotary_encoder.hpp @@ -0,0 +1,23 @@ +// 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 +#include +#include + +#include +#include + +namespace bsp +{ + namespace rotary_encoder + { + void init(xQueueHandle qHandle); + void deinit(); + std::vector getKeyEvents(); + BaseType_t IRQHandler(uint32_t mask); + } // namespace rotary_encoder + +} // namespace bsp diff --git a/module-bsp/board/rt1051/bellpx/bsp/switches/switches.cpp b/module-bsp/board/rt1051/bellpx/bsp/switches/switches.cpp index fdfc92e4de335863da2b6b375f5b8785ef334f70..3ca2264246c2516e3470a5c819f839aaf2d44872 100644 --- a/module-bsp/board/rt1051/bellpx/bsp/switches/switches.cpp +++ b/module-bsp/board/rt1051/bellpx/bsp/switches/switches.cpp @@ -43,21 +43,6 @@ namespace bsp::bell_switches Invalid }; - enum class NotificationSource : uint16_t - { - leftSideKeyPress = 0x0001, - leftSideKeyRelease = 0x0002, - rightSideKeyPress = 0x0004, - rightSideKeyRelease = 0x0008, - lightCenterKeyPress = 0x0010, - lightCenterKeyRelease = 0x0020, - latchKeyPress = 0x0040, - latchKeyRelease = 0x0080, - wakeupEvent = 0x0400, - wakeupEventRelease = 0x0800, - Invalid = 0xFFFF - }; - void debounceTimerCallback(TimerHandle_t timerHandle); struct DebounceTimerState @@ -143,8 +128,26 @@ namespace bsp::bell_switches if (timerState->notificationSource == NotificationSource::latchKeyPress) { latchEventFlag.setReleased(); } - // Using responding release notification source, which is one bit shifted - auto val = (static_cast(timerState->notificationSource) << 1); + auto val = NotificationSource::Invalid; + switch (timerState->notificationSource) { + case NotificationSource::leftSideKeyPress: + val = NotificationSource::leftSideKeyRelease; + break; + case NotificationSource::rightSideKeyPress: + val = NotificationSource::rightSideKeyRelease; + break; + case NotificationSource::lightCenterKeyPress: + val = NotificationSource::lightCenterKeyRelease; + break; + case NotificationSource::latchKeyPress: + val = NotificationSource::latchKeyRelease; + break; + case NotificationSource::wakeupEvent: + val = NotificationSource::wakeupEventRelease; + break; + default: + break; + } xQueueSendFromISR(qHandleIrq, &val, &xHigherPriorityTaskWoken); timerState->lastState = KeyEvents::Pressed; } @@ -345,79 +348,59 @@ namespace bsp::bell_switches gpio_wakeup->DisableInterrupt(1 << static_cast(BoardDefinitions::BELL_WAKEUP)); } - std::vector getKeyEvents(KeyNotificationSource notification) + std::vector getKeyEvents(NotificationSource notification) { std::vector out; + KeyEvent keyEvent; - if (notification & static_cast(NotificationSource::leftSideKeyPress)) { + switch (notification) { + case NotificationSource::leftSideKeyPress: LOG_DEBUG("leftSideKeyPress"); - KeyEvent keyEvent{KeyCodes::FnLeft, KeyEvents::Pressed}; + keyEvent = {KeyCodes::FnLeft, KeyEvents::Pressed}; out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::leftSideKeyRelease)) { + break; + case NotificationSource::leftSideKeyRelease: LOG_DEBUG("leftSideKeyRelease"); - KeyEvent keyEvent{KeyCodes::FnLeft, KeyEvents::Released}; + keyEvent = {KeyCodes::FnLeft, KeyEvents::Released}; out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::rightSideKeyPress)) { + break; + case NotificationSource::rightSideKeyPress: LOG_DEBUG("rightSideKeyPress"); - KeyEvent keyEvent{KeyCodes::FnRight, KeyEvents::Pressed}; + keyEvent = {KeyCodes::FnRight, KeyEvents::Pressed}; out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::rightSideKeyRelease)) { + break; + case NotificationSource::rightSideKeyRelease: LOG_DEBUG("rightSideKeyRelease"); - KeyEvent keyEvent{KeyCodes::FnRight, KeyEvents::Released}; + keyEvent = {KeyCodes::FnRight, KeyEvents::Released}; out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::lightCenterKeyPress)) { + break; + case NotificationSource::lightCenterKeyPress: LOG_DEBUG("lightCenterKeyPress"); - KeyEvent keyEvent{KeyCodes::JoystickEnter, KeyEvents::Pressed}; - out.push_back(keyEvent); - // workaround for current GUI event processing - keyEvent = {KeyCodes::JoystickEnter, KeyEvents::Released}; + keyEvent = {KeyCodes::JoystickEnter, KeyEvents::Moved}; out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::lightCenterKeyRelease)) { + break; + case NotificationSource::lightCenterKeyRelease: LOG_DEBUG("lightCenterKeyRelease"); - KeyEvent keyEvent{KeyCodes::JoystickEnter, KeyEvents::Pressed}; - out.push_back(keyEvent); - // workaround for current GUI event processing - keyEvent = {KeyCodes::JoystickEnter, KeyEvents::Released}; + keyEvent = {KeyCodes::JoystickEnter, KeyEvents::Moved}; out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::latchKeyPress)) { + break; + case NotificationSource::latchKeyPress: LOG_DEBUG("latchKeyPress"); - KeyEvent keyEvent{KeyCodes::JoystickRight, KeyEvents::Pressed}; + keyEvent = {KeyCodes::JoystickRight, KeyEvents::Moved}; out.push_back(keyEvent); - // workaround for current GUI event processing - keyEvent = {KeyCodes::JoystickRight, KeyEvents::Released}; - out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::latchKeyRelease)) { + break; + case NotificationSource::latchKeyRelease: LOG_DEBUG("latchKeyRelease"); - KeyEvent keyEvent{KeyCodes::JoystickLeft, KeyEvents::Pressed}; + keyEvent = {KeyCodes::JoystickLeft, KeyEvents::Moved}; out.push_back(keyEvent); - // workaround for current GUI event processing - keyEvent = {KeyCodes::JoystickLeft, KeyEvents::Released}; - out.push_back(keyEvent); - } - - if (notification & static_cast(NotificationSource::wakeupEvent)) { + break; + case NotificationSource::wakeupEvent: /* Implement wakeup event */ - } - - if (notification & static_cast(NotificationSource::wakeupEventRelease)) { - KeyEvent keyEvent; + break; + case NotificationSource::wakeupEventRelease: /* Implement wakeup event */ + break; } - return out; } diff --git a/module-bsp/board/rt1051/bellpx/bsp/switches/switches.hpp b/module-bsp/board/rt1051/bellpx/bsp/switches/switches.hpp index 235fb0246b217cd29ad145877f3403a57b3535c8..670abd721f3f85a09683a4871855d3e49301b22e 100644 --- a/module-bsp/board/rt1051/bellpx/bsp/switches/switches.hpp +++ b/module-bsp/board/rt1051/bellpx/bsp/switches/switches.hpp @@ -4,13 +4,14 @@ #pragma once #include +#include #include #include namespace bsp::bell_switches { - std::vector getKeyEvents(KeyNotificationSource notification); + std::vector getKeyEvents(NotificationSource notification); std::int32_t init(xQueueHandle qHandle); diff --git a/module-bsp/board/rt1051/bellpx/hal/key_input/KeyInput.cpp b/module-bsp/board/rt1051/bellpx/hal/key_input/KeyInput.cpp index bf1fb57530b722eac3d37d31f4a860f4f361a8ec..45d79baa8e5ea15a62343bdb89967a2c914f792a 100644 --- a/module-bsp/board/rt1051/bellpx/hal/key_input/KeyInput.cpp +++ b/module-bsp/board/rt1051/bellpx/hal/key_input/KeyInput.cpp @@ -2,9 +2,11 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "KeyInput.hpp" +#include #include #include +#include #include namespace hal::key_input @@ -17,21 +19,35 @@ namespace hal::key_input void KeyInput::init(xQueueHandle queueHandle) { bsp::bell_switches::init(queueHandle); + bsp::rotary_encoder::init(queueHandle); } void KeyInput::deinit() { bsp::bell_switches::deinit(); + bsp::rotary_encoder::deinit(); } std::vector KeyInput::getKeyEvents(KeyNotificationSource notification) { - return bsp::bell_switches::getKeyEvents(notification); + auto keyNotification = static_cast(notification); + if (keyNotification == bsp::NotificationSource::rotaryEncoder) { + return bsp::rotary_encoder::getKeyEvents(); + } + else { + return bsp::bell_switches::getKeyEvents(keyNotification); + } } BaseType_t generalIRQHandler(std::uint32_t irqMask) { - return bsp::bell_switches::IRQHandler(irqMask); + constexpr std::uint32_t encoderMask{99}; + if (irqMask == encoderMask) { + return bsp::rotary_encoder::IRQHandler(irqMask); + } + else { + return bsp::bell_switches::IRQHandler(irqMask); + } } BaseType_t wakeupIRQHandler() diff --git a/module-bsp/board/rt1051/bellpx/irq_gpio.cpp b/module-bsp/board/rt1051/bellpx/irq_gpio.cpp index 74ec3b4b9c358a0a8c8a0d295783491aa16294e9..ba5d3de0e906a728762cce787b72da4f3583979c 100644 --- a/module-bsp/board/rt1051/bellpx/irq_gpio.cpp +++ b/module-bsp/board/rt1051/bellpx/irq_gpio.cpp @@ -8,6 +8,7 @@ #include "FreeRTOS.h" #include "queue.h" #include "fsl_common.h" +#include #include "board/rt1051/bsp/eink/bsp_eink.h" #include @@ -28,6 +29,7 @@ namespace bsp DisableIRQ(GPIO2_Combined_16_31_IRQn); DisableIRQ(GPIO3_Combined_16_31_IRQn); DisableIRQ(GPIO5_Combined_0_15_IRQn); + DisableIRQ(TMR3_IRQn); GPIO_PortDisableInterrupts(GPIO1, UINT32_MAX); GPIO_PortDisableInterrupts(GPIO2, UINT32_MAX); @@ -39,6 +41,10 @@ namespace bsp GPIO_PortClearInterruptFlags(GPIO2, UINT32_MAX); GPIO_PortClearInterruptFlags(GPIO3, UINT32_MAX); GPIO_PortClearInterruptFlags(GPIO5, UINT32_MAX); + QTMR_ClearStatusFlags(TMR3, + kQTMR_Channel_0, + kQTMR_CompareFlag | kQTMR_Compare1Flag | kQTMR_Compare2Flag | kQTMR_OverflowFlag | + kQTMR_EdgeFlag); EnableIRQ(GPIO1_Combined_0_15_IRQn); NVIC_SetPriority(GPIO1_Combined_0_15_IRQn, configLIBRARY_LOWEST_INTERRUPT_PRIORITY); @@ -57,6 +63,9 @@ namespace bsp EnableIRQ(GPIO5_Combined_0_15_IRQn); NVIC_SetPriority(GPIO5_Combined_0_15_IRQn, configLIBRARY_LOWEST_INTERRUPT_PRIORITY); + + EnableIRQ(TMR3_IRQn); + NVIC_SetPriority(TMR3_IRQn, configLIBRARY_LOWEST_INTERRUPT_PRIORITY); } extern "C" @@ -173,5 +182,15 @@ namespace bsp // Switch context if necessary portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); } + + void TMR3_IRQHandler(void) + { + QTMR_ClearStatusFlags(TMR3, + kQTMR_Channel_0, + kQTMR_CompareFlag | kQTMR_Compare1Flag | kQTMR_Compare2Flag | kQTMR_OverflowFlag | + kQTMR_EdgeFlag); + const uint8_t QTMR3_mask = 99; + hal::key_input::generalIRQHandler(QTMR3_mask); + } } } // namespace bsp diff --git a/module-bsp/bsp/rotary_encoder/rotary_encoder.hpp b/module-bsp/bsp/rotary_encoder/rotary_encoder.hpp deleted file mode 100644 index 780165286b60e0a9cb82944c9d71dbf91ac80ebd..0000000000000000000000000000000000000000 --- a/module-bsp/bsp/rotary_encoder/rotary_encoder.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -#include "../common.hpp" -#include - -namespace bsp -{ - namespace rotary_encoder - { - enum class type - { - forward = 0x01, - backward = 0x02 - }; - int init(xQueueHandle qHandle); - void deinit(); - std::optional WorkerEventHandler(); - } // namespace rotary_encoder - -} // namespace bsp diff --git a/module-gui/gui/input/Translator.cpp b/module-gui/gui/input/Translator.cpp index 9f4e22d8c6034f94565473badccb108d0923305d..92674edc7eb2dc2fefa26059c814e388ead6a274 100644 --- a/module-gui/gui/input/Translator.cpp +++ b/module-gui/gui/input/Translator.cpp @@ -175,11 +175,15 @@ namespace gui InputEvent KeyInputSimpleTranslation::translate(RawKey key) { auto evt = KeyBaseTranslation::set(key); - // when last action timed out we don't want to handle key release if (isPreviousKeyTimedOut && key.state == RawKey::State::Released) { + // when last action timed out we don't want to handle key release evt.setState(InputEvent::State::Undefined); isPreviousKeyTimedOut = false; } + else if (key.state == RawKey::State::Moved) { + // translation of single moved event to keyReleasedShort + evt.setState(InputEvent::State::keyReleasedShort); + } evt.setKeyCode(getKeyCode(key.keyCode)); return evt; } diff --git a/products/BellHybrid/services/evtmgr/WorkerEvent.cpp b/products/BellHybrid/services/evtmgr/WorkerEvent.cpp index a385cb2fc4fb94a811a6e8fc7b4ac4c467c985e2..2a8039032b830d8ffc88c58a568949631c5bec85 100644 --- a/products/BellHybrid/services/evtmgr/WorkerEvent.cpp +++ b/products/BellHybrid/services/evtmgr/WorkerEvent.cpp @@ -6,7 +6,6 @@ #include #include #include -#include namespace bell { @@ -15,56 +14,23 @@ namespace bell {} void WorkerEvent::addProductQueues(std::list &queuesList) - { - constexpr auto elementSize = sizeof(std::uint8_t); - queuesList.emplace_back(rotaryEncoderQueueName, elementSize, rotaryEncoderQueueSize); - } + {} void WorkerEvent::initProductHardware() { bsp::eink_frontlight::init(); - bsp::rotary_encoder::init(queues[static_cast(EventQueues::queueRotaryEncoder)]->GetQueueHandle()); } bool WorkerEvent::handleMessage(std::uint32_t queueID) { - auto &queue = queues[queueID]; - if (queueID == static_cast(EventQueues::queueRotaryEncoder)) { - uint8_t notification; - if (!queue->Dequeue(¬ification, 0)) { - return false; - } - handleRotaryEncoderEvent(); - } return WorkerEventCommon::handleMessage(queueID); } void WorkerEvent::deinitProductHardware() { bsp::eink_frontlight::deinit(); - bsp::rotary_encoder::deinit(); - } - - void WorkerEvent::processRotaryAsShortRelease(bsp::KeyCodes code) - { - processKeyEvent(bsp::KeyEvents::Pressed, code); - processKeyEvent(bsp::KeyEvents::Released, code); } - void WorkerEvent::handleRotaryEncoderEvent() - { - if (const auto &key = bsp::rotary_encoder::WorkerEventHandler(); key.has_value()) { - if (key.value() == bsp::rotary_encoder::type::forward) { - processRotaryAsShortRelease(bsp::KeyCodes::JoystickUp); - } - else if (key.value() == bsp::rotary_encoder::type::backward) { - processRotaryAsShortRelease(bsp::KeyCodes::JoystickDown); - } - else { - LOG_ERROR("Unknown rotary event"); - } - } - } void WorkerEvent::processKeyEvent(bsp::KeyEvents event, bsp::KeyCodes code) { auto message = std::make_shared(); diff --git a/products/BellHybrid/services/evtmgr/WorkerEvent.hpp b/products/BellHybrid/services/evtmgr/WorkerEvent.hpp index ab8b8aaccb7f402cbfa5664f063e321bdf57594f..1a950cdddbd66908e0420f4daa403dbbfcfe570e 100644 --- a/products/BellHybrid/services/evtmgr/WorkerEvent.hpp +++ b/products/BellHybrid/services/evtmgr/WorkerEvent.hpp @@ -18,12 +18,6 @@ namespace bell void deinitProductHardware() final; void processKeyEvent(bsp::KeyEvents event, bsp::KeyCodes code) final; bool handleMessage(std::uint32_t queueID) override; - void processRotaryAsShortRelease(bsp::KeyCodes code); - void handleRotaryEncoderEvent(); - enum class EventQueues - { - queueRotaryEncoder = static_cast(WorkerEventQueues::queueRTC) + 1, - }; static constexpr auto rotaryEncoderQueueSize = 64U; static constexpr auto rotaryEncoderQueueName = "qRotaryEncoder"; };