This commit is contained in:
robertfisk 2025-06-07 23:09:19 +02:00 committed by GitHub
commit 5b38dcfc0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 20 deletions

View File

@ -46,6 +46,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "mesh/generated/meshtastic/deviceonly.pb.h" #include "mesh/generated/meshtastic/deviceonly.pb.h"
#include "meshUtils.h" #include "meshUtils.h"
#include "modules/AdminModule.h" #include "modules/AdminModule.h"
#include "modules/CannedMessageModule.h"
#include "modules/ExternalNotificationModule.h" #include "modules/ExternalNotificationModule.h"
#include "modules/TextMessageModule.h" #include "modules/TextMessageModule.h"
#include "modules/WaypointModule.h" #include "modules/WaypointModule.h"
@ -2394,9 +2395,17 @@ void Screen::handleOnPress()
{ {
// If Canned Messages is using the "Scan and Select" input, dismiss the canned message frame when user button is pressed // If Canned Messages is using the "Scan and Select" input, dismiss the canned message frame when user button is pressed
// Minimize impact as a courtesy, as "scan and select" may be used as default config for some boards // Minimize impact as a courtesy, as "scan and select" may be used as default config for some boards
if (scanAndSelectInput != nullptr && scanAndSelectInput->dismissCannedMessageFrame()) // (Fall-through if using auto carousel, to prevent unexpected closing of canned message frame)
if (scanAndSelectInput != nullptr && !config.display.auto_screen_carousel_secs &&
scanAndSelectInput->dismissCannedMessageFrame())
return; 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 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 we are in a transition, the press must have bounced, drop it.
if (ui->getUiState()->frameState == FIXED) { if (ui->getUiState()->frameState == FIXED) {

View File

@ -391,12 +391,9 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
if (validEvent) { if (validEvent) {
requestFocus(); // Tell Screen::setFrames to move to our module's frame, next time it runs requestFocus(); // Tell Screen::setFrames to move to our module's frame, next time it runs
// Let runOnce to be called immediately. // Run CannedMessageModule thread now from callee thread context,
if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) { // and also schedule it to run later in its own context with the requested delay.
setIntervalFromNow(0); // on fast keypresses, this isn't fast enough. setIntervalFromNow(runOnce());
} else {
runOnce();
}
} }
return 0; return 0;
@ -440,9 +437,13 @@ int32_t CannedMessageModule::runOnce()
if ((this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) || if ((this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) ||
(this->runState == CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED) || (this->runState == CANNED_MESSAGE_RUN_STATE_MESSAGE)) { (this->runState == CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED) || (this->runState == CANNED_MESSAGE_RUN_STATE_MESSAGE)) {
// TODO: might have some feedback of sending state // TODO: might have some feedback of sending state
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; if (this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) {
this->restoreOldState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
}
this->runState = this->restoreOldState;
temporaryMessage = ""; temporaryMessage = "";
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
this->currentMessageIndex = -1; this->currentMessageIndex = -1;
this->freetext = ""; // clear freetext this->freetext = ""; // clear freetext
this->cursor = 0; this->cursor = 0;
@ -454,11 +455,9 @@ int32_t CannedMessageModule::runOnce()
this->notifyObservers(&e); this->notifyObservers(&e);
} else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) && } else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) &&
!Throttle::isWithinTimespanMs(this->lastTouchMillis, INACTIVATE_AFTER_MS)) { !Throttle::isWithinTimespanMs(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 e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
this->currentMessageIndex = -1; this->currentMessageIndex = -1;
this->freetext = ""; // clear freetext
this->cursor = 0;
#if !defined(T_WATCH_S3) && !defined(RAK14014) && !defined(USE_VIRTUAL_KEYBOARD) #if !defined(T_WATCH_S3) && !defined(RAK14014) && !defined(USE_VIRTUAL_KEYBOARD)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
@ -511,8 +510,6 @@ int32_t CannedMessageModule::runOnce()
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) { } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) {
if (this->messagesCount > 0) { if (this->messagesCount > 0) {
this->currentMessageIndex = getPrevIndex(); this->currentMessageIndex = getPrevIndex();
this->freetext = ""; // clear freetext
this->cursor = 0;
#if !defined(T_WATCH_S3) && !defined(RAK14014) && !defined(USE_VIRTUAL_KEYBOARD) #if !defined(T_WATCH_S3) && !defined(RAK14014) && !defined(USE_VIRTUAL_KEYBOARD)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
@ -524,8 +521,6 @@ int32_t CannedMessageModule::runOnce()
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) { } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) {
if (this->messagesCount > 0) { if (this->messagesCount > 0) {
this->currentMessageIndex = this->getNextIndex(); this->currentMessageIndex = this->getNextIndex();
this->freetext = ""; // clear freetext
this->cursor = 0;
#if !defined(T_WATCH_S3) && !defined(RAK14014) && !defined(USE_VIRTUAL_KEYBOARD) #if !defined(T_WATCH_S3) && !defined(RAK14014) && !defined(USE_VIRTUAL_KEYBOARD)
this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE; this->destSelect = CANNED_MESSAGE_DESTINATION_TYPE_NONE;
@ -675,13 +670,9 @@ int32_t CannedMessageModule::runOnce()
if (screen) if (screen)
screen->removeFunctionSymbol("Fn"); screen->removeFunctionSymbol("Fn");
} }
this->lastTouchMillis = millis();
this->notifyObservers(&e);
return INACTIVATE_AFTER_MS;
} }
if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) { if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT || this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) {
this->lastTouchMillis = millis(); this->lastTouchMillis = millis();
this->notifyObservers(&e); this->notifyObservers(&e);
return INACTIVATE_AFTER_MS; return INACTIVATE_AFTER_MS;
@ -765,6 +756,7 @@ void CannedMessageModule::showTemporaryMessage(const String &message)
UIFrameEvent e; UIFrameEvent e;
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
notifyObservers(&e); notifyObservers(&e);
this->restoreOldState = this->runState;
runState = CANNED_MESSAGE_RUN_STATE_MESSAGE; runState = CANNED_MESSAGE_RUN_STATE_MESSAGE;
// run this loop again in 2 seconds, next iteration will clear the display // run this loop again in 2 seconds, next iteration will clear the display
setIntervalFromNow(2000); setIntervalFromNow(2000);
@ -1156,6 +1148,7 @@ ProcessMessage CannedMessageModule::handleReceived(const meshtastic_MeshPacket &
UIFrameEvent e; UIFrameEvent e;
e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen e.action = UIFrameEvent::Action::REGENERATE_FRAMESET; // We want to change the list of frames shown on-screen
requestFocus(); // Tell Screen::setFrames that our module's frame should be shown, even if not "first" in the frameset requestFocus(); // Tell Screen::setFrames that our module's frame should be shown, even if not "first" in the frameset
this->restoreOldState = this->runState;
this->runState = CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED; this->runState = CANNED_MESSAGE_RUN_STATE_ACK_NACK_RECEIVED;
this->incoming = service->getNodenumFromRequestId(mp.decoded.request_id); this->incoming = service->getNodenumFromRequestId(mp.decoded.request_id);
meshtastic_Routing decoded = meshtastic_Routing_init_default; meshtastic_Routing decoded = meshtastic_Routing_init_default;

View File

@ -138,6 +138,7 @@ class CannedMessageModule : public SinglePortModule, public Observable<const UIF
int currentMessageIndex = -1; int currentMessageIndex = -1;
cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
cannedMessageModuleRunState restoreOldState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
char payload = 0x00; char payload = 0x00;
unsigned int cursor = 0; unsigned int cursor = 0;
String freetext = ""; // Text Buffer for Freetext Editor String freetext = ""; // Text Buffer for Freetext Editor