~aleteoryx/muditaos

4a11f85ae2def9d053625a072a5ca610d93e58c4 — Adam Wulkiewicz 3 years ago 6404e09
[MOS-210] Avoid blocking of key handling, artificially generate Release

In rare cases when corresponding Press and Release key events were not
generated the logic prevented other keys from being handled. Handling of
other keys is no longer blocked.

In addition to the above Release event is artificially generated. This
ensures that key presses are not ignored if there were no real Release
event. Typically this may occur when keys are pressed fast one after
another. A side effect is that when a key was pressed while other one
was already pressed then both of them are handled by the UI which
prevents e.g. letters from being ignored while writing.
M module-services/service-evtmgr/WorkerEventCommon.cpp => module-services/service-evtmgr/WorkerEventCommon.cpp +19 -20
@@ 146,40 146,39 @@ bool WorkerEventCommon::deinit(void)
    return true;
}

void WorkerEventCommon::processKeyEvent(bsp::KeyEvents event, bsp::KeyCodes code)
void WorkerEventCommon::sendKeyUnicast(RawKey const &key)
{
    auto message = std::make_shared<sevm::KbdMessage>();
    message->key = key;
    service->bus.sendUnicast(message, service::name::evt_manager);
}

    message->key.keyCode = code;

void WorkerEventCommon::processKeyEvent(bsp::KeyEvents event, bsp::KeyCodes code)
{
    switch (event) {
    case bsp::KeyEvents::Pressed:
    case bsp::KeyEvents::Pressed: {
        auto const tick = xTaskGetTickCount();
        if (lastState == bsp::KeyEvents::Pressed) {
            return;
            LOG_WARN("Generating Release %s", c_str(lastPressed));
            sendKeyUnicast({RawKey::State::Released, lastPressed, 0, tick});
        }
        message->key.state     = RawKey::State::Pressed;
        message->key.timePress = xTaskGetTickCount();
        lastPressed            = code;
        lastState              = event;
        sendKeyUnicast({RawKey::State::Pressed, code, tick, 0});
        lastState   = bsp::KeyEvents::Pressed;
        lastPressed = code;
        break;
    }
    case bsp::KeyEvents::Released:
        if (lastState != bsp::KeyEvents::Pressed) {
            return;
        }
        if (lastPressed != code) {
        if (lastState != bsp::KeyEvents::Pressed || lastPressed != code) {
            return;
        }
        lastState = bsp::KeyEvents::Released;
        {
            message->key.state       = RawKey::State::Released;
            message->key.timeRelease = xTaskGetTickCount();
        }
        sendKeyUnicast({RawKey::State::Released, code, 0, xTaskGetTickCount()});
        lastState   = bsp::KeyEvents::Released;
        lastPressed = code;
        break;
    case bsp::KeyEvents::Moved:
        message->key.state = RawKey::State::Moved;
        sendKeyUnicast({RawKey::State::Moved, code});
        break;
    }
    service->bus.sendUnicast(message, service::name::evt_manager);
}

void WorkerEventCommon::updateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency)

M module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp => module-services/service-evtmgr/service-evtmgr/WorkerEventCommon.hpp +1 -0
@@ 69,6 69,7 @@ class WorkerEventCommon : public sys::Worker
    void updateResourcesAfterCpuFrequencyChange(bsp::CpuFrequencyMHz newFrequency);
    bool initEventQueues();
    bool initCommonHardwareComponents();
    void sendKeyUnicast(RawKey const &key);

    /**
     * @brief list of keys with long press enabled. First item is key code, second is long press time.