From 8e7991606e21ced1efe404fa3990dad286859f01 Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Sat, 10 Aug 2024 05:38:46 -0400 Subject: [PATCH] Improve CannedMessageModule usability - Don't let Screen timer jump away from CannedMessageModule frame - Correctly timeout CannedMessageModule with INACTIVATE_AFTER_MS - Don't reset half-typed messages on timeout --- src/graphics/Screen.cpp | 7 +++++++ src/modules/CannedMessageModule.cpp | 14 ++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 68fdba207..a6b4f9cbe 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -45,6 +45,7 @@ along with this program. If not, see . #include "mesh/generated/meshtastic/deviceonly.pb.h" #include "meshUtils.h" #include "modules/AdminModule.h" +#include "modules/CannedMessageModule.h" #include "modules/ExternalNotificationModule.h" #include "modules/TextMessageModule.h" #include "sleep.h" @@ -2317,6 +2318,12 @@ void Screen::handleOnPress() if (scanAndSelectInput != nullptr && scanAndSelectInput->dismissCannedMessageFrame()) return; + // Don't transition away from canned messages if it is active + if (cannedMessageModule->shouldDraw()) { + lastScreenTransition = millis(); + return; + } + // If screen was off, just wake it, otherwise advance to next frame // If we are in a transition, the press must have bounced, drop it. if (ui->getUiState()->frameState == FIXED) { diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 87a3e8927..ab8f368ae 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -360,12 +360,9 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event) if (validEvent) { requestFocus(); // Tell Screen::setFrames to move to our module's frame, next time it runs - // Let runOnce to be called immediately. - if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) { - setIntervalFromNow(0); // on fast keypresses, this isn't fast enough. - } else { - runOnce(); - } + // Run CannedMessageModule thread now from callee thread context, + // and also schedule it to run later in its own context with the requested delay. + setIntervalFromNow(runOnce()); } return 0; @@ -423,11 +420,8 @@ int32_t CannedMessageModule::runOnce() this->notifyObservers(&e); } else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) && ((millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS)) { - // Reset module + // Don't reset module, just hide the frame e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen - this->currentMessageIndex = -1; - this->freetext = ""; // clear freetext - this->cursor = 0; #if !defined(T_WATCH_S3) && !defined(RAK14014) this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;