diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index 9ff7d7e1..14e17b7a 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -15,14 +15,14 @@ int32_t KbI2cBase::runOnce() // Input device is not detected. return INT32_MAX; } - InputEvent e; - e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_NONE; - e.source = this->_originName; Wire.requestFrom(CARDKB_ADDR, 1); while (Wire.available()) { char c = Wire.read(); + InputEvent e; + e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + e.source = this->_originName; switch (c) { case 0x1b: // ESC e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL; @@ -56,10 +56,10 @@ int32_t KbI2cBase::runOnce() e.kbchar = c; break; } - } - if (e.inputEvent != ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { - this->notifyObservers(&e); + if (e.inputEvent != ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { + this->notifyObservers(&e); + } } return 500; } diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 2ffe221d..dc118dc5 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -141,7 +141,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) if (event->inputEvent == static_cast(ANYKEY)) { DEBUG_MSG("Canned message event any key pressed\n"); // when inactive, this will switch to the freetext mode - if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) { + if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) { this->runState = CANNED_MESSAGE_RUN_STATE_FREETEXT; } // pass the pressed key @@ -218,10 +218,12 @@ int32_t CannedMessageModule::runOnce() this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) { this->currentMessageIndex = getPrevIndex(); + this->freetext = ""; // clear freetext this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; DEBUG_MSG("MOVE UP (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage()); } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) { this->currentMessageIndex = this->getNextIndex(); + this->freetext = ""; // clear freetext this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; DEBUG_MSG("MOVE DOWN (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage()); } else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {